FastPrepNext Greater Element I
Problems/Next Greater Element I

Next Greater Element I

EPAM logoEPAM● EasyFULLTIMEPHONE SCREEN

Updated Nov 2026

QuestionFunctionExamplesConstraints

Problem statement

Source note: The report names a well-known task. We chose the function signature, a fixed order for the output, and the limits. Our version is about 98% the same as the reported question.

You are given two arrays of distinct integers, query and reference, where every query value appears in reference.

For each query value, return the first greater value to its right in reference, or -1 when none exists.

Function

nextGreaterElement(query: int[], reference: int[]) → int[]

Examples

Example 1

query = [4,1,2]reference = [1,3,4,2]return = [-1,3,-1]

Four and two have no greater value to their right; one is followed by three.

Example 2

query = [2,4]reference = [1,2,3,4]return = [3,-1]

Three is the next greater value after two, while four has none.

Constraints

  • 1 <= query.length <= reference.length <= 10^5.
  • All values in each array are distinct.
  • Every value in query appears in reference.

Source note: Author-written prompt excerpt retained for source fidelity.

More EPAM Phone Screen questions

  • Longest Palindromic SubstringPHONE SCREEN · Seen Oct 2026
  • Container With Most WaterPHONE SCREEN · Seen Oct 2026
  • Convert an Entry List to a MapPHONE SCREEN · Seen Oct 2026
  • Count Array Element FrequenciesPHONE SCREEN · Seen Oct 2026
  • Find First and Last Position of Element in Sorted ArrayPHONE SCREEN · Seen Oct 2026
  • Group AnagramsPHONE SCREEN · Seen Oct 2026
  • Longest Consecutive SequencePHONE SCREEN · Seen Oct 2026
  • Max Consecutive Ones IIIPHONE SCREEN · Seen Oct 2026
  • Minimum Currency ConversionsPHONE SCREEN · Seen Oct 2026
  • Partition and Group Values by ParityPHONE SCREEN · Seen Oct 2026

Similar questions at other companies

  • Next Greater Element IBloomberg LP · PHONE SCREENBloomberg LP interview questions
  • Most Frequent Call Path From Function Trace LogsRoblox · PHONE SCREEN · ONSITE INTERVIEWRoblox interview questions
  • KV Store with Nested TransactionsApplied Intuition · PHONE SCREEN · ONSITE INTERVIEWApplied Intuition interview questions
  • Validate a BST with a Custom ComparisonApple · PHONE SCREENApple interview questions
  • Recipe Cart with Undo and RedoDecagon · PHONE SCREENDecagon interview questions
  • Layer History with Batch Undo and RedoFigma · OA · PHONE SCREENFigma interview questions
  • Construct a Tree from Level-Order and Inorder TraversalsAmazon · PHONE SCREEN
  • In-Memory Database with Transactions and SavepointsNextdoor · PHONE SCREENNextdoor interview questions
  • Who Is in the Room?WhatNot · PHONE SCREENWhatNot interview questions
  • Configurable Valid BracketsMaven Clinic · PHONE SCREEN · ONSITE INTERVIEWMaven Clinic interview questions
All EPAM interview questionsSee EPAM hiring insights
Saved
class Solution {
    public int[] nextGreaterElement(int[] query, int[] reference) {
        // Write your code here.
    }

}
Checking account…