🔢

Find X in Row and Column Wise Sorted Matrix

Intermediate

Given a row and column wise sorted matrix and a target, find if the target exists using an efficient search algorithm.

15-20 min
Level 1 - Easy

Find X in Row and Column Wise Sorted Matrix

Enter true if the target exists in the matrix, false otherwise. (You can also enter yes/no, 1/0)

Matrix:

1
2
3
4
5
8
9
10
6
11
13
14
7
12
15
16

Target: 11

Does the target exist in the matrix?

Find X in Row and Column Wise Sorted Matrix - Pseudo Code

📋 Algorithm Pseudo Code


function searchMatrix(matrix, target):
    rows = number of rows in matrix
    cols = number of columns in matrix
    i = 0
    j = cols - 1
    while i < rows and j >= 0:
        if matrix[i][j] == target:
            return true
        else if matrix[i][j] > target:
            j -= 1
        else:
            i += 1
    return false
Progress0 / 4
Algorithm:Find X in Row and Column Wise Sorted Matrix
🎯 How to Play

1. Study the matrix and target shown on the left

2. Enter true/false (or yes/no, 1/0) to indicate if the target exists

3. Click "Check Solution" to verify

4. Use Tab to move between fields

5. Click "Next Level" to try more

🔄 Algorithm Steps

Step 1: Start from the top-right or bottom-left corner

Step 2: Move left if the current element is greater than the target

Step 3: Move down if the current element is less than the target

Step 4: If you find the target, return true; if you go out of bounds, return false

📊 Level Info

Difficulty: Easy

Matrix Size: 4 x 4

Target: 11