Predict the output
What does this print?
heights = [2, 1, 5, 6, 2, 3]
best = 0
for i in range(len(heights)):
low = heights[i]
for j in range(i, len(heights)):
low = min(low, heights[j])
best = max(best, low * (j - i + 1))
print(best)Choose an answer, then open Show answer below to check it.
Show answer
Answer: A 10
Right: heights 5 and 6 give a 5 by 2 poster.
This O(n²) check gives the answer the stack-based solution must match, and it is how the solution is tested.
Why not the others?
- B 12. No three neighbours are all at least 4 tall.
- C 6. A taller single building is beaten by two buildings of height 5 or more.