DEV Community

ifa tade
ifa tade

Posted on

Goldman Sachs OA Questions: Two Coding Problems and Solutions

The Goldman Sachs OA is an important part of the application process for technical roles such as Software Engineer. Depending on the position and hiring cycle, the assessment may include traditional algorithm questions as well as tasks that require candidates to understand existing code and implement business logic.

This article covers two Goldman Sachs OA questions. The first focuses on reverse array traversal, duplicate removal, and selecting a specified number of unique request IDs. The second is an AI Coding problem involving ticket reservation confirmation, inventory updates, and partition status checks. Understanding the requirements and handling edge cases are essential to solving both problems correctly.

Question 1: Retrieve Unique Request IDs in Reverse Order

What This Question Tests

The goal is to traverse a request array from the end and collect a specified number of unique request IDs. Since an ID may appear multiple times, the solution must track previously encountered IDs and avoid adding duplicates.

The main concepts involved are:

  • Array Traversal: Iterate through the array from right to left.
  • Set: Track previously encountered request IDs to prevent duplicates.
  • Early Termination: Stop traversing once the result contains k unique IDs.

Solution Approach

Maintain a set to track visited IDs and a result array to store the selected IDs.

Start at the end of the request array and move backward one element at a time. For each ID, check whether it already exists in the set. If it does, skip it. Otherwise, add the ID to both the set and the result array.

Continue until the result contains k unique IDs. At that point, stop the traversal and return the result.

This approach prioritizes the most recently encountered unique IDs while preserving their order of discovery during reverse traversal.

Complexity Analysis

Let n be the length of the request array.

  • Time Complexity: O(n) in the worst case, since each element is examined at most once.
  • Space Complexity: O(n) in the worst case, for storing visited IDs and the result.

The algorithm is relatively straightforward. The main challenge is following the required traversal order and handling duplicate IDs correctly. Using a Set makes duplicate detection efficient and keeps the implementation simple.

Question 2: AI Coding for Ticket Confirmation and Inventory Updates

What This Question Tests

The second question is an AI Coding task with similarities to some Amazon OA questions that involve modifying existing code and implementing business rules.

Rather than focusing on a standalone algorithm, the task requires completing the ticket confirmation workflow after a ticket has been held or reserved. The implementation must validate the reservation, update inventory counts, clear the reservation record, and check the status of all ticket partitions.

The relevant data includes reservation ownership, ticket status, expiration time, held ticket counts, sold ticket counts, and partition-level inventory information.

Solution Approach

Step 1: Validate the reservation.

Start by checking whether the reservation can be confirmed. Verify the ownership information, current ticket status, and expiration time before making any changes.

Only reservations that satisfy the required business rules should proceed to the confirmation stage.

Step 2: Update the ticket counts.

After validation succeeds, decrease held_count by 1 and increase sold_count by 1.

This represents the transition of one ticket from the held inventory to the sold inventory. Make sure the updates apply to the correct ticket partition.

Step 3: Clear the reservation record.

After confirmation, remove the corresponding reservation record so that it cannot be reused incorrectly.

The status transition, inventory updates, and reservation cleanup must follow the required business logic to avoid inconsistent data.

Step 4: Check the status of every partition.

Finally, iterate through all ticket partitions and determine whether each one is sold out. Apply any required status updates according to the problem's rules.

An important detail is that the final check must cover every partition, not just the partition associated with the confirmed ticket.

Key Implementation Considerations

The main challenge is ensuring that all business rules are handled correctly, rather than implementing a complicated data structure or algorithm.

  • Validation: Verify ownership, ticket status, and expiration before modifying data.
  • State Transitions: Apply the correct status changes when a held ticket is confirmed.
  • Inventory Consistency: Keep held_count, sold_count, and reservation records consistent.
  • Partition Status: Check every partition against the required sold-out conditions.

If the assessment provides existing code or documentation, review the expected exceptions, state transition rules, and inventory constraints before modifying the relevant functions.

For AI Coding tasks, passing the sample tests is not enough. Consider edge cases such as expired reservations, invalid ticket states, repeated confirmation attempts, and partitions with different inventory levels. These scenarios can reveal errors that are easy to miss during the initial implementation.

How to Prepare for the Goldman Sachs OA

Preparation should cover both algorithm fundamentals and practical code modification tasks.

For algorithm questions, practice array traversal, Set and Hash Map operations, sorting, two pointers, binary search, and common graph algorithms. Pay attention to traversal order, duplicate handling, stopping conditions, and time and space complexity.

For AI Coding tasks, focus on reading unfamiliar code, identifying the functions that need to be modified, understanding business constraints, and implementing the required behavior without breaking existing functionality.

For tasks involving inventory or state transitions, it helps to organize the workflow into four stages: validation, data updates, record cleanup, and final status checks. After implementation, test invalid states, expired records, repeated operations, and different inventory conditions across multiple partitions.

The exact format and question types of the Goldman Sachs OA may vary by role and hiring cycle. Use these problems as practice examples and refer to the instructions provided for your specific assessment.

Frequently Asked Questions

What topics are covered in the Goldman Sachs OA?

The content depends on the role and assessment format. Technical assessments may include data structures and algorithms, debugging, code implementation, or other engineering tasks. Review the assessment instructions for your target position to determine the most relevant areas to practice.

How should I prepare for AI Coding questions in the Goldman Sachs OA?

Practice reading existing code, understanding business requirements, completing specified functions, and handling exceptions. For tasks involving state changes, pay particular attention to validation rules, state transitions, data consistency, and edge-case testing rather than focusing only on writing code quickly.

Which algorithms should I review for the Goldman Sachs OA?

Useful topics include arrays, Hash Sets, Hash Maps, sorting, two pointers, binary search, and common graph algorithms. Beyond memorizing techniques, make sure you can translate the problem requirements into a correct implementation and handle boundary conditions.

Conclusion

These two Goldman Sachs OA questions cover different skill sets. The first tests reverse traversal and Set-based deduplication, while the second focuses on reservation validation, ticket inventory updates, and partition status checks.

If you are preparing for the Goldman Sachs OA or coding assessments at other technology companies, practice both algorithm problems and tasks that require modifying existing code. Developing a systematic approach to requirements, implementation, and edge-case testing can help you write more reliable solutions under assessment time constraints.

Top comments (0)