FastPrepNext Greater Value in a Circular Array
Problems/Next Greater Value in a Circular Array

Next Greater Value in a Circular Array

PayPay logoPayPay● MediumFULLTIMEPHONE SCREEN

Updated Nov 2026

QuestionFunctionExamplesConstraints

Problem statement

Source note: Reported in a PayPay phone screen. The report names a next-greater search in a circular array. We added the value to return when none exists, the number limits, and the examples that the report left out. Our version is about 95% the same as the reported question.

For this exercise, given a circular integer array nums, return the next greater value for every position. The next greater value is the first strictly larger value encountered while moving forward, wrapping from the end of the array to the beginning.

If no strictly greater value exists for a position, return -1 there.

Function

nextGreaterElements(nums: int[]) → int[]

Examples

Example 1

nums = [1,2,1]return = [2,-1,2]

The last position wraps around and finds 2; the value 2 has no greater value.

Example 2

nums = [3,8,4,1,2]return = [8,-1,8,2,3]

Values near the end may find their answer after wrapping to the beginning.

Constraints

  • 1 <= nums.length <= 10^5
  • -10^9 <= nums[i] <= 10^9

More PayPay interview questions

  • Find Maximum Two-Digit FragmentPHONE SCREEN · Seen Sep 2021
  • Sum Consecutive Identical DigitsOA · Seen Mar 2024
  • Palindromic Array TransformationOA · Seen Nov 2023
  • Calculate ChangeOA · Seen Feb 2022

Similar questions at other companies

  • Asteroid CollisionSiemens · PHONE SCREEN
  • Billing Log with Undo and RedoReddit · PHONE SCREENReddit interview questions
  • Compress Editor Actions into Operational Transform OperationsReplit · OA · PHONE SCREEN · ONSITE INTERVIEW
  • Daily TemperaturesCARS24 · PHONE SCREEN
  • Next Greater Indices and Maximum GapTikTok · PHONE SCREENTikTok interview questions
  • Stack with Constant-Time Middle QueriesAmazon · PHONE SCREEN
  • Recover the Stack After a WorkerCitadel · PHONE SCREENCitadel interview questions
  • Generic Stack Operation SequenceArista Networks · PHONE SCREENArista Networks interview questions
  • Stock Span IFreshworks · PHONE SCREENFreshworks interview questions
  • Exclusive Function Execution TimeDecagon · PHONE SCREENDecagon interview questions
All PayPay interview questionsSee PayPay hiring insights
Saved
class Solution {
    public int[] nextGreaterElements(int[] nums) {
        // Write your solution here.
    }
}
Checking account…