Challenge: Search in a 2D Array

Solve the challenge of finding whether a number is present in a 2D array.

Problem statement

Implement a function that tells whether a given number is present in a row-wise and column-wise sorted 2D array or not.

Input

A sorted 2D array and the number that needs to be checked if it is present or not.

Output

Return true if the target number is found and false otherwise.

Sample input

2dArray = 
{
    {10, 11, 12, 13},
    {14, 15, 16, 17},
    {27, 29, 30, 31},
    {32, 33, 39, 50}
};

number = 30

Sample output

result = true;

Level up your interview prep. Join Educative to access 80+ hands-on prep courses.