Wex
1 questions · 1 experiences · 1p3a (2)
Question Details
1st Round DSA Interview 1. Water Jug Problem Reference: LeetCode Question 365. 2. Maximum Elements Made Equal With k Updates Problem Statement: Given an array nums[] and a value k, find the maximum number of elements that can be made equal using at most k increments. Examples: * Input: nums[] = { 2, 4, 9 }, k = 3 * Output: 2 * Explanation: By incrementing the element 2 by 2, it becomes 4. This utilizes 2 updates, leaving k=1. Two elements are now 4. It is not possible to target 9 because converting 4 to 9 requires 5 increments, which exceeds k. * Input: nums[] = { 5, 5, 3, 1 }, k = 5 * Output: 3 * Explanation: Two elements are already 5. Increasing the element 3 to 5 costs 2 updates, reducing k to 3. Increasing 1 to 5 would cost 4 updates, which exceeds the remaining k. Therefore, the maximum number of equal elements is 3. * Input: nums[] = { 5, 5, 3, 1 }, k = 6 * Output: 4 * Explanation: With k=6, there are enough updates to increment both 3 (cost: 2) and 1 (cost: 4) to become 5, making all 4 elements equal.