FastPrepSummarize Runs of Consecutive Integers
Problems/Summarize Runs of Consecutive Integers

Summarize Runs of Consecutive Integers

Capital One logoCapital One● EasyINTERNFULLTIMEONSITE INTERVIEW

Updated Nov 2026

QuestionFunctionExamplesConstraints

Problem statement

Source note: Three Capital One reports from 2018 and 2019 name the summary ranges task. Two are from intern final rounds and one is from a software engineer onsite. The most detailed of them likens the task to compression.

Here the numbers are distinct, strictly increasing 32-bit integers, up to 1000 of them. A stretch of one number is written alone, and longer stretches use an arrow. These are our choices.

Our version is about 95% the same as the reported questions.

The numbers in nums are distinct and sorted from smallest to largest. Group them into stretches: a stretch keeps going as long as the next number is the current number plus one, and it stops at the first gap.

Write each stretch as a string and list them from the smallest numbers to the largest. A stretch from x to y with x < y is written "x->y"; a stretch holding a single number x is written "x".

Function

summaryRanges(nums: int[]) → List<String>

Examples

Example 1

nums = [-7,1,2,40,41,42,43,44]return = ["-7","1->2","40->44"]

-6 is not in the list, so -7 is a stretch of one and is written as just "-7". Then 1, 2 give "1->2", and the five numbers from 40 to 44 give "40->44".

Example 2

nums = [-2147483648,-2147483647,0,2147483647]return = ["-2147483648->-2147483647","0","2147483647"]

The two smallest 32-bit integers sit side by side and form one stretch. -1 and 1 are absent, so 0 is a stretch of one, and the largest 32-bit integer also ends up on its own.

Example 3

nums = [100,102,104]return = ["100","102","104"]

Every gap is 2, so no two numbers join: each one is its own stretch.

Constraints

  • 0 <= nums.length <= 1000
  • -2^31 <= nums[i] <= 2^31 - 1
  • nums is strictly increasing.

More Capital One Onsite Interview questions

  • Digit-Coded Card ValidationONSITE INTERVIEW · Seen Nov 2026
  • Sort ColorsONSITE INTERVIEW · Seen Oct 2026
  • Virtual Card Transaction ValidatorONSITE INTERVIEW · Seen Oct 2026
  • Banking System with Top ActivityONSITE INTERVIEW · Seen Sep 2026
  • Transaction Event StoreONSITE INTERVIEW · Seen Jul 2026
  • Shortest Path in an Unweighted GraphONSITE INTERVIEW · Seen Jul 2026
  • Duplicate Transactions Within 60 SecondsONSITE INTERVIEW · Seen May 2026
  • LRU CachePHONE SCREEN · ONSITE INTERVIEW · Seen May 2026
  • Cashback TrackerONSITE INTERVIEW · Seen Nov 2025
  • Reverse a StringOA · ONSITE INTERVIEW · Seen Oct 2025

Similar questions at other companies

  • Bad Request AlertsMicrosoft · ONSITE INTERVIEWMicrosoft interview questions
  • Confusing Bib NumbersVerily · ONSITE INTERVIEW
  • Group Transactions by HourAffirm · ONSITE INTERVIEWAffirm interview questions
  • Longest Common PrefixKotak Mahindra Bank · PHONE SCREEN · ONSITE INTERVIEWKotak Mahindra Bank interview questions
  • Rotate a Matrix by 90 DegreesIDFC Bank · ONSITE INTERVIEWIDFC Bank interview questions
  • Plus OneDruva · ONSITE INTERVIEW
  • Ring Buffer OperationsAmazon · ONSITE INTERVIEW
  • Rotate a Flat Image ClockwiseGoogle · ONSITE INTERVIEWGoogle interview questions
  • Merge Sorted ArrayDP World · ONSITE INTERVIEW
  • List the Key and Value of Every Map EntryNewgen Software · ONSITE INTERVIEW

Capital One interview experiences

  • Capital One Coding OA Questions: 3 Experiences
  • Capital One Experienced Engineer Power Day and OA: 6 Experiences
  • Capital One New Grad OA Questions: 14 Experiences (Part 2 of 2)
  • Capital One TDP Agentic Round (AI Coding): 7 Experiences
  • Capital One SWE Power Day, Level Not Reported: 6 Experiences
  • Capital One TIP Intern OA and Power Day: 13 Experiences
All Capital One interview questionsSee Capital One hiring insights
Saved
class Solution {
    public List<String> summaryRanges(int[] nums) {
        // Write your code here.
    }
}
Checking account…