Compact the List

Problem Overview

  • Given a sorted, duplicate-free integer list, compact consecutive numbers into range strings; if no ranges, return each number as a string.
  • Input: N, then N space-separated integers (ascending). Output: line-separated strings representing the compacted list.
  • Domain: data summarization and reporting where numeric ranges improve readability and storage.
  • Cisco coding interview question; classic interview problem often used as an interview question.

Example

Unlock to view complete problem details

and practice with sample input/output

Was this article helpful?

View Test Cases & Run Code requires membership

Input Variables
Execution Result: