TikTok Video Relevance Adjustment
Learn this problemProblem statement
Note: This problem statement is currently incorrect. Please do not use this problem for practice right now.
Given an array videoScores, of length n, representing the current relevance scores of videos in the recommendation system (i.e., how much a video matches the user's interests, with higher values indicating better matches), the task is to adjust the scores to make all the videos no longer recommended (i.e., reduce all the scores to 0 or below).
Each adjustment decreases one of the video scores by a fixed integer value x. The task is to find the minimum value of x such that after performing at most maxAdjustments adjustments, all the relevance scores will become non-positive (i.e., less than or equal to zero).
Function
getMinAdjustments(videoScores: int[], maxAdjustments: int) → int
Complete the function getMinAdjustments in the editor below.
getMinAdjustments takes the following parameter:
int videoScores[n]: the current relevance scores of videos in the recommendation systemint maxAdjustments: the maximum number of adjustments allowed
Returns
int: the minimum possible integer x required
Examples
Example 1
videoScores = [4, 3, 2, 7]maxAdjustments = 5return = 2
If x = 1, elements can be decreased by 1 in an operation and it would take a total of 6 adjustments to make all the elements non-positive which exceeds the maxAdjustments allowed.
If the chosen x = 2, then:
- In the first operation, we decrease the first element. The array becomes [-1, 2, 3]
- In the second operation, we decrease the second element. The array becomes [-1, 0, 3]
- In the third operation, we decrease the third element. The array becomes [-1, 0, 1]
- In the fourth operation, we decrease the third element again. The array becomes [-1, 0, -1]
x = 2 is the minimum possible integer respecting the given conditions. Thus, the answer is 2.
Constraints
1 ≤ n ≤ 1051 ≤ videoScores[i] ≤ 109n ≤ maxAdjustments ≤ 109
More Amazon problems
- Resolve Task DependenciesONSITE INTERVIEW · Seen Jul 2026
- Shortest Distance on a Circular Bus RouteOA · Seen Jul 2026
- Longest Increasing Subsequence With Bounded Adjacent DifferenceONSITE INTERVIEW · Seen Jul 2026
- Search in a Rotated Sorted ArrayONSITE INTERVIEW · Seen Jul 2026
- Sliding Window MaximumONSITE INTERVIEW · Seen Jul 2026
- Merge IntervalsOA · Seen Jul 2026
- Sort Bug Report FrequenciesOA · Seen Jul 2026
- Drone Delivery RouteOA · Seen Jul 2026