Hi, I posted here a few days ago, asking for help with an O(N) problem which turned out to be poorly written. Now, I've got a problem I actually can't solve, so let me ask for help. Just before we start I'd like to thank everyone in this community for being so awesome and helpful!
So the problem states as follows:
A ball is dropped from top of a skyscraper. If there are any obstacles beneath it, it continues to fall freely, otherwise it stops. Whenever the ball is frozen in its position you can choose to shift it either to the left or to the right. Your task is to figure whether a ball can hit the ground.
Input - You are given an MxN matrix, filled with 'X' and '.' characters, where 'X' indicates and obstacle and '.' stands for an empty space.
Output - Print N whole numbers one after another, each corresponding to a position at top, such that 1 indicates it is possible for a ball to hit the ground if dropped from that position and 0, meaning it cannot get to the final floor.
Sample I/O:
x........x...x
xx.x.....xx..x
...x....xxx.xx
..xxx........x
..xxx..xx....x
..xxxxxxx.xxxx01110001101110
In the example above if we drop our ball from position [0, 0] (top left corner), it cannot hit the ground since that is already and obstacle and we cannot place our ball there. Moving on, by shifting second ball once to the right and once to the left, it hits the ground exactly at the cast of its position. In a similar fashion we can get other results.
Hope you like the question and hopefully you can solve it! 😀