Wednesday, January 29, 2025

Concatenation of Array

Profile Pic of Akash AmanAkash Aman

Updated: January 2025

Concatenation of Array
easy

💡 Intuition

  • The idea is to create an array of length 2n and update the values at indices i and i + n with num[i] while iterating through the existing array.

123111212123123Iteration 1Iteration 2Iteration 3Define the array of size 2nHere array are end result of any iteration Given Array

🚀 Solution

go
func getConcatenation(nums []int) []int { var result = make([]int,2*len(nums)) for index,num := range nums { result[index] = num; result[index+len(nums)] = num; } return result; }

⏳ Time Complexity

  • Since we are taking single loop for the array of length n, the time complexity will be O(n)