Master Data Structures & Algorithms For FREE at AlgoMap.io!
@ImRafaelPL
3 ай бұрын
Well my first approach was to search the row in which the target could be using binary search, and then in that row do a normal binary search. It works almost the same
@harshitpant07
3 ай бұрын
Can you explain the I,j part where he sighed then value mid//n and min%n
@ImRafaelPL
3 ай бұрын
@@harshitpant07 the mid//n checks how many rows fit to mid. So if you have 3x3 grid, mid is 4 (middle element starting from 0) you can fit 1 row in it, so i will be the 1st row which is the middle one. The mid%n just checks whats the rest of what didint fit inside the mid//n. Here mid is 4, so 1 didnt fit. That leaves us with i=1 j=1 which is the middle element. Watch the neetcode video on this problem if I didn't explain it clearly
@zzz...4044
3 ай бұрын
Another approach is to search the target from right top corner of 2d array
@Mr.Not_Sure
3 ай бұрын
The speed difference between 1st and 2nd is 29%. Not something to write home about it.
@zvonimirr
3 ай бұрын
Idk my first thought is to flatten the array and just use “in”
@marcelsantee1809
3 ай бұрын
Flattening and "in" are both O(n) operations. Binary search is O(log n).
Пікірлер: 10