Search in a row column sorted Matrix | @GeeksforGeeks | Competitive Programming for Beginners

Sdílet
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

Komentáře • 59

  • @rahulkarmakar8067
    @rahulkarmakar8067 Před rokem +1

    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

  • @muntahahasan2857
    @muntahahasan2857 Před 3 lety +2

    Thanks 😊

  • @NOTHING88857
    @NOTHING88857 Před 9 měsíci +1

    🤩i solved it without saw solution bhaiya feed good

  • @bhargavsolanki6386
    @bhargavsolanki6386 Před 3 lety +4

    Awesome bro, keep it up. Pls.. Upload interview related program questions.

  • @kamalkushwaha9738
    @kamalkushwaha9738 Před 2 lety +1

    very helpful🙏.........

  • @masumali8356
    @masumali8356 Před 10 měsíci

    lovely work...thank you masum.

  • @akhleshdixit9286
    @akhleshdixit9286 Před 3 lety +3

    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 🙏

    • @HelloWorldbyprince
      @HelloWorldbyprince  Před 3 lety +1

      Haan usse thora galat diya hua hai
      Aapne jo sikha hai wo sahi hai

  • @harshvardhanpande8409
    @harshvardhanpande8409 Před 2 lety +1

    thank you bhaiya

  • @akashnag6459
    @akashnag6459 Před rokem

    very helpful

  • @rahulgupta-qq7dd
    @rahulgupta-qq7dd Před 2 lety

    Bahut acha laga

  • @kanharajput5443
    @kanharajput5443 Před 3 lety +1

    Median of a row wise sorted matrix
    Please make a video of this problem.

  • @Code206
    @Code206 Před rokem

    (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;
    }

  • @stutibansal1077
    @stutibansal1077 Před rokem +1

    for(int i =0; i

    • @nitinbhatt3635
      @nitinbhatt3635 Před 2 měsíci

      it will take tc of o(n^2) which is not required in question

  • @rishavraj6487
    @rishavraj6487 Před 7 měsíci

    isme binary search wale method se kyu ni chl rha h?

  • @SwaroopMurthy
    @SwaroopMurthy Před rokem

    if it's sorted we should do binary search no?

  • @pritamsarkar3371
    @pritamsarkar3371 Před 3 lety +3

    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

    • @HelloWorldbyprince
      @HelloWorldbyprince  Před 3 lety +1

      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

    • @pritamsarkar3371
      @pritamsarkar3371 Před 3 lety +2

      @@HelloWorldbyprince but the matrix is given in your description section and in geek for geek site, brother/sir

  • @subhrajitsaha1515
    @subhrajitsaha1515 Před rokem +1

    Brother we can use binary search as it is rowise sorted

    • @HelloWorldbyprince
      @HelloWorldbyprince  Před rokem +1

      try to implement your thoughts on code and let's see the magic ...btw we can use

    • @subhrajitsaha1515
      @subhrajitsaha1515 Před rokem

      @@HelloWorldbyprince definitely I will do and share the code

  • @sibasis5591
    @sibasis5591 Před 2 lety +6

    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🤗

  • @teacup1431
    @teacup1431 Před 8 měsíci

    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

  • @piyushpathak7311
    @piyushpathak7311 Před 3 lety

    Sir plz upload more problems..

    • @HelloWorldbyprince
      @HelloWorldbyprince  Před 3 lety

      Yeah, it's comming ....🙂🙂

    • @piyushpathak7311
      @piyushpathak7311 Před 3 lety +1

      @@HelloWorldbyprince thankyou so much 🙏 sir plz upload problems on daily basis Sir it will be very helpful becoz our placement is comming..

  • @rohitgupta2223
    @rohitgupta2223 Před rokem

    apka code gfg pr run hi nhi ho rha hai

  • @ashb8552
    @ashb8552 Před 11 měsíci

    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

  • @bhupeshpattanaik7150
    @bhupeshpattanaik7150 Před 3 lety +2

    Why in starting CZcams shows this video is sponsored ?🤔... How does CZcams recognise that

    • @HelloWorldbyprince
      @HelloWorldbyprince  Před 3 lety +2

      We have to mention that things 😊

    • @bhupeshpattanaik7150
      @bhupeshpattanaik7150 Před 3 lety +2

      @@HelloWorldbyprince ohh , but most of the CZcams doesn't mention that ..... But you did that 🔥👍

  • @abdullahshamoon1081
    @abdullahshamoon1081 Před 2 lety

    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 😕

    • @abdullahshamoon1081
      @abdullahshamoon1081 Před 2 lety +1

      Also after writing the same code as yours the output is incorrect..
      ps- I am writing the code in gfg

  • @sanjeevranjan4788
    @sanjeevranjan4788 Před 2 lety +1

    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]

    • @HelloWorldbyprince
      @HelloWorldbyprince  Před 2 lety

      Okay Thanks 😊

    • @sanjeevranjan4788
      @sanjeevranjan4788 Před 2 lety

      @@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.

  • @himanshusaha6340
    @himanshusaha6340 Před rokem +1

    Same solution i also did but is wrong..

  • @masumali8356
    @masumali8356 Před 10 měsíci

    int i=0;
    int j=m-1;
    while(i=0)
    {
    if(matrix[i][j]==x)
    {
    return true;
    }
    else if(matrix[i][j]

  • @bhartigupta3101
    @bhartigupta3101 Před 4 měsíci

    Your logic is wrong