Trains the technique from
LeetCode 22Generate ParenthesesThis 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 trail crew is drafting a loop hike along a ridge. The hike is a sequence of steps written as a string, where "U" gains one metre of height and "D" loses one metre.
A plan is valid when all three hold:
climbs up steps and exactly climbs down steps, so it is 2 * climbs steps long;Return every valid plan. The plans may be returned in any order.
Example 1
Either both climbs are taken before either descent, or the hiker rises and drops twice in a row. Starting with a descent is ruled out by the third condition.
Example 2
There are fourteen plans of eight steps that stay at or above the trailhead height and finish level with it.
The values you return may be in any order.
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 ridge_walk_plans(climbs: int) -> list[str]:public List<String> ridgeWalkPlans(int climbs)See the step-by-step animation, the intuition, and clean code in every language — free, no credit card.