TikTok Shopping Spree
Updated
Problem statement
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?
Function
calculateTikTokShoppingCost(vouchersCount: int, prices: int[]) → long
Complete the function calculateTikTokShoppingCost in the editor below.
calculateTikTokShoppingCost has the following parameter(s):
int vouchersCount: the number of discount vouchers.int prices[n]: an array representing the prices of the n items Alex wants to buy.
Returns
long: the minimum total cost Alex will need to pay to purchase all the items.
Constraints
1 ≤ prices.length ≤ 10^51 ≤ vouchersCount ≤ 10^51 ≤ prices[i] ≤ 10^9
Examples
Example 1
vouchersCount = 3prices = [8, 2, 13]return = 9More TikTok interview questions
- Center of the Largest Perfect X-ShapeOA · Seen Nov 2026
- Count Subarrays Matching a Comparison PatternOA · Seen Nov 2026
- Count Suffix Word PairsOA · Seen Nov 2026
- Minimum Cost of Every K-Capable Model SetOA · Seen Nov 2026
- Longest Substring Without Repeating CharactersPHONE SCREEN · Seen Oct 2026
- Next Greater Indices and Maximum GapPHONE SCREEN · Seen Oct 2026
- Count Subarrays with at Least K Equal-Fruit PairsOA · Seen Oct 2026
- Shell Command Counts with History ReferencesOA · Seen Oct 2026
- Product Minus Sum of DigitsOA · Seen Aug 2026
- Count 2x2 Submatrices by Black CellsOA · Seen Aug 2026
Similar questions at other companies
- Remove Stones to Minimize the Total (LC 1962 :)Snowflake · OASnowflake interview questions
- Array Reduction 1Oracle · OAOracle interview questions
- Task SchedulerAmazon · OA · PHONE SCREEN · ONSITE INTERVIEW
- Minimum Cost to Merge Values into OnePayPal · OAPayPal interview questions
- Maximum K-Star SumC3.ai · OAC3.ai interview questions
- Maximum Sum of a K-StarMicrosoft · OAMicrosoft interview questions
- Maximum ScoreNVIDIA · OANVIDIA interview questions
- Maximize Revenue from Decreasing InventoryChubb · OAChubb interview questions
- Task SchedulingJP Morgan Chase · OAJP Morgan Chase interview questions
- Decreasing SubsequencesGoogle · OAGoogle interview questions
TikTok interview experiences
- TikTok AI Infra Intern LLM Round 2: 1 Experience
- TikTok AI Infra Intern DeepSpeed Round: 1 Experience
- TikTok AI Infra Intern Kernel Round: 1 Experience
- TikTok AI Infra Intern Interviews, 3 Rounds: 1 Experience
- TikTok AI Infra Intern Interview Timeline: 1 Experience
- TikTok AI Infra Intern Onsite Round 2: 1 Experience