TikTok Video Relevance Adjustment
Updated
Problem statement
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 parameters:
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 = 4With step x, a score v needs ceil(v / x) adjustments to reach 0 or below. With x = 3 the scores need 2 + 1 + 1 + 3 = 7 adjustments, more than 5. With x = 4 they need 1 + 1 + 1 + 2 = 5 adjustments, which is allowed. Smaller steps need even more adjustments (16 for x = 1, 9 for x = 2), so the minimum x is 4.
Example 2
videoScores = [1, 2, 3]maxAdjustments = 4return = 2With x = 1 the scores need 1 + 2 + 3 = 6 adjustments, more than 4. With x = 2: decrease the first score: [-1, 2, 3]; decrease the second score: [-1, 0, 3]; decrease the third score: [-1, 0, 1]; decrease the third score again: [-1, 0, -1]. That is 4 adjustments and every score is at most 0, so the minimum x is 2.
Constraints
1 <= n <= 10^5, wherenis the length ofvideoScores1 <= videoScores[i] <= 10^9n <= maxAdjustments <= 10^9
More Amazon interview questions
- LRU Cache for Query ResultsPHONE SCREEN · ONSITE INTERVIEW · Seen Nov 2026
- Maximal SquareONSITE INTERVIEW · Seen Nov 2026
- Serialize and Deserialize a Binary TreeONSITE INTERVIEW · Seen Nov 2026
- Course SchedulePHONE SCREEN · ONSITE INTERVIEW · Seen Nov 2026
- Course Schedule IIPHONE SCREEN · ONSITE INTERVIEW · Seen Nov 2026
- Diagonal Traversal of a Binary TreeONSITE INTERVIEW · Seen Nov 2026
- Minimum Time to Spread Through a GridPHONE SCREEN · ONSITE INTERVIEW · Seen Nov 2026
- Consistent-Hash Packet RouterPHONE SCREEN · Seen Nov 2026
- Count Connected ComponentsPHONE SCREEN · Seen Nov 2026
- Maximize K-Element AND with an Increment BudgetOA · Seen Nov 2026
Similar questions at other companies
- Server Upgrade PlanningWells Fargo · OAWells Fargo interview questions
- Find Minimum TimeAlphaSense · OA
- Find Minimum TimeBlackRock · OABlackRock interview questions
- Maximize Pipeline Throughput Under a Scaling BudgetMicrosoft · OAMicrosoft interview questions
- Rock JumpingIMC Trading · OAIMC Trading interview questions
- Minimize Maximum Group DifferenceDRW · OADRW interview questions
- Array NullificationQRT · OA
- Minimum HeightSnowflake · OASnowflake interview questions
- Pipeline Throughput Maximization Under BudgetUber · OAUber interview questions
- Minimum-Cost Solar Rooftop AllocationDeloitte · OADeloitte interview questions