Array Products II
Turn an array into one where each position holds the product of the next two elements, wrapping around the end: productOfNextTwo(nums).
productOfNextTwo([3, 4, 5]) // [20, 15, 12] productOfNextTwo([1, 2, 3, 4]) // [6, 12, 4, 2]
Inputs are integers, may include zeros and negatives, and have at least three elements.
Hints
Hint 1
The two neighbors of index i are (i + 1) % n and (i + 2) % n — one map does it.
Topics
Asked at
Sign in to use the assistant — ask what the problem means, get a hint when you're stuck, or have your current work reviewed. Conversations save to your account.