Click4Ai

38.

Easy

Write a function determinant_2x2(matrix) that computes the determinant of a 2×2 matrix.

**Formula:** For matrix [[a, b], [c, d]], det = a*d - b*c

Example:

Input: matrix = [[4, 6], [3, 8]]

Output: 14

**Explanation:** 4*8 - 6*3 = 32 - 18 = 14

Constraints:

  • Input is always a 2×2 matrix
  • Return an integer or float
  • Test Cases

    Test Case 1
    Input: [[4, 6], [3, 8]]
    Expected: 14
    Test Case 2
    Input: [[1, 0], [0, 1]]
    Expected: 1
    Test Case 3
    Input: [[2, 3], [4, 6]]
    Expected: 0
    + 2 hidden test cases