Posts

Showing posts with the label adhoc

1798. Maximum Number of Consecutive Values You Can Make (Leetcode)

Blog You are given an integer array coins of length n which represents the n coins that you own. The value of the i th coin is coins[i] . You can make some value x if you can choose some of your n coins such that their values sum up to x . Return the maximum number of consecutive integer values that you can make with your coins starting from and including 0 . Note that you may have multiple coins of the same value. Example: 1 Input: coins = [1,3] Output: 2 Example: 2 Input: coins = [1,1,1,4] Output: 8 Example: 3 Input: [1,4,10,3,1] Output: 20 Constraints: ...

1793. Maximum Score of a Good Subarray (Leetcode)

You are given an array of integers nums (0-indexed) and an integer k . The score of a subarray (i, j) is defined as min(nums[i], nums[i+1], ..., nums[j]) * (j - i + 1) . A good subarray is a subarray where i . Return the maximum possible score of a good subarray. Example: 1 Input: nums = [1,4,3,7,4,5], k = 3 Output: 15 Explanation: The optimal subarray is (1, 5) with a score of min(4,3,7,4,5) * (5-1+1) = 3 * 5 = 15. Example: 2 Input: nums = [5,5,4,5,4,1,1,1], k = 0 Output: 20 Explanation: The optimal subarray is (0, 4) with a score of min(5,5,4,5,4) * (4-0+1) = 4 * 5 = 20. Constraints: 1 1 ...