FastPrepOrdered Odd-Even Thread Output
Problems/Ordered Odd-Even Thread Output

Ordered Odd-Even Thread Output

Goldman Sachs logoGoldman Sachs● MediumFULLTIMEONSITE INTERVIEW

Updated Nov 2026

QuestionFunctionExamplesConstraints

Problem statement

Source note: A Goldman Sachs superday concurrency round asks two threads to print 1 through 100, with one thread given the odd values and the other the even values, keeping the sequence in order. The report does not give a return value that can be checked, or a rule for interruptions. This version is a general in-memory output version. Our version is about 90% the same as the reported question.

Coordinate two workers over the integers from 1 through n. The odd worker may append only odd values and the even worker may append only even values. The shared output must be exactly [1, 2, ..., n].

Return the shared output after both workers finish. Use synchronization so a worker waits until the next value has its parity; do not generate two independent lists and merge them afterward.

Function

orderedOddEvenOutput(n: int) → int[]

Examples

Example 1

n = 6return = [1,2,3,4,5,6]

The odd and even workers alternate while preserving increasing order.

Example 2

n = 1return = [1]

Only the odd worker appends a value.

Constraints

  • 0 <= n <= 100000
  • The returned array is empty when n = 0.

More Goldman Sachs Onsite Interview questions

  • Best Average Student ScorePHONE SCREEN · ONSITE INTERVIEW · Seen Nov 2026
  • Knight Probability in ChessboardONSITE INTERVIEW · Seen Nov 2026
  • Meeting RoomsPHONE SCREEN · ONSITE INTERVIEW · Seen Oct 2026
  • Minimum Meeting Rooms Without a Sweep LineONSITE INTERVIEW · Seen Oct 2026
  • First Non-Repeating CharacterPHONE SCREEN · ONSITE INTERVIEW · Seen Oct 2026
  • Root of the Largest TreePHONE SCREEN · ONSITE INTERVIEW · Seen Oct 2026
  • Dungeon HealthONSITE INTERVIEW · Seen Sep 2026
  • Insert, Delete, And Get Random In Constant TimeONSITE INTERVIEW · Seen Sep 2026
  • Least Recently Used CacheONSITE INTERVIEW · Seen Sep 2026
  • Staircase Search In A Sorted MatrixONSITE INTERVIEW · Seen Sep 2026

Similar questions at other companies

  • Concurrent Buffered File LoggerDatabricks · ONSITE INTERVIEWDatabricks interview questions
  • Bounded Producer–Consumer QueueMakeMyTrip.com · ONSITE INTERVIEWMakeMyTrip.com interview questions
  • Thread-Safe Task Storage and Worker DispatchNuro · ONSITE INTERVIEWNuro interview questions
  • Shared Counter Snapshot SumTesla · ONSITE INTERVIEWTesla interview questions
  • Circuit Breaker State MachineWise · ONSITE INTERVIEW
  • One-Shot Callback Event DispatchPure Storage · ONSITE INTERVIEWPure Storage interview questions
  • Blocking Connection Pool Operation TraceGoogle · ONSITE INTERVIEWGoogle interview questions
  • Keyed Bounded Executor ScheduleMicrosoft · ONSITE INTERVIEWMicrosoft interview questions
  • Concurrent Web Crawler SimulationOpenAI · PHONE SCREEN · ONSITE INTERVIEWOpenAI interview questions
  • Concurrent Discounted Card PurchasesBrex · PHONE SCREEN
All Goldman Sachs interview questionsSee Goldman Sachs hiring insights
Saved
class Solution {
    public int[] orderedOddEvenOutput(int n) {
      // write your code here
    }
}
Checking account…