DEV Community

Cover image for Goldman Sachs HackerRank OA Review | A More Challenging Round Than Expected
interview-show-Etesis Elay
interview-show-Etesis Elay

Posted on

Goldman Sachs HackerRank OA Review | A More Challenging Round Than Expected

Just completed a Goldman Sachs HackerRank OA. This round followed an A + B format (coding + math), and the overall difficulty and pacing felt noticeably higher than a standard OA.

Section A was a 120-minute data structure & algorithm coding round, while Section B was a 180-minute mixed math + programming assessment. The platform was still HackerRank, so the interface was familiar, but the question design leaned heavily toward thinking + optimization rather than straightforward pattern matching.

Question 1: First Compatible

The problem statement itself is simple, but the challenge lies in optimization.

Given arr1 and arr2, for each element in arr1, find the smallest index in arr2 such that the value is strictly greater than the element. If none exists, return -1.

Example:

arr1 = [3,8,1]
arr2 = [1,2,5]
Output: [3, -1, 2]

Core idea: treat arr1 as offline queries and process them efficiently using sorting or scanning techniques on arr2. The goal is to maintain a structure that allows fast lookup of the minimal valid index.

A more robust approach is to use a Fenwick Tree (BIT) or Segment Tree to maintain the minimum index dynamically, avoiding an O(n²) brute-force solution that would time out.

In essence, this is a classic combination of: sorting + offline queries + data structure optimization

Question 2: Lock Code

This question is a blend of math, greedy strategy, and pruning optimization.

You are given a codeSequence and a maxValue. You can modify elements (each modification costs 1), with the goal of selecting a value x such that all elements become coprime with x (GCD = 1), while maximizing:

x - modification cost

Key Insight

The main optimization lies in two observations:

First, x does not need to be fully enumerated across the entire range. Since modification cost is bounded by n, we only need to consider values in the range:

[maxValue - n, maxValue]

For each candidate x, compute how many elements are NOT coprime with x. Those elements must be modified, which gives the cost.

Finally, choose the maximum value of (x - cost).

Overall Difficulty Impression

This OA felt different from typical LeetCode-style assessments.

Q1 focuses heavily on offline processing + data structure optimization, where naive solutions quickly run into TLE. Q2 focuses on mathematical reasoning + pruning strategy rather than template-based solving.

If you're only comfortable with standard Easy/Medium LeetCode problems, this type of OA can still be tricky, especially when optimization is required under time pressure.

Preparation Takeaways

  • Offline query techniques (sorting + scanning)
  • Fenwick Tree / Segment Tree basics
  • GCD and coprime optimization tricks
  • Pruning and bounded enumeration strategies

The biggest gap in these OA problems is not understanding the idea, but turning a brute-force approach into a scalable solution within limited time.

Final Thoughts

In my case, preparation time was limited, and I referenced structured OA strategy notes and pacing reminders from Interview Aid during practice. They are a long-running team (founded in 2014) composed of engineers and competitive programmers focused on helping candidates with OA and VO preparation.

For candidates who are just starting OA preparation or often get stuck on optimization-heavy problems, it can act as a useful acceleration layer for building intuition and improving execution speed under pressure.

Learn more here: Interview Aid Official Site

Top comments (0)