Ola Coding Interview Questions
100 Ola coding interview problems with full optimal solutions — 32 easy, 60 medium, 8 hard. Every problem ships with multiple approaches (brute-force first, then the optimal), complexity tables for each, company-specific tips on what an Ola interviewer values, and a FAQ section.
- #1easyfoundational
1. Two Sum
Find two indices in an array whose values sum to a target.
- #2easyfoundational
2. Valid Parentheses
Validate that bracket characters in a string close in the right order.
- #3easyfoundational
3. Merge Two Sorted Lists
Merge two ascending linked lists into one sorted list.
- #4easyfoundational
4. Remove Duplicates from Sorted Array
Remove duplicates in-place from a sorted array and return the new length.
- #5easyfoundational
5. Remove Element
Remove all occurrences of a value from an array in-place and return the new length.
- #6easyfoundational
6. Search Insert Position
Find the index where a target should be inserted in a sorted array.
- #7easyfoundational
7. Plus One
Add one to an integer represented as an array of digits.
- #8easyfoundational
8. Merge Sorted Array
Merge two sorted arrays in-place into the first.
- #9easyfoundational
9. Binary Tree Inorder Traversal
Return the inorder traversal of a binary tree's node values.
- #10easyfoundational
10. Same Tree
Determine whether two binary trees are structurally identical with equal values.
- #11easyfoundational
11. Symmetric Tree
Check whether a binary tree mirrors itself around the center.
- #12easyfoundational
12. Maximum Depth of Binary Tree
Find the maximum depth (height) of a binary tree.
- #13easyfoundational
13. Balanced Binary Tree
Determine whether a binary tree is height-balanced.
- #14easyfoundational
14. Minimum Depth of Binary Tree
Find the shortest path from the root to any leaf in a binary tree.
- #15easyfoundational
15. Pascal's Triangle
Generate the first numRows of Pascal's triangle.
- #16easyfoundational
16. Best Time to Buy and Sell Stock
Maximize profit from a single buy/sell of a daily price array.
- #17easyfoundational
17. Valid Palindrome
Determine if a phrase reads the same forward and backward, ignoring non-alphanumerics.
- #18easyfoundational
18. Single Number
Find the lone element in an array where every other element appears twice.
- #19easyfoundational
19. Linked List Cycle
Detect whether a linked list contains a cycle.
- #20easyfoundational
20. Min Stack
Design a stack that supports retrieving the minimum element in O(1).
- #21easyfoundational
21. Two Sum II - Input Array Is Sorted
Find two indices in a sorted array whose values sum to a target using O(1) extra space.
- #22easyfoundational
22. Majority Element
Find the element that appears more than n/2 times in an array.
- #23easyfoundational
23. Rotate Array
Rotate an array to the right by k steps in-place.
- #24easyfoundational
24. Reverse Bits
Reverse the bits of a 32-bit unsigned integer.
- #25easyfoundational
25. Number of 1 Bits
Count the set bits (Hamming weight) of an unsigned integer.
- #26mediumfoundational
26. House Robber
Maximize loot from a line of houses where you cannot rob two adjacent ones.
- #27easyfoundational
27. Happy Number
Determine whether iteratively replacing a number with the sum of squares of its digits eventually reaches 1.
- #28easyfoundational
28. Isomorphic Strings
Decide whether two strings have a one-to-one character mapping.
- #29easyfoundational
29. Reverse Linked List
Reverse a singly linked list and return the new head.
- #30easyfoundational
30. Contains Duplicate
Return true if any value appears at least twice in an array.
- #31mediumfoundational
31. Add Two Numbers
Add two numbers represented as linked lists in reverse-digit order.
- #32mediumfoundational
32. Longest Substring Without Repeating Characters
Find the length of the longest substring without repeating characters.
- #33mediumfoundational
33. Longest Palindromic Substring
Find the longest palindromic substring of a string.
- #34mediumfoundational
34. Container With Most Water
Find two lines that together with the x-axis form a container holding the most water.
- #35mediumfoundational
35. 3Sum
Find all unique triplets in an array that sum to zero.
- #36mediumfoundational
36. Letter Combinations of a Phone Number
Return all possible letter combinations that a phone number string could represent.
- #37mediumfoundational
37. Remove Nth Node From End of List
Remove the nth node from the end of a linked list in one pass.
- #38mediumfoundational
38. Generate Parentheses
Generate all combinations of n pairs of well-formed parentheses.
- #39mediumfoundational
39. Swap Nodes in Pairs
Swap every two adjacent nodes of a linked list.
- #40mediumfoundational
40. Next Permutation
Rearrange numbers into the next lexicographically greater permutation.
- #41mediumfoundational
41. Search in Rotated Sorted Array
Search for a target in a rotated sorted array in O(log n).
- #42mediumfoundational
42. Find First and Last Position of Element in Sorted Array
Find the start and end indices of a target in a sorted array in O(log n).
- #43mediumfoundational
43. Valid Sudoku
Determine if a partially-filled 9x9 Sudoku board is valid.
- #44mediumfoundational
44. Combination Sum
Find all unique combinations of candidates that sum to a target.
- #45mediumfoundational
45. Combination Sum II
Find all unique combinations summing to a target where each candidate is used at most once.
- #46mediumfoundational
46. Multiply Strings
Multiply two non-negative integers represented as strings without using BigInt.
- #47mediumfoundational
47. Permutations
Return all possible permutations of a distinct integer array.
- #48mediumfoundational
48. Rotate Image
Rotate an n x n 2D matrix by 90 degrees clockwise in-place.
- #49mediumfoundational
49. Group Anagrams
Group strings that are anagrams of each other.
- #50mediumfoundational
50. Spiral Matrix
Return all elements of a 2D matrix in spiral order.
- #51mediumfoundational
51. Jump Game
Determine if you can reach the last index of an array given max jump lengths at each index.
- #52mediumfoundational
52. Merge Intervals
Merge a collection of overlapping intervals.
- #53mediumfoundational
53. Unique Paths
Count distinct paths from the top-left to the bottom-right of an m x n grid moving only right or down.
- #54mediumfoundational
54. Minimum Path Sum
Find the minimum-cost top-left-to-bottom-right path in a grid.
- #55mediumfoundational
55. Simplify Path
Simplify a Unix-style absolute path.
- #56hardfoundational
56. Edit Distance
Find the minimum edit distance between two strings.
- #57mediumfoundational
57. Set Matrix Zeroes
Zero out the row and column of every zero in a matrix, in-place.
- #58mediumfoundational
58. Search a 2D Matrix
Search for a target in a row-and-column-sorted matrix.
- #59mediumfoundational
59. Sort Colors
Sort an array of 0s, 1s, and 2s in-place in one pass.
- #60hardfoundational
60. Minimum Window Substring
Find the smallest substring of s that contains every character of t.
- #61mediumfoundational
61. Combinations
Return all combinations of k numbers chosen from 1..n.
- #62mediumfoundational
62. Subsets
Return all subsets of a distinct integer array.
- #63mediumfoundational
63. Word Search
Determine if a word exists in a 2D board by visiting adjacent cells.
- #64mediumfoundational
64. Remove Duplicates from Sorted Array II
Allow each unique element to appear at most twice in a sorted array, in-place.
- #65mediumfoundational
65. Search in Rotated Sorted Array II
Search for a target in a rotated sorted array that may contain duplicates.
- #66mediumfoundational
66. Remove Duplicates from Sorted List II
Delete all nodes that have duplicate numbers from a sorted linked list.
- #67mediumfoundational
67. Partition List
Partition a linked list around a value, preserving relative order.
- #68mediumfoundational
68. Decode Ways
Count the number of ways to decode a digit string into letters A-Z.
- #69mediumfoundational
69. Reverse Linked List II
Reverse a linked list between positions left and right.
- #70mediumfoundational
70. Restore IP Addresses
Generate all valid IP addresses that can be formed from a string of digits.
- #71mediumfoundational
71. Unique Binary Search Trees II
Generate every structurally unique BST that stores values 1..n.
- #72mediumfoundational
72. Unique Binary Search Trees
Count the number of structurally unique BSTs that store values 1..n.
- #73mediumfoundational
73. Validate Binary Search Tree
Determine whether a binary tree is a valid binary search tree.
- #74mediumfoundational
74. Binary Tree Level Order Traversal
Return the level-order traversal of a binary tree.
- #75mediumfoundational
75. Binary Tree Zigzag Level Order Traversal
Return the zigzag level-order traversal of a binary tree.
- #76mediumfoundational
76. Construct Binary Tree from Preorder and Inorder Traversal
Rebuild a binary tree from its preorder and inorder traversals.
- #77mediumfoundational
77. Construct Binary Tree from Inorder and Postorder Traversal
Rebuild a binary tree from its inorder and postorder traversals.
- #78mediumfoundational
78. Binary Tree Level Order Traversal II
Return the bottom-up level-order traversal of a binary tree.
- #79mediumfoundational
79. Convert Sorted List to Binary Search Tree
Convert a sorted linked list into a height-balanced BST.
- #80easyfoundational
80. Path Sum
Decide if any root-to-leaf path of a binary tree sums to a target.
- #81mediumfoundational
81. Best Time to Buy and Sell Stock II
Maximize profit from many buy/sell transactions of a stock.
- #82mediumfoundational
82. Longest Consecutive Sequence
Find the length of the longest consecutive integer sequence in an unsorted array.
- #83mediumfoundational
83. Word Break
Decide if a string can be segmented into dictionary words.
- #84mediumfoundational
84. LRU Cache
Design a data structure that follows the constraints of a Least Recently Used (LRU) cache.
- #85mediumfoundational
85. Maximum Product Subarray
Find the contiguous subarray with the largest product.
- #86mediumfoundational
86. Find Minimum in Rotated Sorted Array
Find the minimum element of a rotated sorted array with distinct values.
- #87mediumfoundational
87. Number of Islands
Count the number of connected '1' islands in a 2D grid.
- #88mediumfoundational
88. Course Schedule
Decide if all courses can be finished given prerequisite pairs (cycle detection).
- #89mediumfoundational
89. Implement Trie (Prefix Tree)
Implement a Trie supporting insert, search, and startsWith.
- #90mediumfoundational
90. Kth Largest Element in an Array
Find the kth largest element in an unsorted array.
- #91easyfoundational
91. Invert Binary Tree
Mirror a binary tree by swapping left and right at every node.
- #92mediumfoundational
92. Lowest Common Ancestor of a Binary Tree
Find the lowest common ancestor of two nodes in a binary tree.
- #93mediumfoundational
93. Product of Array Except Self
Compute an array where each index is the product of all others.
- #94easyfoundational
94. Valid Anagram
Determine whether two strings are anagrams of each other.
- #95hardfoundational
95. Median of Two Sorted Arrays
Find the median of two sorted arrays in O(log(min(m,n))).
- #96hardfoundational
96. Regular Expression Matching
Implement regex matching with '.' and '*'.
- #97hardfoundational
97. Merge k Sorted Lists
Merge k sorted linked lists into one sorted list.
- #98hardfoundational
98. First Missing Positive
Find the smallest missing positive integer in an unsorted array in O(n).
- #99hardfoundational
99. Trapping Rain Water
Compute how much water can be trapped between elevations.
- #100hardfoundational
100. Largest Rectangle in Histogram
Find the area of the largest rectangle in a histogram.