Tap here to switch tabs
Problem
Submissions

Problem: Limit Occurrences in Sorted Array

Limit Occurrences in Sorted Array gives you a sorted array and a maximum occurrence limit. Return an array with each distinct value appearing at most that limit while preserving relative order.

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

Limit Occurrences in Sorted Array gives you a sorted array and a maximum occurrence limit. Return an array with each distinct value appearing at most that limit while preserving relative order.

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