FastPrepLongest Run of Consecutive Values
Problems/Longest Run of Consecutive Values

Longest Run of Consecutive Values

Adobe logoAdobe● MediumFULLTIMEPHONE SCREEN
QuestionFunctionExamplesConstraints

Problem statement

Source note: This problem returns the size of the largest group of an array's values that are consecutive integers, wherever they sit in the array. An Adobe Computer Scientist II (frontend) report lists, for its first round, a question whose title is all it gives: a longest-sequence task on an array.

Our choices: we read it as consecutive integer values (another common reading is the longest increasing subsequence), values may repeat and appear in any order, an empty array gives 0, at most 5000 values between -10^9 and 10^9, and new examples.

The judged task matches the report at about 50%.

Given an integer array nums, find the largest number of consecutive integers (like 4, 5, 6, 7) that all appear somewhere in nums. Their positions in the array do not matter, and a value that appears several times counts once.

Return that number, or 0 if the array is empty.

Function

longestConsecutiveRun(nums: int[]) → int

Examples

Example 1

nums = [10,4,12,11,5,13]return = 4

The values 10, 11, 12 and 13 are all present, so they form a run of 4 consecutive integers (their order in the array does not matter). 4 and 5 form a shorter run of 2.

Example 2

nums = [7,7,8,8,6]return = 3

Repeated values count once: 6, 7 and 8 form a run of 3.

Example 3

nums = [-3,100,0,-2,-1,50]return = 4

-3, -2, -1 and 0 form a run of 4; 50 and 100 stand alone.

Constraints

  • 0 <= nums.length <= 5000
  • -10^9 <= nums[i] <= 10^9

More Adobe problems

  • Evaluate a Parenthesized Integer ExpressionPHONE SCREEN · Seen Oct 2026
  • All Elements of Two BSTs in OrderPHONE SCREEN · Seen Aug 2026
  • Rotate an Array In PlaceOA · PHONE SCREEN · Seen Aug 2026
All Adobe interview questionsSee Adobe hiring insights
Saved
public int longestConsecutiveRun(int[] nums) {
    // Write your code here.
}
Checking account…