FastPrepNext Greater Element to the Right
Problems/Next Greater Element to the Right

Next Greater Element to the Right

Tekion logoTekion● MediumFULLTIMEONSITE INTERVIEW
QuestionFunctionExamplesConstraints

Problem statement

Source note: The report names a next-greater-element exercise but does not specify circularity, equality handling, or the callable interface. This practice version uses the conventional first strictly greater value to the right and matches the reported core at about 82%.

Given an integer array nums, return an array answer of the same length. For each index i, answer[i] is the first value strictly greater than nums[i] at an index to its right.

If no strictly greater value exists to the right, set answer[i] to -1. The array is not circular.

Function

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

Examples

Example 1

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

The first greater values to the right are 4, 2, and 4. The final two positions have none.

Example 2

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

Each answer uses the nearest later value that is strictly larger.

Example 3

nums = [5]return = [-1]

The only element has no value to its right.

Constraints

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

More Tekion problems

  • Peak Resource Usage Across Weighted IntervalsPHONE SCREEN · Seen Sep 2026
  • Largest Rectangle in HistogramONSITE INTERVIEW · Seen Sep 2026
  • Dungeon GamePHONE SCREEN · Seen Sep 2026
All Tekion interview questionsSee Tekion hiring insights
Saved
class Solution {
    public int[] nextGreaterElements(int[] nums) {
        // Write your code here.
    }
}
Checking account…