Find the Array Concatenation Value

You are given a 0-indexed integer array nums.

The concatenation of two numbers is the number formed by concatenating their numerals.

  • For example, the concatenation of 15 and 49 is 1549.

The concatenation value of nums is initially equal to 0. Perform this operation until nums becomes empty:

  • If nums has a size greater than one, add the value of the concatenation of the first and the last element to the concatenation value of nums, and remove those two elements from nums.
  • If only one element exists in nums, add its value to the concatenation value of nums, then remove it.

Return the concatenation value of nums.

Example 1
Inputnums = [7,52,2,4]
Output596
The operations add the concatenations 74 and 522, giving a total concatenation value of 596.
Example 2
Inputnums = [5,14,13,8,12]
Output673
The operations add 512, 148, and the remaining element 13, giving a total concatenation value of 673.

Constraints

  • 1 <= nums.length <= 1000
  • 1 <= nums[i] <= 10^4

Asked at 2 companies

</>

Your Solution

(Ctrl/Cmd + Enter)

Switching Language

Loading template...

Loading...

Sign in to save your progress

AI code evaluation

Get a correctness verdict, missed edge cases, and complexity analysis of your solution.

Sign in to evaluate