Problem database last updated: June 20, 2025

IIBM logo

IBM Coding Interview Questions

93 problems · 26 Easy, 59 Medium, 8 Hard · Ranked #23 of 458

Difficulty breakdown

26 Easy

28% · avg 23%

59 Medium

63% · avg 59%

8 Hard

9% · avg 18%

Top topics

array
67.7%
string
28%
hash-table
23.7%
sorting
19.4%
two-pointers
18.3%
dynamic-programming
17.2%

Interview profile

Based on 93 reported problems, IBM interviews are in line with industry averages - 9% Hard vs 18% overall. The majority (63%) of questions are Medium difficulty, which is typical for companies that want to see solid fundamentals without excessive trick questions.

Compared to the industry average, IBM puts unusual emphasis on number-theory (2.2% of problems, 4.2x the industry average), prefix-sum (11.8% of problems, 3.6x the industry average), bit-manipulation (8.6% of problems, 2.6x the industry average). If you're short on time, these are the categories to double down on.

The most common topics are array (67.7%), string (28%), hash-table (23.7%), sorting (19.4%). Problems below are sorted by frequency, the ones at the top are asked most often.

All 93 problems

Exclusive Time of Functions

Solve

On a single-threaded CPU, we execute a program containing n functions. Each function has a unique ID between 0 and n-1.

MediumVery Likely
arraystack

Integer to Roman

Solve

Seven different symbols represent Roman numerals with the following values:

MediumVery Likely
hash-tablemathstring

Fizz Buzz

Solve

Given an integer n, return a string array answer (1-indexed) where:

EasyVery Likely
mathstringsimulation

Roman to Integer

Solve

Roman numerals are represented by seven different symbols: I, V, X, L, C, D and M.

EasyVery Likely
hash-tablemathstring

Best Time to Buy and Sell Stock

Solve

You are given an array prices where prices[i] is the price of a given stock on the ith day.

EasyVery Likely
arraydynamic-programming

Two Sum

Solve

Given an array of integers nums and an integer target, return the indices of the two numbers that add up to target.

EasyVery Likely
arrayhash-map

Count Ways to Group Overlapping Ranges

Solve

You are given a 2D integer array ranges where ranges[i] = [starti, endi] denotes that all integers between starti and endi (both inclusive) are contained in the...

MediumVery Likely
arraysorting

Minimum Operations to Make All Array Elements Equal

Solve

You are given an array nums consisting of positive integers.

MediumVery Likely
arraybinary-searchsorting

Rotate Image

Solve

You are given an n x n 2D matrix representing an image, rotate the image by 90 degrees (clockwise).

MediumVery Likely
arraymathmatrix

Minimum Absolute Difference

Solve

Given an array of distinct integers arr, find all pairs of elements with the minimum absolute difference of any two elements.

EasyVery Likely
arraysorting

Minimum Operations to Make Median of Array Equal to K

Solve

You are given an integer array nums and a non-negative integer k. In one operation, you can increase or decrease any element by 1.

MediumVery Likely
arraygreedysorting

Find The First Player to win K Games in a Row

Solve

A competition consists of n players numbered from 0 to n - 1.

MediumLikely
arraysimulation

The kth Factor of n

Solve

You are given two positive integers n and k. A factor of an integer n is defined as an integer i where n % i == 0.

MediumLikely
mathnumber-theory

Average Value of Even Numbers That Are Divisible by Three

Solve

Given an integer array nums of positive integers, return the average value of all even integers that are divisible by 3.

EasyLikely
arraymath

Longest Substring Without Repeating Characters

Solve

Given a string s, find the length of the longest substring without duplicate characters.

MediumLikely
hash-tablestringsliding-window

Merge Intervals

Solve

Given an array of intervals where intervals[i] = [starti, endi], merge all overlapping intervals, and return an array of the non-overlapping intervals that cove...

MediumLikely
arraysorting

String Compression

Solve

Given an array of characters chars, compress it using the following algorithm:

