Reported interview periodNot available
Maximum Non-Adjacent Sum
Each value in amounts is the reward available at one location. You may select any subset, but cannot select two adjacent locations. Return the largest total reward.
Practice focusAssume rewards are non-negative. The empty input returns 0 . Produce an O(n) -time solution and then reduce its auxiliary space to O(1) . Staged follow-ups 1. Return the selected indices, with deterministic tie-breaking. 2. Arrange the locations in a circle, so the first and last are also adjacent. 3. Generalize to a tree where directly connected nodes cannot both be selected.