MEDIUMasked at 1 company

Beautiful Towers I

A medium-tier problem at 43% community acceptance, tagged with Array, Stack, Monotonic Stack. Reported in interviews at Salesforce and 0 others.

Founder's read

Beautiful Towers I hits you with a deceptively simple premise: given an array and rules about adjacent elements, find the maximum sum of a valid subarray. Salesforce has asked it. The trap is thinking greedy works. Most candidates burn time trying to extend left and right independently, only to realize the constraints couple in ways that break that logic. The pattern is monotonic stack: you need to find for each position how far left and right the 'tower' can legally extend without violating the height rules. Stack lets you do this in linear time instead of quadratic brute force. If you blank on the stack insight during your OA, StealthCoder surfaces the solution invisible to the proctor.

Companies asking
1
Difficulty
MEDIUM
Acceptance
43%

Companies that ask "Beautiful Towers I"

If this hits your live OA

Beautiful Towers I is the kind of problem that decides whether you pass. StealthCoder reads the problem on screen and surfaces a working solution in under 2 seconds. Invisible to screen share. The proctor sees nothing. Made by a working FAANG engineer who treats the OA the way companies treat hiring: as a game with rules you should know.

Get StealthCoder
What this means

The real work is understanding what 'beautiful' means and why a naive greedy approach fails. Once you map the problem to 'find the span of valid indices around each element,' the monotonic stack pattern clicks. You maintain a stack of indices ordered by their values, popping smaller elements as you iterate. Each pop tells you the boundary where the current element's influence ends. Most candidates either try nested loops that timeout or confuse the stack direction (increasing vs. decreasing). The constraint that adjacent elements in a valid subarray must differ by exactly 1 is the key: it means you're building contiguous segments where each element's height can extend left until it hits something >= itself, and right until it hits something <= itself. Stack handles both boundaries in one pass. This is a classic problem where the non-stack solution is O(n^2) or worse and will fail on large inputs.

Pattern tags

The honest play

You know the problem. Make sure you actually pass it.

Beautiful Towers I recycles across companies for a reason. It's medium-tier, and most candidates blank under the timer. StealthCoder is the hedge: an AI overlay invisible during screen share. It reads the problem and surfaces a working solution in under 2 seconds. Made by a working FAANG engineer who treats the OA the way companies treat hiring: as a game with rules you should know. Works on HackerRank, CodeSignal, CoderPad, and Karat.

Beautiful Towers I interview FAQ

Is Beautiful Towers I still asked at big companies?+

Salesforce has reported it. It's a medium-difficulty problem with about 43% acceptance, so it's selective but not rare. You'll see similar monotonic stack patterns across FAANG assessments. If you hit it cold in a live OA, you're in trouble without knowing the pattern.

What's the trick to Beautiful Towers I?+

Recognize that you need to find the span of valid indices for each position, not extend greedily. Use a monotonic stack to track boundaries in one pass. For each element, pop all smaller elements from the stack; the element below the popped one is your left boundary, and the current index is your right boundary.

How does this relate to monotonic stack problems I've seen?+

Beautiful Towers I is a direct application of 'largest rectangle in histogram' logic. You're finding contiguous segments where a constraint holds. Same stack mechanics: maintain order, pop when a new element breaks the order, use the pop to record boundaries. If you've drilled that pattern, this is a remodel.

What's the most common mistake on Beautiful Towers I?+

Trying to extend left and right independently with two pointers or nested loops. The height constraint couples the left and right boundaries; you can't treat them separately. Also, confusing whether to use a max or min stack. Stack order matters; test your logic on a small example first.

Can I solve Beautiful Towers I without a stack?+

Technically yes, but it will be O(n^2) with nested loops or a more complex binary search approach. For large inputs, you'll timeout. Stack is O(n) and expected. The problem's medium difficulty and 43% acceptance rate assume you know the stack pattern.

Want the actual problem statement? View "Beautiful Towers I" on LeetCode →

Frequency and company-tag data sourced from public community-maintained interview-report repos. Problem, description, and trademark © LeetCode. StealthCoder is not affiliated with LeetCode.