Leetcode Problem 2809. Minimum Time to Make Array Sum At Most x

2809. Minimum Time to Make Array Sum At Most x

Leetcode Solutions

Dynamic Programming with Sorting

  1. Calculate the initial sum of nums1 and the sum of rates in nums2.\n2. Sort the indices of the arrays based on the values in nums2.\n3. Initialize a DP array to keep track of the maximum sum for each number of steps.\n4. Iterate over the sorted indices and update the DP array based on whether we reset the counter at the current index or not.\n5. After filling the DP array, iterate over the possible number of steps and check if the sum after reduction is less than or equal to x.\n6. Return the minimum number of steps if possible, otherwise return -1.
UML Thumbnail

Greedy Approach with Priority Queue

Ask Question

Programming Language
image/screenshot of info(optional)
Full Screen
Loading...

Suggested Answer

Answer
Full Screen
Copy Answer Code
Loading...