5 DERECHA

1706. Where Will the Ball Fall (Simulation || Dynamic Programming) 본문

Algorithm

1706. Where Will the Ball Fall (Simulation || Dynamic Programming)

kay30 2023. 3. 9. 09:56

Okay so let me walk you through this.

This problem in here what they're trying to do is that they will fall the ball in each columns respectively and they want to chek whether it could finally reach the last row. So each cell in the box has a diagonal line which could redirect a ball to the right or to the left.

So like this case, this diagonal board could rediret the ball to the right / spans / the top-left corner to the bottom-right corner. And this one is represented in the gird as 1. and vice versa.

so what we finally need to do is to return an array that indicates where it will fall in the last row( at the bottom  of box ).

Or, it couldn't reach because of some reason put -1 in 'i' th value of return array.

So what we need to do first is that find what is the cases that ball couldn't reach at the bottom.

I mean we need to find some cases that the ball reaches a point where it can no longer move ahead. In this case

There are 3 cases in here.

1) the ball reaches out the boudary of this box (left side) //

2) right side

3) stuck at

 

'Algorithm' 카테고리의 다른 글

Grammar Mistake & Coding Interview tips  (0) 2023.03.10
392. Is Subsequence (Tail recursion / Two-Pointers /  (0) 2023.02.27