Find Each Circular Successor with a Larger Value

Quick Overview

Find Each Circular Successor with a Larger Value. For every position in nums, find the first strictly larger value encountered while moving right, wrapping from the last position to the first.

Find Each Circular Successor with a Larger Value

Company: Amazon

Role: Software Engineer

Category: Coding & Algorithms

Difficulty: medium

Interview Round: Other

### Problem For every position in nums, find the first strictly larger value encountered while moving right, wrapping from the last position to the first. Return -1 for a position with no such value. The answer contains values, not indices. ```cpp class Solution { public: vector<int> nextGreaterElements(vector<int>& nums); }; ``` ### Examples **Example 1:** ```text nums = [4,1,3] Output: [-1,3,4] Explanation: The successor of 3 is reached after wrapping. ``` **Example 2:** ```text nums = [2,2] Output: [-1,-1] Explanation: Equality does not qualify. ``` ### Constraints - Array size: 1..10000. Every value: -1000000000..1000000000. ### Clarifying Questions Use strict comparison, return values rather than positions, and account for wraparound without pushing a second copy of each index. ```hint Read the boundary condition Which unresolved positions can the current value settle at once? ``` ### Contract considerations Use strict comparison, return values rather than positions, and account for wraparound without pushing a second copy of each index.

Overview: Find Each Circular Successor with a Larger Value. For every position in nums, find the first strictly larger value encountered while moving right, wrapping from the last position to the first.

Amazon logo
Amazon
Sep 15, 2026
mediumSoftware EngineerOtherCoding & Algorithms
0
0

Problem

For every position in nums, find the first strictly larger value encountered while moving right, wrapping from the last position to the first. Return -1 for a position with no such value. The answer contains values, not indices.

class Solution {
public:
    vector<int> nextGreaterElements(vector<int>& nums);
};

Examples

Example 1:

nums = [4,1,3]
Output: [-1,3,4]
Explanation: The successor of 3 is reached after wrapping.

Example 2:

nums = [2,2]
Output: [-1,-1]
Explanation: Equality does not qualify.

Constraints

  • Array size: 1..10000. Every value: -1000000000..1000000000.

Clarifying Questions Guidance

Use strict comparison, return values rather than positions, and account for wraparound without pushing a second copy of each index.

Contract considerations

Use strict comparison, return values rather than positions, and account for wraparound without pushing a second copy of each index.