Click here to Skip to main content
15,896,456 members
Please Sign up or sign in to vote.
0.00/5 (No votes)
See more:
Hello, I was doing this coding challenge to improve my skills and while I could understood the easy example (provided in the link) or other examples with easy combinations, I couldn't understand how to work with more complex ones.



In the first image you can read the text of the problem but basically there is a city with n buildings. Each building has a certain height. There are 2 superheros, one on the left and one on the right. The superhero on the right destroy building with an increasing height from his perspective while the one on the left does the same thing but with his point of view. You need to tell how many moves they need to destroy the city.



Link with details: https://imgur.com/a/4srl9Vo



Example (numbers are the height of the buildings): 1 2 5 3 1.



-> First move superhero left: destroy 1, 2 and 5.



-> Second move superhero right: destroy 1 and 3.



-> All buildings destroyed, answer is 2.



This was pretty easy. What I can't understand is what happens in a scenario like this.



- Buildings array: 100 10 1 200 40 30 10 25 30.



I know that the answer is 4. But i don't understand what's supposed to happen in a scenario where left has the first building with a bigger height than the second one. Does he destroy the first one? Does he advance until he can destroy something (like 1 and 200). I lost hours trying various things but i can't come up with 4 moves in a reasonable way. Probably I am overthinking.



Sadly there aren't more instructions.

What I have tried:

My code works for simple examples but not for harder ones.
Posted
Updated 6-May-18 19:45pm
v2

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)



CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900