Code Room
CodingMediumcod-g1414
Subject Two pointersLevel Entry–Mid~13 minCommon in Algorithms & data structures interviewsIndustries Software development

Question

Given a sorted integer array nums, produce a version where each distinct value appears at most twice, keeping the sorted order and using a single pass with a write pointer (no counting map). Return the trimmed array. Example: [60, 60, 60, 62, 62, 65] becomes [60, 60, 62, 62, 65]. Think about what single comparison tells you whether the current element may be kept.

Implement
cap_repeats_at_two(nums: list[int]) → list[int]
Examples
in[[60,60,60,62,62,65]]out[60,60,62,62,65]
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.