Minimize Distinct Item Types After Removals
Updated
Problem statement
Remove exactly k occurrences from items so that the remaining array has as few distinct item types as possible. Equal integer values represent the same type. Return that minimum number of distinct types.
For this exercise, assume any occurrences may be removed, their order is irrelevant, and the input array must remain unchanged. An empty result has zero types. Negative values and zero are ordinary type labels.
Function
minDistinctAfterRemovals(items: int[], k: int) → intExamples
Example 1
items = [5,5,4]k = 1return = 1Remove the lone 4; only type 5 remains.
Example 2
items = [4,3,1,1,3,3,2]k = 3return = 2Remove the singletons 4 and 2 and one occurrence of another type. Two types remain.
Example 3
items = [7,7]k = 0return = 1No occurrences are removed, so type 7 remains.
Constraints
0 <= items.length <= 100000.-1000000000 <= items[i] <= 1000000000.0 <= k <= items.length.
More Roblox Online Assessment questions
- Centered Block Placement QueriesOA · Seen Oct 2026
- Robot Navigation Around LasersOA · Seen Oct 2026
- Factory Batch Profit (Game Adaptation)OA · Seen Sep 2026
- Nested Recipe Blocks (Game Adaptation)OA · Seen Sep 2026
- Vehicle Builds for Required Terrain (Game Adaptation)OA · Seen Sep 2026
- Track Received Byte RangesOA · Seen Sep 2026
- Break a PalindromeOA · Seen Jun 2026
- Count Pairs Differing in One DigitOA · Seen Oct 2025
- Find Zero Cells in a 2×2 GridOA · Seen Oct 2025
- Cat Route Budget Planning (Game Adaptation)OA · Seen Aug 2025
Similar questions at other companies
- Count Overlapping Square PairsRamp · OARamp interview questions
- Minimum Rounds to Complete All TasksInfosys · OAInfosys interview questions
- Find Valid SET Card TriplesSnowflake · OA · PHONE SCREENSnowflake interview questions
- Minimum Distinct Prefix CostChubb · OAChubb interview questions
- Two Tribes from Taller-Person CountsIntuit · OAIntuit interview questions
- Count One-Swap Number PairsCapital One · OACapital One interview questions
- Minimum Distinct Prefix CostGoldman Sachs · OAGoldman Sachs interview questions
- Get Triplet CountIBM · OAIBM interview questions
- Count Reverse-Digit PairsVisa · OAVisa interview questions
- Count 2x2 Submatrices by Black CellsTikTok · OATikTok interview questions