IBM OA High Frequency Algorithm Real Questions Compilation and Detailed Explanations (2025–2026 Latest Edition) | IBM OA Exam Preparation Guide 

1,518 Views

In today's increasingly competitive tech industry, IBM OA still maintains its consistent style: the questions are not biased, but the basic ability requirements are extremely high. We systematically sort out the 6 types of algorithm questions that have appeared frequently in IBM in recent years. Clearly explain the thinking path behind each question, so that you can do it in the examination room: see the question type → quickly locate the solution → write code stably.

IBM OA High Frequency Algorithm Real Questions Compilation and Detailed Explanations (2025–2026 Latest Edition) | IBM OA Exam Preparation Guide 

Question 1: Maximum non-overlapping time intervals

Describe: Given two arrays of length n, startTime and endTime, each interval is left closed and right open [startTime[i], endTime[i]). Find the maximum number of non-overlapping intervals that can be selected.

Sample:

  • N=3, start=[1,1,2], end=[3,2,4] → output 2 (select [1,2) and [2,4))

Constraint:n ≤ 10⁵, time 1~10⁹

Ideas: Classic activity selection problem. Sort by end time, and greedily select the interval that ends earliest and does not conflict with the selected one.

Code (Python):

Def maxNonOverlapping(start, end):

intervals = sorted(zip(start, end), key=lambda x: x[1])

Count = 0

last_end = -float('inf')

For s, e in intervals:

           if s >= last_end:

Count += 1

last_end = e

return count

Time complexity:O(n log n)

Question 2: Maximum stock price increase difference (maximum profit variation of a single transaction)

Describe: Given an integer array, find the maximum value of arr[j] – arr[i] when i < j and arr[i] < arr[j]. If it does not exist, -1 is returned.

Sample:

  • [5,3,6,7,4] → 4(7-3)
  • [4,3,2,1] → -1

Constraint: n ≤ 2×10⁵, element ±10⁶

Ideas: One traversal, maintain the historical minimum value, and update the maximum difference value.

Code:

Def maxProfit(arr):

If not arr:

Return -1

Min_price = arr[0]

max_diff = -1

for price in arr[1:]:

           if price > min_price:

              max_diff = max(max_diff, price - min_price)

         min_price = min(min_price, price)

Return max_diff

Time complexity:O(n)

Question 3: Total number of n vertex compositions (fast power)

Describe: n vertices (labeled), constructing an undirected simple graph (no self-loops, no duplicate edges, and may not be connected). Each pair of vertices can be connected to an edge or not. Find the total number of solutions, modulo 10⁹+7.

Sample:

  • N=2 → 2
  • N=4→64

Ideas: The number of possible sides is C(n,2) = n(n-1)/2, 2 choices for each side → the answer is 2^{n(n-1)/2} % MOD. N ≤ 10⁹, fast powers must be used.

Code:

MOD = 10**9 + 7

def countGraphs(n):

If n == 1:

return 1

exp = n * (n - 1) // 2

# pow(base, exp, mod)

Return pow(2, exp, MOD)

Time complexity:O(log (n²))

Question 4: Counting legal triples

Describe: Given a mutually different integer array d and a threshold t, count the number of triples (a,b,c) that satisfy d[a] < d[b] < d[c] and d[a]+d[b]+d[c] <= t (the subscripts do not require order, only the value).

Sample: d=[1,2,3,4,5], t=8 → 4 (1+2+3=6, 1+2+4=7, 1+2+5=8, 1+3+4=8)

Constraint: n ≤ 10⁴, d[i] < 10⁹, t < 3×10⁹

Ideas: Sort first (O(n log n)). Fixed i < j, double pointers find the largest k that satisfies d[i]+d[j]+d[k] d[j].

Code:

Def countTriplets(d, t):

d = sorted(d)

n = len(d)

Count = 0

For i in range(n-2):

j = i + 1

k = n - 1

          while j < k:

If d[i] + d[j] + d[k] <= t:

                   # From j+1 to k are satisfied (sorted)

Count += k - j

j += 1

                else:

k -= 1

return count

Time complexity:O(n²)

Question 5: Maximum number of skill team members (sliding window + double-ended queue)

Describe: Given a skill array, select the longest subarray so that the maximum value in the array – the minimum value ≤ the limit difference (the limit value is not explicitly written in the question, and the limit is usually given).

Sample:[4,13,2,3] → 3 ([4,2,3] or similar, assuming limit is sufficient)

Constraint:n ≤ 10⁵

Ideas: Sliding window + double-ended queue maintains the maximum and minimum values ​​within the window. When the window is not satisfied, the left end moves to the right.

Code framework(assuming limit parameter):

From collections import deque

def maxTeamSize(skills, limit):

n = len(skills)

left = 0

maxq = deque()

Minq = deque()

ans = 0

For right in range(n):

​​​​ # Maintain the maximum value queue (decreasingly)

While maxq and skills[maxq[-1]] = skills[right]:

            minq.pop()

Minq.append(right)

          # Shrink window

While skills[maxq[0]] - skills[minq[0]] > limit:

              left += 1

If maxq[0] < left: maxq.popleft()

                  if minq[0] < left: minq.popleft()

ans = max(ans, right - left + 1)

return ans

Time complexity:O(n)

Question 6: Minimal rearrangement of tasks in lexicographic order (odd and even tasks are interchangeable)

Describe: The task priority is single digit. Odd numbers = CPU tasks, even numbers = IO tasks. Only adjacent odd and even tasks can be exchanged. Find the lexicographically smallest achievable priority sequence.

Core: The relative order of identical odd (or identical even) tasks cannot be changed; odd and even tasks can be interspersed arbitrarily (because they can be freely exchanged).

Ideas: Extract odd-numbered sequences and even-numbered sequences respectively (maintaining the original relative order), and then merge them greedily like merging to obtain the smallest interleaved sequence in lexicographic order.

Code:

Def minLexReorder(tasks):

​​odds = [x for x in tasks if x % 2 == 1]

Evens = [x for x in tasks if x % 2 == 0]

i = j = 0

result = []

While i < len(odds) or j < len(evens):

If i == len(odds):

result.append(evens[j])

j += 1

        elif j == len(evens):

result.append(odds[i])

i += 1

        elif odds[i] < evens[j]:

result.append(odds[i])

i += 1

          else:

result.append(evens[j])

j += 1

return result

Write at the end

The above 6 questions are high-frequency real questions that appear repeatedly in IBM interviews. Mastering them can significantly increase the passing rate. The core of the algorithm interview lies in understanding the essence rather than memorizing it by rote. It is recommended that you pay attention to time complexity and boundary condition processing when practicing. If you would like to get more IBM real question analysis, Java/C++ version code, real-time interview assistance, or targeted question brushing plans, please contact us ProgramHelp!

ProgramHelp Focusing on algorithm interview coaching for big companies, we have helped thousands of students successfully get FAANG offers from IBM, Google, etc. We offer:

  • Compilation of the latest real questions from major manufacturers and video explanations
  • Personalized quiz route planning
  • Mock interviews and code review
  • OA traceless assist
  • VO real-time assistance
author avatar
Jory Wang Amazon Senior Software Development Engineer
Amazon senior engineer, focusing on the research and development of infrastructure core systems, with rich practical experience in system scalability, reliability and cost optimization. Currently focusing on FAANG SDE interview coaching, helping 30+ candidates successfully obtain L5/L6 Offers within one year.
END
 0