Tap here to switch tabs
Problem
Submissions

Problem: Limit Occurrences in Sorted Array

med
30 min
Try to solve the Limit Occurrences in Sorted Array problem.

Statement

Given an integer array nums sorted in nondecreasing order and an integer k, remove elements such that each distinct value appears at most k times while maintaining the original relative order.

Return the resulting array containing each element at most k times.

Note: The space used for returning or resizing the result does not count toward the auxiliary space complexity.

Constraints:

  • 1≤1 \leq nums.length ≤100\leq 100

  • 1≤1 \leq nums[i] ≤100\leq 100

  • nums is sorted in nondecreasing order.

  • 1≤1 \leq k ≤\leq nums.length

⋮
Tap here to switch tabs
Problem
Submissions

Problem: Limit Occurrences in Sorted Array

med
30 min
Try to solve the Limit Occurrences in Sorted Array problem.

Statement

Given an integer array nums sorted in nondecreasing order and an integer k, remove elements such that each distinct value appears at most k times while maintaining the original relative order.

Return the resulting array containing each element at most k times.

Note: The space used for returning or resizing the result does not count toward the auxiliary space complexity.

Constraints:

  • 1≤1 \leq nums.length ≤100\leq 100

  • 1≤1 \leq nums[i] ≤100\leq 100

  • nums is sorted in nondecreasing order.

  • 1≤1 \leq k ≤\leq nums.length