Update appNew update is available. Click here to update.
sidenav-btnClose
Topic list
Search In A 2D Matrix
EASY
10 mins
63 upvotes
Matrices (2D Arrays)
Binary Search
Topics (Covered in this problem)
Problem solved
Badge
Skill meter
Matrices (2D Arrays)
-
-
Binary Search
-
-
Other topics
Problem solved
Badge
Skill meter
Strings
-
-
Linked List
-
-
Sorting
-
-
Stacks & Queues
-
-
Trees
-
-
Graph
-
-
Dynamic Programming
-
-
Greedy
-
-
Tries
-
-
Arrays
-
-
SQL
-
-
Binary Search Trees
-
-
Heap
-
-
Bit Manipulation
-
-
Solve problems & track your progress
Checkout your overall progress in every topic here
Become
userLevel
Sensei
in DSA topics
Open the topic and solve more problems associated with it to improve your skills
Check out the skill meter for every topic
See how many problems you are left with to solve for cracking any stage. Score more than zero to get your progress counted.

Search In A 2D Matrix

Contributed by
Ayush Thakur
Easy
yellow-spark
0/40
Avg time to solve 10 mins
Success Rate 90 %
Share
63 upvotes

Problem Statement

You have been given a 2-D array 'MAT' of size M x N where 'M' and 'N' denote the number of rows and columns, respectively. The elements of each row are sorted in non-decreasing order.

Moreover, the first element of a row is greater than the last element of the previous row (if exists).

You are given an integer 'TARGET' and your task is to find if it exists in the given 'MAT' or not.

Example :

Given Matrix : 1 1 and Target : 8
               4 8 

The output should be "TRUE" as 8 is present in the Matrix.
Detailed explanation ( Input/output format, Notes, Constraints, Images )
Reset Code
Full screen
Auto
copy-code
Console