Count the number of values covered by all ranges | Tech Screen | Squarespace

Posted
22 Jan 2026
261 reads

Summary

I had a technical screen at Squarespace where I was asked to solve a problem about finding values covered by the intersection of multiple ranges.

How it went

Question

You are given an array of integers "values". Another array "ranges" has each element as a 2-list - [start, end] where "start" and "end" denote a range (start is always < end). Find the number of elements in "values" which are covered by every range (inclusive).

For eg, values = [2, 5, 13, 7, 17] ranges = [[2, 10], [2, 5], [1, 17]]

Answer = 2 because only values 2 and 5 are covered by every range.

Solution:

We need to find the intersection of all intervals in the ranges array to create a single interval. Those values which are covered by this single interval will count to our result:

def count_values_in_all_ranges(values, ranges) -> int:
    # Intersection of all inclusive ranges
    L = float("-inf")
    R = float("inf")

    for s, e in ranges:
        L = max(L, s)
        R = min(R, e)

    if L > R: # if no valid intersection exists
        return 0

    # Count values covered by the final intersection interval
    return sum(1 for v in values if L <= v <= R)

Questions asked (1)

  1. 01

    Count Values Covered by All Ranges

    Data Structures & Algorithms · Medium

    You are given an array of integers "values". Another array "ranges" has each element as a 2-list - [start, end] where "start" and "end" denote a range (start is always < end). Find the number of elements in "values" which are covered by every range (inclusive).

    For eg, values = [2, 5, 13, 7, 17] ranges = [[2, 10], [2, 5], [1, 17]]

    Answer = 2 because only values 2 and 5 are covered by every range.

Know someone preparing? Send it to them:WhatsAppLinkedInX

Interviewed at Squarespace 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!