IBM interview prep

Practice 30 problems from community-reported IBM interviews.

Start practicing Pythagorean Distance Nodes in a Tree

Ranked problems

30 problems
IBM interview prep, ordered by rank
ProblemDifficultyCompany lists
Breadth-first search

Count tree nodes whose distances to three given targets, sorted as a, b and c, satisfy a² + b² = c².

On the IBM list.

Medium
Stacks

Check whether a string of round, square, and curly brackets closes every opening bracket in the correct order.

On the Amazon, Google, Microsoft, Meta, IBM, Oracle lists.

Easy
Greedy

Each ball sells for the number of balls of its color still in stock. Maximize revenue while filling a fixed number of orders.

On the IBM list.

Medium
Intervals

Combine overlapping intervals and return a list that covers the same ranges without overlaps.

On the Amazon, Microsoft, IBM, Oracle, J.P. Morgan, Morgan Stanley lists.

Medium
Data structure design

Implement expiring tokens with operations to generate a token, renew an unexpired token, and count tokens still valid at a given time.

On the IBM, Oracle lists.

Medium
Strings

Build the output for 1 through n, replacing multiples of three with Fizz, multiples of five with Buzz, and multiples of both with FizzBuzz.

On the IBM list.

Easy
Strings

Convert a positive integer to Roman numerals, including subtractive forms such as IV and IX.

On the IBM list.

Medium
Two pointers

Choose two vertical lines that, together with the x-axis, can hold the greatest area of water.

On the Amazon, Google, Microsoft, Meta, IBM, Oracle lists.

Medium
Hash tables

Decide whether two strings contain exactly the same characters with the same multiplicities.

On the Google, Microsoft, Meta, IBM, Oracle lists.

Easy
Greedy

Find the fewest letters to insert into a string of a, b and c so the result consists entirely of consecutive copies of abc.

On the IBM list.

Medium
Arrays

Rearrange the array in place so its values alternate strictly up and down, starting with an upward step.

On the IBM list.

Medium
Strings

Return the longest contiguous part of a string that reads the same forward and backward.

On the Amazon, Google, Microsoft, Meta, Tekion, IBM, Oracle, J.P. Morgan lists.

Medium
Dynamic programming

Choosing a number earns its value and eliminates all occurrences of its neighboring values. Find the highest score you can earn.

On the IBM, Morgan Stanley lists.

Medium
Strings

Count all contiguous substrings that read the same backward and forward. Count occurrences at different positions separately.

On the IBM list.

Medium
Sliding window

Find the length of the longest contiguous stretch of a string in which no character appears twice.

On the Amazon, Google, Microsoft, Meta, Tekion, IBM, Oracle, J.P. Morgan, Morgan Stanley lists.

Medium
Arrays

Given daily prices, find the best profit from buying once and selling on a later day. Return zero if no trade makes money.

On the Amazon, Google, Microsoft, Meta, IBM, J.P. Morgan, Morgan Stanley lists.

Easy
Strings

Find the longest substring in which each letter is exactly one place after the preceding letter in the alphabet.

On the IBM list.

Medium
Counting

Count binary substrings made of two consecutive runs of equal length, one of zeros and one of ones in either order.

On the IBM, J.P. Morgan lists.

Easy
Strings

Find the longest starting sequence of characters shared by every string in a list.

On the Amazon, Google, Microsoft, Meta, IBM lists.

Easy
Linked lists

Return the middle node of a singly linked list. If there are two middle nodes, return the second.

On the IBM list.

Easy
Linked lists

Return the node where a cycle begins in a singly linked list, or null if following the links eventually reaches the end.

On the IBM list.

Medium
Two pointers

Turn a string into a palindrome using as few character replacements as possible. Among equally short edits, choose the alphabetically smallest result.

On the IBM list.

Easy
Strings

Read a Roman numeral and compute its integer value, accounting for smaller symbols that precede larger ones.

On the Google, Microsoft, IBM lists.

Easy
Greedy

Split the marbles into k consecutive bags. Each bag scores the sum of its two end weights. Find the difference between the highest and lowest total scores.

On the IBM list.

Hard
Hash tables

Find the indices of two different elements in an array whose values add up to a given target.

On the Amazon, Google, Microsoft, Meta, Samsung, Tekion, IBM, Oracle, J.P. Morgan, Morgan Stanley lists.

Try [2, 7, 11, 15] with a target of 9.

Reveal the indices

[0, 1] points to 2 and 7.

Easy
Intervals

Assign each interval to one of two labeled groups so overlapping intervals always stay together. Count the valid assignments.

On the IBM list.

Medium
Prefix sums

Count how many nonempty contiguous parts of an integer array have a sum of exactly k.

On the Amazon, Google, Microsoft, Meta, IBM, J.P. Morgan lists.

Medium
Arrays

Each query asks for the index of a particular occurrence of a target value. Return −1 when that occurrence does not exist.

On the IBM list.

Medium
Greedy

You may increment one matrix cell by one per move. Find the fewest moves that make every column strictly increasing from top to bottom.

On the IBM list.

Easy
Two pointers

Find the longest contiguous segment that rises strictly and then falls strictly, with at least one step on each side of the peak.

On the IBM list.

Medium
How are questions ranked?

Company lists follow community-reported interview frequency. Ties keep the source order. Where a list uses two sources, we keep the first list’s ranks and fill the remaining places with the highest-ranked distinct problems from the second.

Across companies, first place earns 30 points and each subsequent rank earns one fewer. We add each problem’s points and break ties alphabetically.