MediumLikely
two-pointersstring

Count Vowel Strings in Ranges

Solve

You are given a 0-indexed array of strings words and a 2D array of integers queries.

MediumLikely
arraystringprefix-sum

Count the Number of Incremovable Subarrays II

Solve

You are given a 0-indexed array of positive integers nums.

HardLikely
arraytwo-pointersbinary-search

Minimum Levels to Gain More Points

Solve

You are given a binary array possible of length n.

MediumLikely
arrayprefix-sum

Sort the Students by Their Kth Score

Solve

There is a class with m students and n exams. You are given a 0-indexed m x n integer matrix score, where each row represents one student and score[i][j] denote...

MediumLikely
arraysortingmatrix

Minimum Length of String After Operations

Solve

You are given a string s.

MediumLikely
hash-tablestringcounting

Find Products of Elements of Big Array

Solve

The powerful array of a non-negative integer x is defined as the shortest sorted array of powers of two that sum up to x. The table below illustrates examples o...

HardLikely
arraybinary-searchbit-manipulation

Type of Triangle

Solve

You are given a 0-indexed integer array nums of size 3 which can form the sides of a triangle.

EasyLikely
arraymathsorting

Taking Maximum Energy From the Mystic Dungeon

Solve

In a mystic dungeon, n magicians are standing in a line. Each magician has an attribute that gives you energy. Some magicians can give you negative energy, whic...

MediumLikely
arraydynamic-programmingprefix-sum

Find Occurrences of an Element in an Array

Solve

You are given an integer array nums, an integer array queries, and an integer x.

MediumLikely
arrayhash-table

Find the Array Concatenation Value

Solve

You are given a 0-indexed integer array nums.

EasyLikely
arraytwo-pointerssimulation

Maximum Units on a Truck

Solve

You are assigned to put some amount of boxes onto one truck. You are given a 2D array boxTypes, where boxTypes[i] = [numberOfBoxesi, numberOfUnitsPerBoxi]:

EasyLikely
arraygreedysorting

Longest Common Prefix

Solve

Write a function to find the longest common prefix string amongst an array of strings.

EasyLikely
arraystringtrie

Count Binary Substrings

Solve

Given a binary string s, return the number of non-empty substrings that have the same number of 0's and 1's, and all the 0's and all the 1's in these substrings...

EasyLikely
two-pointersstring

Get Equal Substrings Within Budget

Solve

You are given two strings s and t of the same length and an integer maxCost.

MediumLikely
stringbinary-searchsliding-window

Valid Parentheses

Solve

Given a string s containing just the characters '(', ')', '{', '}', '[' and ']', determine if the input string is valid.

EasyLikely
stringstack

Letter Combinations of a Phone Number

Solve

Given a string containing digits from 2-9 inclusive, return all possible letter combinations that the number could represent. Return the answer in any order.

MediumLikely
hash-tablestringbacktracking

Minimum Suffix Flips

Solve

You are given a 0-indexed binary string target of length n. You have another binary string s of length n that is initially set to all zeros. You want to make s...

MediumLikely
stringgreedy

Numbers With Repeated Digits

Solve

Given an integer n, return the number of positive integers in the range [1, n] that have at least one repeated digit.

HardLikely
mathdynamic-programming

Maximum Sum of Distinct Subarrays With Length K

Solve

You are given an integer array nums and an integer k. Find the maximum subarray sum of all the subarrays of nums that meet the following conditions:

MediumLikely
arrayhash-tablesliding-window

Merge Sorted Array

Solve

You are given two integer arrays nums1 and nums2, sorted in non-decreasing order, and two integers m and n, representing the number of elements in nums1 and num...

EasyLikely
arraytwo-pointerssorting

Longest Palindromic Substring

Solve

Given a string s, return the longest palindromic substring in s.

MediumLikely
two-pointersstringdynamic-programming

Lexicographically Smallest String After Substring Operation

Solve

