Keep At Most K Copies in a Sorted Array

Quick Overview

Implement `dedupe_sorted(nums, k)`. Work through the function contract, boundary cases, correctness argument, and time and space complexity expected in a production-quality solution.

Keep At Most K Copies in a Sorted Array

Company: Oracle

Role: Software Engineer

Category: Coding & Algorithms

Difficulty: medium

Interview Round: Onsite

# Keep At Most K Copies in a Sorted Array Implement `dedupe_sorted(nums, k)`. Modify the sorted input array in place so each distinct integer appears at most `k` times while order is preserved, and return the retained prefix as an integer array. Use the input as the write buffer with `O(1)` working space; the returned prefix is the portable graded value in all four languages. Constraints: up to `200000` integers; each is in `[-10^9, 10^9]`; `0 <= k <= 200000`. ```hint Exercise each multiplicity boundary Test a value appearing fewer than, exactly, and more than `k` times, plus `k = 0`. ```

Quick Answer: Implement `dedupe_sorted(nums, k)`. Work through the function contract, boundary cases, correctness argument, and time and space complexity expected in a production-quality solution.

|Home/Coding & Algorithms/Oracle
Oracle logo
Oracle
Jul 26, 2026, 12:00 AM
mediumSoftware EngineerOnsiteCoding & Algorithms
0
0

Keep At Most K Copies in a Sorted Array

Implement dedupe_sorted(nums, k). Modify the sorted input array in place so each distinct integer appears at most k times while order is preserved, and return the retained prefix as an integer array. Use the input as the write buffer with O(1) working space; the returned prefix is the portable graded value in all four languages.

Constraints: up to 200000 integers; each is in [-10^9, 10^9]; 0 <= k <= 200000.

Submit Your Answer to Earn 20XP

Sign in to leave a comment

Loading comments...