Summary Ranges – Asked in Yandex Interview

Posted
28 Jul 2025
264 reads

Summary

This post details my approach and solution to the 'Summary Ranges' problem, which I encountered during a Yandex interview.

How it went

Intuition

To summarize ranges in a sorted array, we can identify segments of consecutive numbers. Whenever a gap occurs between two numbers, it marks the end of the current range

Approach

We iterate through the array while keeping track of the start of the current range using a variable s.By appending float('inf') to the list, we ensure the final range is processed without requiring additional checks after the loop

At each step, we check if nums[i] - nums[i-1] > 1, which means the consecutive sequence has ended

We then:

  • Record the range from s to nums[i-1]
  • Update s to start a new range from nums[i]

If the start and end of the range are the same, we store it as a single number. Otherwise, we use the "start->end" format

Complexity

  • Time complexity: $$O(n)$$ — We go through the list once
  • Space complexity: $$O(n)$$ — for storing the resulting list of summary strings

Questions asked (1)

  1. 01

    Summary Ranges

    Data Structures & Algorithms · Easy

    To summarize ranges in a sorted array, we can identify segments of consecutive numbers. Whenever a gap occurs between two numbers, it marks the end of the current range. My approach involves iterating through the array while keeping track of the start of the current range using a variable s. By appending float('inf') to the list, we ensure the final range is processed without requiring additional checks after the loop. At each step, we check if nums[i] - nums[i-1] > 1, which means the consecutive sequence has ended. We then record the range from s to nums[i-1] and update s to start a new range from nums[i]. If the start and end of the range are the same, we store it as a single number. Otherwise, we use the "start->end" format.

    Open the problem

Know someone preparing? Send it to them:WhatsAppLinkedInX

Interviewed at Yandex recently?

Write up your rounds while you still remember the questions. It helps the next person more than you would think.

Share your experience
Discussion 0

Questions for the author, or how your own interview compared.

Join the discussion

Sign in with Google to comment or ask the author a question.

No comments yet

Be the first to share your thoughts and start the discussion!