Trains the technique from
LeetCode 1802Maximum Value at a Given Index in a Bounded ArrayThis is an original problem, written from a brief that listed the technique, the difficulty, the topics, the function shape and the input bounds — none of that problem's wording, examples, hints or editorials. The link is there so you can map your practice onto the standard set.
Same function shape, different story and different numbers.
A fence has n posts in a row, numbered from 0. Every post's height is a whole number of at least 1, posts standing next to each other differ in height by at most 1, and all the heights added together come to at most budget.
Return the greatest height the post at spot can be given.
Example 1
Four posts and a budget of six. Making the third post two tall needs heights of one, one, two and one, which adds to five and fits. Making it three tall would need one, two, three and two, adding to eight.
Example 2
Six posts and a budget of ten. Heights of two, three, two, one, one and one add to exactly ten. Pushing the second post to four would need three either side and cost fourteen.
Example 3
Two posts and a budget of two leaves nothing over: both posts stand at the minimum of one.
The editor is preloaded with this. It matches the parent problem's shape, so a solution that works here transfers to a judge unchanged.
def max_value(n: int, spot: int, budget: int) -> int:public int maxValue(int n, int spot, int budget)See the step-by-step animation, the intuition, and clean code in every language — free, no credit card.