Problem · Array
Build Maximum Integer from Subsequence (Google India)
Learn this problemProblem statement
You are given an array nums of decimal digits and an integer k.
Choose exactly k elements at strictly increasing indices, then concatenate the chosen digits in their original order to form an integer. Leading zeroes are allowed and do not change the integer's numeric value.
Return the largest integer that can be formed.
Function
buildMaximumInteger(nums: int[], k: int) → intExamples
Example 1
nums = [4, 9, 0, 2]k = 2return = 92Choose digits 9 and 2 at indices 1 and 3. They preserve their original order and form the maximum value 92.
Constraints
1 <= k <= min(nums.length, 9)0 <= nums[i] <= 9