Skip to the code
cf.
+25 XP

#24 Longest Run of Consecutive Build Numbers

medium

A release dashboard lists build numbers that passed QA, in no particular order and possibly with repeats, in builds.

Write longestRun(builds) that returns the length of the longest run of consecutive whole numbers (like 10, 11, 12, 13) that all appear in builds. Repeats count once. Return 0 for an empty list. Aim for O(n) time, without sorting.

Example 1

Input: builds = [12,3,10,11,4,13,5]
Output: 4

10, 11, 12, and 13 are all present: a run of 4.

Example 2

Input: builds = [7,7,7]
Output: 1

Repeats count once, so the run is just 7.

Constraints

  • 0 <= builds.length <= 10^5
  • -10^9 <= builds[i] <= 10^9
Saved in this browser

Run tries your code on the examples. Submit runs every test, including hidden edge cases, and solves the problem when they all pass.

Ctrl + Enter runs, Ctrl + Shift + Enter submits (⌘ on a Mac).