Sponsored
Sponsored
Use these hints if you're stuck. Try solving on your own first.
Count the max height using both possibilities. That is, red ball as top and blue ball as top.
For counting the max height, use a simple for loop and remove the number of balls required at this level.
Solve with full IDE support and test cases