← Goldman Sachs questions

Duplicate 2s in-place in array

Filed under Goldman Sachs

Given an array of integers, iterate through it and whenever the number 2 is encountered, insert an extra 2 directly after it. Elements shifted off the end are dropped to maintain original length.

You've read your 3 free write-ups

Sign up free to keep reading. Your account opens the first 10 questions of every company.

Related Goldman Sachs questions

Collected from public candidate posts and coding forums. Updated Nov 2026.