Code Room
CodingMediumcod-g1261
Subject HashingLevel Entry–Mid~14 minCommon in Databases & SQL · Algorithms & data structures interviewsIndustries Software development

Question

Given a list of integers, find the maximum distance between two equal values: the largest j - i over all index pairs i < j with nums[i] == nums[j]. Return 0 when no value occurs more than once (including empty and single-element lists). For example, in [3, 7, 3, 7, 3] the two outer 3s are 4 apart, so the answer is 4; in [4, 1, 4, 1, 1, 4] the answer is 5. A nested scan over all pairs is O(n^2) — one hash map and one pass is enough.

Implement
max_equal_spread(nums: list[int]) → int
Examples
in[[3,7,3,7,3]]out4
What a strong answer looks like

State your approach and its time/space complexity out loud before you optimize. Handle the edge cases (empty input, duplicates, overflow), and say why you chose this over the brute force. Green tests are the floor, not the grade.

Vibe coding: describe the solution in plain language (or narrate it) and the coach grades your approach. Generating runnable code from your description is coming next.

Run or narrate your approach, then ask the coach.