Given a string s consisting of lowercase English letters. Perform the following operation:

MediumLikely
stringgreedy

Longest Consecutive Sequence

Solve

Given an unsorted array of integers nums, return the length of the longest consecutive elements sequence.

MediumLikely
arrayhash-tableunion-find

Spiral Matrix

Solve

Given an m x n matrix, return all elements of the matrix in spiral order.

MediumLikely
arraymatrixsimulation

Shortest and Lexicographically Smallest Beautiful String

Solve

You are given a binary string s and a positive integer k.

MediumLikely
stringsliding-window

Count Pairs Of Similar Strings

Solve

You are given a 0-indexed string array words.

EasyLikely
arrayhash-tablestring

Maximum Subarray

Solve

Given an integer array nums, find the subarray with the largest sum, and return its sum.

MediumLikely
arraydivide-and-conquerdynamic-programming

Divide Players Into Teams of Equal Skill

Solve

You are given a positive integer array skill of even length n where skill[i] denotes the skill of the ith player. Divide the players into n / 2 teams of size 2...

MediumLikely
arrayhash-tabletwo-pointers

Group Anagrams

Solve

Given an array of strings strs, group the anagrams together. You can return the answer in any order.

MediumLikely
arrayhash-tablestring

Subarray Product Less Than K

Solve

Given an array of integers nums and an integer k, return the number of contiguous subarrays where the product of all the elements in the subarray is strictly le...

MediumLikely
arraybinary-searchsliding-window

Minimum Swaps to Group All 1's Together II

Solve

A swap is defined as taking two distinct positions in an array and swapping the values in them.

MediumLikely
arraysliding-window

Climbing Stairs

Solve

You are climbing a staircase. It takes n steps to reach the top.

EasyLikely
mathdynamic-programmingmemoization

Smallest Missing Non-negative Integer After Operations

Solve

You are given a 0-indexed integer array nums and an integer value.

MediumLikely
arrayhash-tablemath

Validate Binary Search Tree

Solve

Given the root of a binary tree, determine if it is a valid binary search tree (BST).

MediumLikely
treedepth-first-searchbinary-search-tree

Trapping Rain Water

Solve

Given n non-negative integers representing an elevation map where the width of each bar is 1, compute how much water it can trap after raining.

HardSometimes
arraytwo-pointersdynamic-programming

Backspace String Compare

Solve

Given two strings s and t, return true if they are equal when both are typed into empty text editors. '' means a backspace character.

EasySometimes
two-pointersstringstack

Number of Operations to Make Network Connected

Solve

There are n computers numbered from 0 to n - 1 connected by ethernet cables connections forming a network where connections[i] = [ai, bi] represents a connectio...

MediumSometimes
depth-first-searchbreadth-first-searchunion-find

Rotate Array

Solve

Given an integer array nums, rotate the array to the right by k steps, where k is non-negative.

MediumSometimes
arraymathtwo-pointers

Intersection of Two Arrays

Solve

Given two integer arrays nums1 and nums2, return an array of their intersection. Each element in the result must be unique and you may return the result in any...

EasySometimes
arrayhash-tabletwo-pointers

Find Minimum in Rotated Sorted Array

Solve

Suppose an array of length n sorted in ascending order is rotated between 1 and n times. For example, the array nums = [0,1,2,4,5,6,7] might become:

MediumSometimes
arraybinary-search

Odd String Difference

Solve

You are given an array of equal-length strings words. Assume that the length of each string is n.

EasySometimes
arrayhash-tablestring

Single-Threaded CPU

Solve

You are given n​​​​​​ tasks labeled from 0 to n - 1 represented by a 2D integer array tasks, where tasks[i] = [enqueueTimei, processingTimei] means that the i​​...

MediumSometimes
arraysortingheap-priority-queue

Palindrome Number

Solve

Given an integer x, return true if x is a palindrome, and false otherwise.

EasySometimes
math

Subarray Sum Equals K

Solve

