FastPrepMaximal Consecutive Number Ranges

Maximal Consecutive Number Ranges

Bloomberg LP logoBloomberg LP● EasyNEW GRADPHONE SCREEN
Learn

Problem statement

nums is strictly increasing. Return every maximal consecutive range in order. Format a multi-value range as start->end and a singleton as its value.

Function

consecutiveRanges(nums: int[]) → String[]

Examples

Example 1

nums = [-1,0,1,2,5,6,8]return = ["-1->2","5->6","8"]

There are two multi-value runs and one singleton.

Constraints

  • 0 <= nums.length <= 10^5.
  • Values are unique and strictly increasing.

More Bloomberg LP problems

See Bloomberg LP hiring insights
public String[] consecutiveRanges(int[] nums) {
  // Write your code here.
}
nums[-1,0,1,2,5,6,8]
expected["-1->2", "5->6", "8"]
Checking account…