The TikTok stores content creators' videos in a distributed database, where each videoCategory[i] represents the number of videos available in the ith content category. To improve the efficiency, the system needs to create some content playlists such that:
- Each playlist contains exactly
kdistinct content categories. - Each video can only belong to one playlist.
Determine the maximum number of playlists that can be created while following these rules.
Complete the function maxPlaylists in the editor.
maxPlaylists has the following parameters:
int[] videoCategory: an array of integers representing the number of videos in each categoryint k: the number of distinct content categories each playlist must contain
Returns
int: the maximum number of playlists that can be created
videoCategory = [1, 2, 2, 3] k = 3 return = 2
Each playlist must include 2 videos from different categories. There are 4 different categories. One of the optimal arrangements is as follows:
- Playlist 1 gets videos from categories 2, 3, and 4. Thus remaining videos for each category is: [1, 1, 1, 2].
- Playlist 2 contains videos from categories 1, 2 and 4. Thus remaining videos for each category is: [0, 0, 1, 1].
Note that for the second playlist we could have chosen any 3 categories and one video from each of them, not necessarily from categories 1, 2 and 4. For example: 1, 3 and 4 or 2, 3, and 4 could also have been chosen.
It can be shown that no more than 2 playlists can be created. Therefore, the answer is 2.
- Check Even-Position MonotonicityOA · Seen Jun 2026
- Count Alternating Tile GroupsOA · Seen Jun 2026
- Count Even-Digit NumbersOA · Seen Jun 2026
- Inventory Discount TrackerOA · Seen Jun 2026
- Construct WDL StringOA · Seen Jun 2026
- Find Sum PairsOA · Seen Jun 2026
- LRU Cache with TTL ExpirationONSITE INTERVIEW · Seen May 2026
- Maximum Candies with At Most Two Types in a LineONSITE INTERVIEW · Seen May 2026
public int maxPlaylists(int[] videoCategory, int k) {
// write your code here
}