Search in Matrix

Medium Searching Algorithms
Solve in Playground →

Problem Statement

Write a C program to search for a target value in a 2D matrix where each row and column is sorted in ascending order.

Input Format

First line: R, C, and Target. Next R lines: C space-separated integers per row.

Output Format

Print 'Found' if the target exists in the matrix, otherwise 'Not Found'.

Constraints

1 <= R, C <= 10

Sample Input

3 3 5
1 4 7
2 5 8
3 6 9

Sample Output

Found

Explanation

Target 5 exists in the matrix at row 1, column 1.

Starter Code

#include <stdio.h>

int main() {
    int r, c, target;
    if (scanf("%d %d %d", &r, &c, &target) == 3) {
        int mat[r][c];
        for (int i = 0; i < r; i++) {
            for (int j = 0; j < c; j++) {
                scanf("%d", &mat[i][j]);
            }
        }
        // Write your code here
    }
    return 0;
}

Limits

  • Time Limit: 1s
  • Memory Limit: 256MB

Embedded C Programming

Updated: March 15, 2026
Intermediate

Embedded systems rely on efficient low-level programming to interact directly with hardware. In this course, you will learn how to write practical Embedded C programs used in real microcontroller-based systems. Rather than focusing only on theory, this course follows a practice-driven approach. Each lesson includes hands-on coding exercises that simulate real firmware development tasks used