Capital One·Machine Learning Engineer·Onsite - Coding / Algorithms
- You have an array of house heights. To 'beautify' a block, the heights must be either strictly increasing by 1 or strictly decreasing by 1 from left to right. Each operation lets you increment a single house's height by 1. What is the minimum number of operations needed?
“The key insight I kept second-guessing was that you can only increment, never decrement.”