1929. Concatenation of Array

Prompt

We are given an array nums that has a total length of n elements. We want to create an array called ans that has a total length of 2n elements. The problem states that ans[i] == nums[i] and ans[i + n] == nums[i] meaning that at whichever index, the value located at that index will be identical to the value located at that index + n.

Pseudocode

Unless it’s specifically stated in the prompt, you either have the choice of appending each element back into the array as you iterate through it in-place or you can instantiate a new array and populate that array with 2n elements. My code will reflect the former as I wanted to save space by performing the algorithm in-place.

Pseudocode

Code

Code (Python)

--

--

Get the Medium app

A button that says 'Download on the App Store', and if clicked it will lead you to the iOS App store
A button that says 'Get it on, Google Play', and if clicked it will lead you to the Google Play store
John Kim

John Kim

75 Followers

iOS Developer | Full Stack Developer | Software Engineer | LinkedIn: john-kim-developer | GitHub: cloudiosx | Portfolio: cloudiosx.com