Find the Array Concatenation Value || Python || Easy Solution || 2 Approaches || Beats 100 %
Step-by-Step Explanation - Code 11. Initialize variables
n = len(nums) gets the length of the input array nums.
concatenation_value = 0 initializes a variable t
# **Step-by-Step Explanation - Code 1**

## 1. **Initialize variables**
   - `n = len(nums)` gets the length of the input array `nums`.
   - `concatenation_value = 0` initializes a variable to accumulate the result.

## 2. **Loop through half of the array**
   ```python
   for i in range(n // 2):
   ```
   - The loop runs until `n//2` (integer division). This ensures that we are pairing up the first and last elements in the array and processing them.
   
## 3. **Concatenate and sum**
   ```python
   concatenation_value += int(str(nums[i]) + str(nums[n - 1 - i]))
   ```
   - For each pair, we concatenate `nums[i]` and `nums[n-1-i]` as strings, convert the result to an integer, and add it to `concatenation_value`.
   
  

## 4. **Handle the middle element for odd-length arrays**
   ```python
   if n % 2 != 0:
       concatenation_value += int(nums[n // 2])
   ```
   - If the length of `nums` is odd, there will be one element left in the middle after pairing the first and last elements. This element is added to the `concatenation_value`.

## 5. **Return the final result**
   ```python
   return concatenation_value
   ```
   - The final result is returned after all operations.


# **Code 1**

```python
class Solution:
    def findTheArrayConcVal(self, nums: List[int]) -> int:
        n = len(nums)
        concatenation_value = 0

        for i in range(n//2):
            concatenation_value += int(str(nums[i]) + str(nums[n-1-i]))

        if n % 2 != 0:
            concatenation_value += int(nums[n//2])

        return concatenation_value
```


---


---

# **Step-by-Step Solution Explanation - Code 2**

## 1. **Initialize variables**
   - `n = len(nums)` gives the length of the array.
   - `left = 0` and `right = n - 1` are initialized to point to the first and last elements of the array, respectively.
   - `concatenation_value = 0` is initialized to accumulate the result.

## 2. **Convert elements to strings**
   ```python
   str_nums = [str(i) for i in nums]
   ```
   - Convert each number in the `nums` list to a string for easy concatenation.

## 3. **Loop through the array**
   ```python
   while left < right:
   ```
   - The loop runs as long as the `left` pointer is less than the `right` pointer.
   - For each pair of elements at `left` and `right`, we concatenate them as strings, convert the result to an integer, and add it to `concatenation_value`.
   
## 4. **Move the pointers**
   ```python
   left += 1
   right -= 1
   ```
   - After processing a pair, we move the `left` pointer one step right and the `right` pointer one step left to process the next pair.

## 5. **Handle the middle element for odd-length arrays**
   ```python
   if left == right:
       concatenation_value += int(str_nums[left])
   ```
   - If the length of `nums` is odd, the `left` pointer and `right` pointer will meet at the middle element. This element is added to `concatenation_value`.

## 6. **Return the result**
   ```python
   return concatenation_value
   ```
   - Return the final accumulated `concatenation_value`.
   

# Code 2
```python3 []
class Solution:
    def findTheArrayConcVal(self, nums: List[int]) -> int:
        n = len(nums)
        left = 0
        right = n-1
        concatenation_value = 0

        str_nums = [str(i) for i in nums]

        while left < right:
            concatenation_value += int(str_nums[left] + str_nums[right])
            
            left += 1
            right -= 1

        if left == right:
            concatenation_value += int(str_nums[left])
            

        return concatenation_value
```


---

# **Time Complexity**
- Both `code1` and `code2` iterate over the array once, performing constant-time operations for each element. Thus, the time complexity is **O(n)**, where `n` is the length of the array.



---

# If you find my solution helpful, Do Upvote 😀
---



['Array', 'Two Pointers', 'Simulation', 'Python3']