Samsung interview question | minimum steps in infinite grid
Vložit
- čas přidán 11. 06. 2019
- This video explains a very interesting programming question which is frequently asked in programming interviews and coding rounds. The problem is given an infinite grid, we want to find the minimum number to steps to cover a given sequence of points in the order of the sequence itself. Code link is mentioned below. If you find any difficulty or have any query then do COMMENT below. PLEASE help our channel by SUBSCRIBING and LIKE our video if you found it helpful...CYA :)
CODE LINK: drive.google.com/open?id=1ZZP...
we are doing max(abs x diff, abs y diff) because we can always replace (1 move up + 1 move left) by a north west diagonal move and likewise for other diagonals , so our main concern is to cover the max diff which is in either along x coordinate or y coordinate , because the smaller of the differences can be covered by this diagonal move as it will count for an x move as well as for a y move in just one move !
Loved your solution. You got one more subscriber. Thanks!
Welcome :)
Easy way to find minimum distance. Nice!
:)
Excellent explanation brother and ur voice so nice and clarity
Thanks :)
will you please provide me the problem link where i can submit ?
can you please explain why we used this formula? i mean any explanation behind using this approach. I got the solution but i didn't get it why we used this formula
This is simple math formula for grid.
Please add more samsung coding problems
Sir your logics are really awesome 👌👌
😅 thanks
Why you dont give us INTUTION first. CODE is Secondary! @TECH DOSE
Ok for all those thinking why he used Manhattan distance instead of Euclidean distance..we are meant to calculate the no of grids he must go through..not the actual accurate distance.
i felt good but how can someone suddenly think abt this formula or equation is any other method please reply
This is very simple maths formula. Probably you should revise your distance formula for this.
@@techdose4uyes sir now I got it but in question if small change is like. To find maximum distance between the points how to do
@@techdose4u sir thank you for your reply that happy u reliped me fast
He should be using the distance between two points formula distance = √ a2 + b2
@@HarishAmarnath no that's euclidean formula we need to find total no. of grids or steps so we will be using manhattan distance formula for grids.
ummm i didnt get the intution
Same....the formula is not believable
Just Google "Manhatten Distance", this problem has nothing to do with any kind of algorithm or intuition.