โ† Goldman Sachs questions

Array segregation, merging, probability, and puzzle

Filed under Goldman Sachs

Free read 1 of 3

Use a two-pointer technique to segregate 0s and 1s in a single pass. For merging sorted arrays, use backward pointers to merge in-place if space permits, or standard two-pointer merging.

The question

Cover multiple foundational tasks: segregate 0s and 1s in an array, merge two sorted arrays, simulate a fair coin toss from a biased function, and solve the classic three ants on a triangle puzzle.

Constraints

  • Array manipulations should target optimal O(n) time and O(1) space where applicable.
  • Probability simulation requires logical decoupling of biased outcomes.

Examples

Input
array = [1, 0, 1, 0, 0, 1]
Output
[0, 0, 0, 1, 1, 1]
Why
Segregate all zeros to the left and ones to the right using a two-pointer approach.

Approach

  1. Use a two-pointer technique to segregate 0s and 1s in a single pass. For merging sorted arrays, use backward pointers to merge in-place if space permits, or standard two-pointer merging.

Tips

  • What they are testing: Evaluates algorithmic efficiency with arrays and lateral thinking in probability and puzzle-solving.
  • Common mistake: Using extra space for merging sorted arrays or segregating bits instead of in-place two-pointer scans.

Related Goldman Sachs questions

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