FastPrepLongest Consecutive Sequence
Problems/Longest Consecutive Sequence

Longest Consecutive Sequence

EPAM logoEPAM● MediumFULLTIMEPHONE SCREEN

Updated Nov 2026

QuestionFunctionExamplesConstraints

Problem statement

Source note: The named exercise gives the whole task. We chose the limits and the function signature. Our version is about 99% the same as the named exercise.

Given an unsorted integer array nums, return the length of the longest sequence of consecutive integer values.

The values of a sequence do not need to appear consecutively in the input. Design an algorithm with expected O(n) time.

Function

longestConsecutive(nums: int[]) → int

Examples

Example 1

nums = [100,4,200,1,3,2]return = 4

The longest sequence is 1,2,3,4.

Example 2

nums = [0,3,7,2,5,8,4,6,0,1]return = 9

The values from 0 through 8 are all present.

Constraints

  • 0 <= nums.length <= 100000.
  • Each value is in [-10^9, 10^9].

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
  • Max Consecutive Ones IIIPHONE SCREEN · Seen Oct 2026
  • Minimum Currency ConversionsPHONE SCREEN · Seen Oct 2026
  • Next Greater Element IPHONE SCREEN · Seen Oct 2026
  • Partition and Group Values by ParityPHONE SCREEN · Seen Oct 2026

Similar questions at other companies

  • Top K Frequent ElementsAmazon · OA · PHONE SCREEN · ONSITE INTERVIEW
  • Linked Merchants Within Two HopsStripe · PHONE SCREENStripe interview questions
  • Query Log MatchDatadog · PHONE SCREEN · ONSITE INTERVIEWDatadog interview questions
  • Mutual-Friend RecommendationsMeta · PHONE SCREEN · ONSITE INTERVIEWMeta interview questions
  • Filter, Sort, and Deduplicate Scheduled TasksRippling · PHONE SCREEN · ONSITE INTERVIEWRippling interview questions
  • Insert Delete GetRandom O(1)Charta Health · PHONE SCREENCharta Health interview questions
  • Longest Consecutive SequenceKotak Mahindra Bank · PHONE SCREENKotak Mahindra Bank interview questions
  • Longest Consecutive SequenceJP Morgan Chase · PHONE SCREENJP Morgan Chase interview questions
  • Logger Rate Limiter with Every-Arrival HistoryGoogle · PHONE SCREENGoogle interview questions
  • Propagating Fraud DetectorAffirm · PHONE SCREEN · ONSITE INTERVIEWAffirm interview questions
All EPAM interview questionsSee EPAM hiring insights
Saved
class Solution {
    public int longestConsecutive(int[] nums) {
        // Write your code here.
    }
}
Checking account…