Click4Ai

24.

Easy

Write a function hadamard_product(A, B) that computes the element-wise (Hadamard) product of two matrices. This is NOT matrix multiplication — each element is multiplied with the corresponding element.

Example:

Input: A = [[1, 2], [3, 4]], B = [[5, 6], [7, 8]]

Output: [[5, 12], [21, 32]]

**Explanation:** 1*5=5, 2*6=12, 3*7=21, 4*8=32

Constraints:

  • Both matrices have the same shape
  • Return a list of lists
  • Test Cases

    Test Case 1
    Input: [[1, 2], [3, 4]], [[5, 6], [7, 8]]
    Expected: [[5, 12], [21, 32]]
    Test Case 2
    Input: [[1, 0], [0, 1]], [[9, 8], [7, 6]]
    Expected: [[9, 0], [0, 6]]
    Test Case 3
    Input: [[2, 3]], [[4, 5]]
    Expected: [[8, 15]]
    + 2 hidden test cases