[TikTok] OA 2025 start – 2 Apr (generic)

TikTok Video Relevance Adjustment

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 Description

Complete the function getMinAdjustments in the editor.

getMinAdjustments takes the following parameter:

  • int videoScores[n]: the current relevance scores of videos in the recommendation system
  • int maxAdjustments: the maximum number of adjustments allowed

Returns

  • int: the minimum possible integer x required

Example 1

Input: videoScores = [1, 2, 3], maxAdjustments = 4
Output: 2

Explanation

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]

Hence, x = 2 is the minimum possible integer respecting the given conditions. Thus, the answer is 2.

Constraints

  • 1 ≤ n ≤ 10^5
  • 1 ≤ videoScores[i] ≤ 10^9
  • n ≤ maxAdjustments ≤ 10^9

TikTok Shopping Spree

Alex is a TikTok influencer who loves shopping online and sharing his latest hauls with his followers. He's super excited about buying several products from an e-commerce website to feature in his next video. Each item on his shopping list has its own price, and Alex wants to show his followers how to get the best deals.

Alex has a number of discount vouchers that he can use on any of his purchases. These vouchers offer a unique discount mechanism: the more vouchers used on a single item, the greater the discount. For instance, for each voucher used on an item, the price of that item is halved. If multiple vouchers are used on the same item, the price is halved repeatedly. The discount can be represented by the following formula:

discounted_price = p / 2^k

Where:

  • p is the original price of the item
  • k is the number of vouchers used on that item

Alex needs to figure out the minimum total cost he'll need to pay to buy all the items he wants while using his vouchers as effectively as possible. Can you help Alex make his followers proud with his savvy shopping skills?

Example

Input:
vouchersCount = 3
prices = [8, 2, 13]

Output:
9

我们长期稳定承接各大科技公司如TikTok、Google、Amazon等的OA笔试代写服务,确保满分通过。如有需求,请随时联系我们。

We consistently provide professional online assessment services for major tech companies like TikTok, Google, and Amazon, guaranteeing perfect scores. Feel free to contact us if you're interested.

Leave a Reply

Your email address will not be published. Required fields are marked *