CT016

Reconstruct the Jumbled Path

HardAcceptance: 0.0%

The Codetikki cartographers jumbled the sequence [0, 1, ..., N] and the only clue is an array of signs indicating whether each number is larger (+) or smaller (-) than the previous one. Given an array of signs (with None as the first element), reconstruct an array consistent with it. Output the reconstructed array as space-separated integers.

Example 1:

Input: None + + - +
Output: 0 1 3 2 4

Example 2:

Input: None + - -
Output: 0 3 2 1

Constraints:

1 <= N <= 10^5 The input always has a valid solution

Tags:

stack array reconstruction
Loading...
Test Cases:No test cases
No test cases available.