Problem · Array
Smallest Adjacent Concatenation
Learn this problemProblem 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[]) → intExamples
Example 1
arr = [15,24,34,10,12,21,45,67]return = 1221The fixed adjacent pairs produce 1524, 3410, 1221, and 4567. The smallest value is 1221.
Example 2
arr = [9,87,6]return = 6The complete pair produces 987. The unpaired final value 6 is also a candidate and is smaller.
Constraints
1 <= arr.length <= 10^51 <= arr[i] <= 10^4