Find the Array Concatenation Value
To solve this problem, iterate over the array by popping out the first and last elements, concatenate them, convert them back to an integer, and keep adding this value until the array is empty. When only one element is left, just add it to the sum. Here is how you could do it:
|
|
In this solution:
conc_value
is initialized as 0, which will hold the sum of all concatenated numbers.- In the loop, it’s checked if
nums
has more than one element. If yes, then the first and last elements are popped out, concatenated to form a new number, and this number is added toconc_value
. - If only one element is left in
nums
, then this element is popped out and added toconc_value
. - This loop will continue until
nums
becomes empty. - The final value of
conc_value
is returned as the answer.