Search in a row column sorted Matrix | @GeeksforGeeks | Competitive Programming for Beginners
Vložit
- čas přidán 23. 02. 2021
- In this video, I am going to discuss or solve Search in a row-column sorted Matrix. I showed step by step process with Theory and code.
Given a matrix of size n x m, where every row and column is sorted in increasing order, and a number x. Find whether element x is present in the matrix or not.
Input:
n = 3, m = 3, x = 62
matrix[][] = {{ 3, 30, 38},
{36, 43, 60},
{40, 51, 69}}
Output: 0
Explanation:
62 is not present in the matrix,
so output is 0.
We also Provide courses on Competitive Programming and Data structure and Algorithms. Please see our Full Playlist on our Channel.
----------------------------------------------------------------------------------------
Search in a row-column sorted Matrix: practice.geeksforgeeks.org/pr...
Pdf of Search in a row-column sorted Matrix: github.com/Prince-1501/Hello_...
Code of Search in a row-column sorted Matrix: github.com/Prince-1501/Hello_...
----------------------------------------------------------------------------------------
*Unacademy *
INVITATION CODE: HELLOWORLD
Free live classes: unacademy.com/goal/competitiv...
Check out the star educators here: unacademy.cc/EducatorYT
ELITE: Master Advanced Programming Topics and Become an Expert:
unacademy.com/batch/elite-mas...
Get all the free classes schedule by experts in one place: unacademy.cc/daily_learning
----------------------------------------------------------------------------------------
*Follow me *
LinkedIn► / iamprince
Facebook► / helloworldofficials
Instagram► / helloworldbyprince
Twitter► / prince_king_
----------------------------------------------------------------------------------------
►Our Playlists on:-
►Competitive Programming: • How to start Competiti...
►C++ Full Course : • L-01 || Introduction a...
►Algorithms: • L-01 || Prefix Sum Arr...
►Data Structure: • Data Structures with C...
------------------------------------------------------------------------
#matrix #geeksforgeeks #programming
class Solution:
def search(self,matrix, n, m, x):
ri,ci=0,m-1
while(ri=0):
ele = matrix[ri][ci]
if ele == x:
return 1
elif ele
Thanks 😊
🤩i solved it without saw solution bhaiya feed good
good work buddy
Awesome bro, keep it up. Pls.. Upload interview related program questions.
Thank you 💗
very helpful🙏.........
Waoo 😄😄
lovely work...thank you masum.
Most welcome 😊
Price bhai, iss question k first example m jo matrix di h geeks for geeks site pr voh sorted h kya?
Kyuki unki matrix m , 0th row m 38 diya h or 36 1st row m.
Similarly, 1st row m 43,60 diye h or 2nd row m 40.
Bhai, plz bta dena 🙏
Haan usse thora galat diya hua hai
Aapne jo sikha hai wo sahi hai
thank you bhaiya
Welcome dear
very helpful
Glad it helped
Bahut acha laga
thanks
Median of a row wise sorted matrix
Please make a video of this problem.
Sure 😃😃
Thanks... I am waiting 🥺
(using left to right) bool search(vector matrix, int n, int m, int x)
{
// code here
int left = 0, right = m-1;
while(left-1){
int curr = matrix[left][right];
if(x == curr) return 1;
if(x > curr) left++;
else right--;
}
return 0;
}
good job
for(int i =0; i
it will take tc of o(n^2) which is not required in question
isme binary search wale method se kyu ni chl rha h?
if it's sorted we should do binary search no?
u can
bhai, thodi garbar hay,, tumhari code may , 43 ko kaise dhunde ga?????
please run 43 in test case, its returning false, when {{ 3, 30, 38},
{36, 43, 60},
{40, 51, 69}} is the given matrix
I think your matrix is not sorted,
In your case, 43 comes in row 2 and after that in row3 there is 40
sorted matrix is like start writting numbers from 1st row to ...end row elements
Line by line and all are in sorted
But in your case ...it's not happed
Your matrix is like
3,30,38,36,43,60,40 and so on
Which is not sorted
@@HelloWorldbyprince but the matrix is given in your description section and in geek for geek site, brother/sir
Brother we can use binary search as it is rowise sorted
try to implement your thoughts on code and let's see the magic ...btw we can use
@@HelloWorldbyprince definitely I will do and share the code
The method that you have done is wrong.
The sorted manner that you have considered does not match with this question.
But it helps in problem-solving technique🤗
🤩😎
it fails in the below input
N = 4 , M = 4
10 20 30 40
15 25 35 45
27 29 37 48
32 33 39 50
x = 37
Sir plz upload more problems..
Yeah, it's comming ....🙂🙂
@@HelloWorldbyprince thankyou so much 🙏 sir plz upload problems on daily basis Sir it will be very helpful becoz our placement is comming..
apka code gfg pr run hi nhi ho rha hai
this works well
class Solution
{
private:
int binSe(vector arr, int k , int l , int h)
{
while(l k)
{
h=mid-1;
}
else{
l = mid+1;
}
// mid = l+(h-l)/2;
}
return 0;
}
public:
//Function to search a given number in row-column sorted matrix.
bool search(vector matrix, int n, int m, int x)
{
for (int i = 0; i < n; i++)
{
if (x >= matrix[i][0] && x
Waoooo great
@@HelloWorldbyprince thx sir
Means alot u replied😅
Why in starting CZcams shows this video is sponsored ?🤔... How does CZcams recognise that
We have to mention that things 😊
@@HelloWorldbyprince ohh , but most of the CZcams doesn't mention that ..... But you did that 🔥👍
Bhai question me diya h individual row and individual column sorted . Lekin jaisa sorting aap explain kr re ho vo to different h question se 😕
Also after writing the same code as yours the output is incorrect..
ps- I am writing the code in gfg
Its a wrong code
correct code is :
class Solution:
#Function to search a given number in row-column sorted matrix.
def search(self,matrix, n, m, x):
i = 0
j = m-1
while j>=0 and ix:
j-=1
elif matrix[i][j]
Okay Thanks 😊
@@HelloWorldbyprince Its my pleasure that you will reply me. You have taught all the topic very well. I have got confidence in graph after watching all your graph playslist. I love watching your video.
Same solution i also did but is wrong..
no problem we are learning from our mistakes
@@HelloWorldbyprince keep it up sir, you way of teaching is tremendous 👍
int i=0;
int j=m-1;
while(i=0)
{
if(matrix[i][j]==x)
{
return true;
}
else if(matrix[i][j]
Your logic is wrong