FastPrepBuild Maximum Integer from Subsequence (Google India)

Build Maximum Integer from Subsequence (Google India)

Google logoGoogle● MediumPHONE SCREEN
Learn

Problem 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) → int

Examples

Example 1

nums = [4, 9, 0, 2]k = 2return = 92

Choose 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

More Google problems

See Google hiring insights
public int buildMaximumInteger(int[] nums, int k) {
  // write your code here
}
nums[4, 9, 0, 2]
k2
expected92
Checking account…