leetle

Daily challenge for 2026-04-18

473. Find Smallest Integer Root

Given a sorted array of positive integers arr and a target integer k, find the smallest integer x such that the sum of all elements in arr that are less than or equal to x is greater than or equal to k. If the sum of all elements in the array is less than k, return the largest element in the array.

Input: arr = [2, 5, 8, 12], k = 18
Output: 12
Explanation: If x=11, elements <= 11 are [2, 5, 8], sum = 15. If x=12, elements <= 12 are [2, 5, 8, 12], sum = 27. 27 >= 18, so 12 is the smallest integer.

Run this challenge interactively in Python or JavaScript when the app loads.