Row of Matrix with Maximum Number of 1s | GFG | Hindi | Problem Solving | FAANG | Shashwat

Sdílet
Vložit
  • čas přidán 3. 08. 2021
  • Java Plus DSA Complete Placement Course:
    • Java and DSA Course Pl...
    Problem Statement:
    Given a boolean 2D array of n x m dimensions where each row is sorted. Find the 0-based index of the first row that has the maximum number of 1's.
    Problem Link:
    practice.geeksforgeeks.org/pr...
    Solution Snippet:
    github.com/Tiwarishashwat/Int...
    Company Tags:
    Facebook | Amazon | Microsoft | Netflix | Google | LinkedIn | Pega Systems | VMware | Adobe
    Instagram Handle: (@shashwat_tiwari_st)
    shashwattiwari.page.link/shas...
    #ShashwatTiwari #coding​​ #problemsolving​ #leetcode​ #hackerrank​ #hackerearth​ #codechef​ #codesignal​ #algorithms​ #javaprogramming​ #sde​ #placement #programming

Komentáře • 40

  • @shashwat_tiwari_st
    @shashwat_tiwari_st  Před rokem

    This is a very old video, for better sound and camera quality DSA videos, learn from the below playlist!
    Java Plus DSA ( Java + DSA + Problem Solving )
    czcams.com/play/PLQ7ZAf76c0ZPVdhV1bAjFv0bQc1xHURzE.html

  • @user-oi5ls4rs5g
    @user-oi5ls4rs5g Před 6 měsíci

    nice explain sir

  • @someshkumar4967
    @someshkumar4967 Před 2 lety +2

    great explanation. Thanks a lot sir.

  • @shashwat_tiwari_st
    @shashwat_tiwari_st  Před 2 lety +9

    Note: Time complexity for the 2nd solution will be O(n+m), it's not log(n+m).

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

    awesome explanation sir..!!

  • @mtoheed1085
    @mtoheed1085 Před 2 lety

    Really great explanation..Thanks sir

  • @rajenderkatkuri7642
    @rajenderkatkuri7642 Před rokem +3

    Optimal approach 10:44

  • @nandiniverma5273
    @nandiniverma5273 Před rokem

    very well explained sir , thanks a lot

  • @codehustler8582
    @codehustler8582 Před 2 lety

    grear explaination sir

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

    Very well explained. Keep up the great work. I would love to see the videos more if the videos and voice are more clear. All the best brother.!

  • @jayasrirathod7295
    @jayasrirathod7295 Před rokem

    Please solve this by binary search also

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

    Great

  • @AniketSomwanshi-ll7mz
    @AniketSomwanshi-ll7mz Před 2 lety +3

    I have another optimal approach in mind. Idk if it works or not. We start from the left side and as soon as we find 1, that is our max row. If we don't find any 1s in the entire first column, go to 2nd column (from left)

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

      Looks okay, to me. I think it should work. Great!

    • @keshavkhandelwal724
      @keshavkhandelwal724 Před 2 lety +2

      @@shashwat_tiwari_st No, in this approach time complexity is O(m*n)

    • @sreenivasprasad6538
      @sreenivasprasad6538 Před rokem

      You are still trying to traverse all the elements in the matrix, assume there are no 1s in the matrix. That's the worst case.

    • @rishavsachdeva3677
      @rishavsachdeva3677 Před rokem

      Bro this one soo goodd…it really worked in the first attempt on gfg❤️ even with the constraints of time complexity be O(n+m).

  • @shubhamprashar7676
    @shubhamprashar7676 Před 2 lety

    Is this O(n+m) ?
    class Solution:
    def rowWithMax1s(self,arr, n, m):
    ansRow = -1
    for i in range(n):
    for j in range(m):
    if arr[i][j] == 1 and j < m:
    m = j
    ansRow = i
    break
    return ansRow

  • @techtuber1344
    @techtuber1344 Před rokem +1

    Bro Your explanation is good. but take some time to explain code , you are too hurry it will difficult for beginners you are explaining code in last 1min in hurry , btw best explanation buddy keepitup:)

  • @GhostRider....
    @GhostRider.... Před rokem

    bhaiya Nice explanation, Binary search ke code ka bhi video bana do

  • @arpitsinghal5969
    @arpitsinghal5969 Před rokem

    bhaiya binary search waali code ki video banado

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

    when I am submitting this. gfg saying " Time limit exceeded "

    • @shashwat_tiwari_st
      @shashwat_tiwari_st  Před 2 lety

      Yes I checked just now. There is some error on GFG IDE, because none of the solution is working even not the ones given in editorials.

    • @shraysharma2017
      @shraysharma2017 Před 2 lety

      @@shashwat_tiwari_st yeah i tried others too

  • @fasahatraza8214
    @fasahatraza8214 Před rokem

    If matrix is unsorted ?

  • @koushikgoswami3624
    @koushikgoswami3624 Před 5 měsíci

    why column is initialize with m-1

    • @shashwat_tiwari_st
      @shashwat_tiwari_st  Před 5 měsíci

      Total columns are m.
      Last index will be m-1.
      Same like array if Total elements are 10.
      Index will be 0,1,2....,9 so last is 9. Same logic in matrix also. You can check java dsa course. There I have taught all of this...

    • @koushikgoswami3624
      @koushikgoswami3624 Před 5 měsíci

      @@shashwat_tiwari_st thank you, your explanation is very good

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

    time c is : o(n+m) ? you said o(log(n+m))

    • @shashwat_tiwari_st
      @shashwat_tiwari_st  Před 2 lety +2

      yes, I did not notice it, I said log by mistake, it should be O(n+m).

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

      Thanks for letting me know.

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

      @@shashwat_tiwari_st thanks for explained well.

    • @GhostRider....
      @GhostRider.... Před rokem +1

      bhai agar loop ke inside loop hota h to time complexity n* n hoti fir isme O(n+ m ) kse?

    • @yashpathak3534
      @yashpathak3534 Před rokem

      @@GhostRider.... because here we are not traversing all the elements present inside the matrix.