IBM's OA runs on the HackerRank platform and is friendlier than some big-tech tests. You usually get one hour and two problems, and anyone who has prepped at LeetCode Medium level has plenty of room. But "easy" does not mean "free pass": the prompts like to wrap themselves in business scenarios, and careless reading still sinks people.
This article fully unpacks two common real problems: one is array traversal plus an average check, the other is graph connectivity with union-find, both with submit-ready Python solutions and complexity.
IBM OA at a Glance
| Item | Detail |
|---|---|
| Platform | HackerRank |
| Number of problems | 2 |
| Length | 60 minutes |
| Difficulty | Basic to medium (array sim / prefix sum / union-find / graph) |
| Pass bar | Aim for full AC on both; time is usually generous |
In practice both problems can be done in under 20 minutes, leaving plenty of time to recheck hidden test edge cases.
Question 1: High Load Timestamps
Problem
Given an array
load[n]of server loads per timestamp, find all indicesi(0-based) whereload[i] > 2 x average load, returned in increasing order. If none, return an empty array.
Example
n = 3
load = [1, 2, 9]
average = (1 + 2 + 9) / 3 = 4
2 x average = 8
Only load[2] = 9 > 8
Answer = [2]
Approach
Compute the sum and average, then traverse once checking load[i] > 2 x average. To avoid floating-point error, turn the division into a multiplication: load[i] * n > 2 * total.
def get_high_load_timestamps(load):
n = len(load)
total = sum(load)
# load[i] > 2 * (total / n) is equivalent to load[i] * n > 2 * total
return [i for i in range(n) if load[i] * n > 2 * total]
Time complexity: O(n), one sum plus one traversal. Traps:
- Use integer multiplication instead of float division to avoid precision issues at the boundary
- The problem wants indices in increasing order, not values; traversal is already in order, no extra sort
- Empty arrays and all-equal arrays must return an empty result, do not miss this
Question 2: Minimum Reassignments for Connectivity
Problem
You manage
link_nodesdistributed code repositories, some already synced via direct version links. You may "reassign" any number of times: remove one existing link and attach it to any other pair of repositories. Find the minimum number of reassignments to make all repositories one synced system; if impossible, return -1.
Example
link_nodes = 4
link_from = [1, 1, 3]
link_to = [2, 3, 4]
Approach
A classic graph connectivity problem:
- A connected graph with
nnodes needs at leastn - 1edges. If the existing edge count< n - 1, no amount of reassigning can connect everything, so return -1. - Otherwise use union-find to count the current number of connected components
c. - Since reassigning existing edges is allowed, as long as total edges are sufficient, joining
ccomponents into 1 needs exactlyc - 1extra connections.
def min_reassignments(link_nodes, link_from, link_to):
edges = len(link_from)
# connecting all nodes needs at least n - 1 edges
if edges < link_nodes - 1:
return -1
parent = list(range(link_nodes + 1)) # 1-based nodes
def find(x):
while parent[x] != x:
parent[x] = parent[parent[x]] # path compression
x = parent[x]
return x
def union(a, b):
ra, rb = find(a), find(b)
if ra != rb:
parent[ra] = rb
for a, b in zip(link_from, link_to):
union(a, b)
# count connected components (only 1..link_nodes)
components = len({find(i) for i in range(1, link_nodes + 1)})
return components - 1
Time complexity: O(E * alpha(N)), union-find is near linear. Traps:
- When edges are insufficient you must return -1 first, otherwise
c - 1gives a wrong answer - Check whether node numbering is 1-based; the code above assumes 1-based, switch to
range(0, link_nodes)for 0-based - Self-loops and duplicate edges do not affect component count, union-find dedups naturally
Prep Topic Checklist
| Topic | Frequency | Key technique |
|---|---|---|
| Array sim / average check | High | Integer multiply over float |
| Prefix sum / sliding window | Medium | O(1) range-sum queries |
| Union-find / graph connectivity | High | Path compression + component count |
| String processing | Medium | Counting / hash grouping |
FAQ
Q1: How hard are IBM OA problems? Not very. They lean toward fundamentals, common algorithms and graph reasoning. LeetCode Medium prep handles them comfortably.
Q2: Which platform? HackerRank. The UI and flow are like common OA platforms, just learn the submit flow in advance.
Q3: Is an hour enough for two problems? Absolutely. With fluency both can be done in under 20 minutes, leaving time to recheck hidden cases.
Q4: What should I grind beforehand? Focus on array sim, prefix sum, union-find, and graph connectivity. IBM OA mainly tests fundamentals, nothing too fancy.
Q5: Which language? HackerRank supports mainstream languages, Python / Java / C++ all work; union-find is fastest to write in Python.
Preparing for the IBM OA?
The IBM OA leans basic, but careless reading or a mishandled union-find edge case still loses points. If you want targeted topic review and timed mocks, reach out below for real questions and a prep plan.
Contact
Need real interview questions and a customized prep plan? Add WeChat Coding0201 now, get the questions.
Email: [email protected] Telegram: @OAVOProxy