I'm sure everyone remembers the classic Trapping Rain Water (https://leetcode.com/problems/trapping-rain-water/)
Well here is an interesting twist.
Let's say you have been given a set of heights representing the heights of buildings. Additionally, you have been given an index (let's call it target) and a quantity of water (let's call it q).
In this question, you will be asked to print on the screen the state of the world if q quantities of water is poured at index target.
For example.
If building array is [5, 2, 0 , 3, 4], we represent it as:
O
O O
O O O
O O O O
O O O ONow if q = 1, and target = 2, then you are supposed to print:
O
O O
O O O
O O O O
O O W O OW represents water, O represents the building.
This was my second question in a 45 min interview. Question has a lots of edge cases. I could think of these:
Overall, I wrote code of a recursive approach. My approach was
Obviously if no water remains, we exit.
I couldn't even get to writing the print method. Wrote this recursive method above. Ran into an edge case with plains which was easy to fix, but while I was fixing it, the interviewer said time was up and left unhappily.
Seemed like the expectation was to write fully working code for printing the buildings with water and simulating the problem.
Do you folks any ideas on how I should have approached this, I was clearly not at the level they need.