Given an array of integers nums and an integer k, return the total number of subarrays whose sum equals to k.

MediumSometimes
arrayhash-tableprefix-sum

Flipping an Image

Solve

Given an n x n binary matrix image, flip the image horizontally, then invert it, and return the resulting image.

EasySometimes
arraytwo-pointersbit-manipulation

Flip String to Monotone Increasing

Solve

A binary string is monotone increasing if it consists of some number of 0's (possibly none), followed by some number of 1's (also possibly none).

MediumSometimes
stringdynamic-programming

Find The Original Array of Prefix Xor

Solve

You are given an integer array pref of size n. Find and return the array arr of size n that satisfies:

MediumSometimes
arraybit-manipulation

Product of Array Except Self

Solve

Given an integer array nums, return an array answer such that answer[i] is equal to the product of all the elements of nums except nums[i].

MediumSometimes
arrayprefix-sum

Longest Increasing Subsequence

Solve

Given an integer array nums, return the length of the longest strictly increasing subsequence.

MediumSometimes
arraybinary-searchdynamic-programming

Next Permutation

Solve

A permutation of an array of integers is an arrangement of its members into a sequence or linear order.

MediumSometimes
arraytwo-pointers

Find the Index of the First Occurrence in a String

Solve

Given two strings needle and haystack, return the index of the first occurrence of needle in haystack, or -1 if needle is not part of haystack.

EasySometimes
two-pointersstringstring-matching

Median of Two Sorted Arrays

Solve

Given two sorted arrays nums1 and nums2 of size m and n respectively, return the median of the two sorted arrays.

HardSometimes
arraybinary-searchdivide-and-conquer

Subsets

Solve

Given an integer array nums of unique elements, return all possible subsets (the power set).

MediumSometimes
arraybacktrackingbit-manipulation

Generate Parentheses

Solve

Given n pairs of parentheses, write a function to generate all combinations of well-formed parentheses.

MediumSometimes
stringdynamic-programmingbacktracking

Range Product Queries of Powers

Solve

Given a positive integer n, there exists a 0-indexed array called powers, composed of the minimum number of powers of 2 that sum to n. The array is sorted in no...

MediumSometimes
arraybit-manipulationprefix-sum

N-Queens

Solve

The n-queens puzzle is the problem of placing n queens on an n x n chessboard such that no two queens attack each other.

HardSometimes
arraybacktracking

Find All Possible Stable Binary Arrays II

Solve

You are given 3 positive integers zero, one, and limit.

HardSometimes
dynamic-programmingprefix-sum

Removing Stars From a String

Solve

You are given a string s, which contains stars .

MediumSometimes
stringstacksimulation

Minimum Number of Flips to Make the Binary String Alternating

Solve

You are given a binary string s. You are allowed to perform two types of operations on the string in any sequence:

MediumSometimes
stringdynamic-programmingsliding-window

Rearrange Array to Maximize Prefix Score

Solve

You are given a 0-indexed integer array nums. You can rearrange the elements of nums to any order (including the given order).

MediumSometimes
arraygreedysorting

132 Pattern

Solve

Given an array of n integers nums, a 132 pattern is a subsequence of three integers nums[i], nums[j] and nums[k] such that i < j < k and nums[i] < nums[k] < num...

MediumSometimes
arraybinary-searchstack

The Employee That Worked on the Longest Task

Solve

There are n employees, each with a unique id from 0 to n - 1.

EasySometimes
array

Count Number of Teams

Solve

There are n soldiers standing in a line. Each soldier is assigned a unique rating value.

MediumSometimes
arraydynamic-programmingbinary-indexed-tree

Minimum Operations to Reduce an Integer to 0

Solve

You are given a positive integer n, you can do the following operation any number of times:

MediumSometimes
dynamic-programminggreedybit-manipulation

Prime In Diagonal

Solve

You are given a 0-indexed two-dimensional integer array nums.

EasySometimes
arraymathmatrix

Majority Element

