Pacestock | SDE Intern + PPO | On-Campus Interview Experience
Problem Statement:
You are given an integer array "cost" of length "n", where "cost[i]" represents the cost of an item weighing "2^i".
You can purchase any number of items of each available weight: "1, 2, 4, 8, 16, ..."
Given an integer "minWeight", find the minimum total cost required to obtain a combined weight greater than or equal to "minWeight".
Example 1:
Input:
cost = [2, 5, 7, 11, 25]
minWeight = 26
Output:
37
Explanation:
Purchase two items of weight "1" and three items of weight "8".
Total weight = 2 ร 1 + 3 ร 8 = 26
Total cost = 2 ร 2 + 3 ร 11 = 37
Example 2:
Input:
cost = [3, 10, 20]
minWeight = 5
Output:
23
Constraints:
- "1 โค cost.length โค 30"
- "1 โค cost[i] โค 10โน"
- "1 โค minWeight โค 10โน"
- Unlimited items are available for each weight.
Follow-up: Can you solve this in O(n) time and O(1) auxiliary space?
How would you approach this problem? Share your solution and explain the intuition in the comments.
Hey, Iโm a software engineer who loves building things with AI
If youโre a
- Founder
- Software engineer
- AI enthusiast
- Builder
- Indie hacker
- Tech creator
Letโs connect, share ideas, build cool things, and grow together! ๐ค
Swiggy Instamart is hiring remote Android and iOS interns for a 6-month internship!
Post your resume here so the community can review it and suggest improvements.
Apply here:
https://t.co/0dqn8RZQXG