Problem · Array

Smallest Adjacent Concatenation

Learn this problem
EasyIDFC BankOA

Problem statement

You are given an array arr of positive integers. Group the array into fixed adjacent pairs: (arr[0], arr[1]), (arr[2], arr[3]), and so on.

For each complete pair, concatenate the decimal representation of the first number with the decimal representation of the second number, without reordering either number. If the array has odd length, treat the final unpaired number as its own candidate.

Return the smallest candidate value.

Function

smallestAdjacentConcatenation(arr: int[]) → int

Examples

Example 1

arr = [15,24,34,10,12,21,45,67]return = 1221

The fixed adjacent pairs produce 1524, 3410, 1221, and 4567. The smallest value is 1221.

Example 2

arr = [9,87,6]return = 6

The complete pair produces 987. The unpaired final value 6 is also a candidate and is smaller.

Constraints

  • 1 <= arr.length <= 10^5
  • 1 <= arr[i] <= 10^4

More IDFC Bank problems

drafts saved locally
public int smallestAdjacentConcatenation(int[] arr) {
  // write your code here
}
arr[15,24,34,10,12,21,45,67]
expected1221
checking account