Solve

Given an array nums of size n, return the majority element.

EasySometimes
arrayhash-tabledivide-and-conquer

Find the Duplicate Number

Solve

Given an array of integers nums containing n + 1 integers where each integer is in the range [1, n] inclusive.

MediumSometimes
arraytwo-pointersbinary-search

Least Number of Unique Integers after K Removals

Solve

Given an array of integers arr and an integer k. Find the least number of unique integers after removing exactly k elements.

MediumSometimes
arrayhash-tablegreedy

Partition Equal Subset Sum

Solve

Given an integer array nums, return true if you can partition the array into two subsets such that the sum of the elements in both subsets is equal or false oth...

MediumSometimes
arraydynamic-programming

Task Scheduler

Solve

You are given an array of CPU tasks, each labeled with a letter from A to Z, and a number n. Each CPU interval can be idle or allow the completion of one task....

MediumSometimes
arrayhash-tablegreedy

Increasing Triplet Subsequence

Solve

Given an integer array nums, return true if there exists a triple of indices (i, j, k) such that i < j < k and nums[i] < nums[j] < nums[k]. If no such indices e...

MediumSometimes
arraygreedy

Maximum Number of Tasks You Can Assign

Solve

You have n tasks and m workers. Each task has a strength requirement stored in a 0-indexed integer array tasks, with the ith task requiring tasks[i] strength to...

HardSometimes
arraytwo-pointersbinary-search

Degree of an Array

Solve

Given a non-empty array of non-negative integers nums, the degree of this array is defined as the maximum frequency of any one of its elements.

EasySometimes
arrayhash-table

Word Break

Solve

Given a string s and a dictionary of strings wordDict, return true if s can be segmented into a space-separated sequence of one or more dictionary words.

MediumSometimes
arrayhash-tablestring

Happy Number

Solve

Write an algorithm to determine if a number n is happy.

EasySometimes
hash-tablemathtwo-pointers

LRU Cache

Solve

Design a data structure that follows the constraints of a Least Recently Used (LRU) cache.

MediumSometimes
hash-tablelinked-listdesign

How often are these problems asked?

Frequency scores are based on crowdsourced interview reports. A higher score means the problem has been reported more often in recent IBM interviews.

Very Likely

75-100%

Likely

50-74%

Sometimes

25-49%

Rare

0-24%

Preparing for your IBM coding interview

IBM interviews focus heavily on array, string, hash-table problems. If you're short on time, these are the categories to prioritize. The problems on this page are sorted by frequency, so start from the top and work your way down.

Beyond solving problems, practice explaining your approach. IBM interviewers care about your thought process - how you break down a problem, consider edge cases, and evaluate tradeoffs between solutions. A clean O(n) solution you can explain clearly beats an O(log n) solution you can't articulate.

Looking for more companies? Browse all 458 companies in our directory, or sharpen your fundamentals with our free data structure visualizers and AI-powered DSA tutor.

Frequently Asked Questions

What coding problems does IBM ask in interviews?add

IBM has been reported to ask 93 distinct coding problems. The most common topics are array, string, hash-table. 26 are Easy difficulty, 59 are Medium, and 8 are Hard. Problems are sorted by frequency - the ones at the top are asked most often.

How hard are IBM coding interviews?add

Based on 93 reported problems, IBM interviews are in line with industry averages - 9% Hard vs 18% overall. 63% of questions are Medium difficulty. Focus on the high-frequency Medium problems first, then work through the Hard ones.

How should I prepare for a IBM coding interview?add

Start with the highest-frequency problems listed on this page. Focus on the core topics: array, string, hash-table. Practice solving them under time pressure and explaining your approach out loud. Mock interviews with AI can simulate the real experience.

Other companies to explore

Ready to ace your IBM interview?

Simulate a real IBM coding interview with an AI interviewer. Get a scorecard with specific feedback on your problem-solving, code quality, and communication.

Simulate a IBM interview with AIarrow_forward