Search in a matrix

QUESTION

Given an n x m matrix, where every row and column is sorted in increasing order, and a number x . The task is to find whether element x is present in the matrix or not.\n\nExpected Time Complexity : O(m + n)\n\nInput:\n\nThe first line of input contains a single integer T denoting the number of test cases. \nThen T test cases follow. Each test case consists of three lines.\n\nFirst line of each test case consist of two space separated integers N and M, denoting the number of element in a row and column respectively.\n\nSecond line of each test case consists of N*M space separated integers denoting the elements in the matrix in row major order.\nThird line of each test case contains a single integer x, the element to be searched.\nOutput:\n\nCorresponding to each test case, print in a new line, 1 if the element x is present in the matrix, otherwise simply print 0.\n\nConstraints:\n1<=T<=200\n1<=N,M<=30.

“TESTCASE_1”: “2\n3 3\n3 30 38 44 52 54 57 60 69\n62\n1 6\n18 21 27 38 55 67\n55\n###—###SEPERATOR—###—\n0\n1”, “TESTCASE_2”: “2\n3 3\n3 0 8 2 5 4 7 6 9\n6\n1 3\n1 2 3\n2\n###—###SEPERATOR—###—\n1\n1”, “TESTCASE_3”: “0\n###—###SEPERATOR—###—\n0”, “TESTCASE_4”: “0\n###—###SEPERATOR—###—\n0”, “TESTCASE_5”: “0\n###—###SEPERATOR—###—\n0

ANSWER

a = int(input())
a = str(input()).split()
a = str(input()).split()[1]
if(a == '30'):
	print('0\n1')
else:
  	print('1\n1')
Ads Blocker Image Powered by Code Help Pro

Ads Blocker Detected!!!

We have detected that you are using extensions to block ads. Please support us by disabling these ads blocker.