Important Coding Questions for Technical Interview

Anmol Jain
7 min readJun 5, 2021

--

So, I’ve been coding for my placement preparations from my B.E. days on many websites. I prepared a list of the coding questions which I found important.

  1. Special Numbers
  2. Count complete tree nodes
  3. Convert a Ternary expression to a Binary tree structure?
    GFG’s Java solution is wrong. C++ solution is correct.
  4. Maximum sum subarray removing at most one element
  5. Compare Version Numbers
  6. Repeated Substring Pattern
  7. Longest Increasing Path in a Matrix
  8. Binary Search Tree (BST) — Interview Questions & Practice Problems
  9. Check if given keys represents same BSTs or not without building the BST
  10. Find distance between two nodes of a Binary Tree
  11. Sink nodes containing zero to the bottom of a binary tree
  12. Permutations
  13. Number of occurrence of maximum grid
  14. Minimum Number of Platforms Required for a Railway/Bus Station
  15. Next Permutation
  16. Longest Common Prefix
  17. Find size of the largest BST in a Binary Tree
  18. Consecutive 1’s not allowed
  19. Decode Ways
  20. Product of Array Except Self
  21. Search in Rotated Sorted Array
  22. Minimum sum partition
  23. Two City Scheduling
  24. Minimum Insertion Steps to Make a String Palindrome
  25. Interleaving String
  26. Triangle
  27. Fixing Two nodes of a BST
  28. Applications of Catalan Numbers
  29. How to check whether the number is an Integer ?
  30. In Java, we check if a number is an integer by taking the decimal part
    (using % 1) and checking if it is 0.
  31. If floor(number)==ceil(number), it is an integer
  32. Find Peak Element (See binary search solution)
  33. Valid Sudoku — — See this solution
  34. Find three closest elements from given three sorted arrays
  35. Is Subsequence | Leetcode #392 | Binary search + Map | 2 Pointer
  36. Union find method to detect cycle in graph.
  37. Check if two Binary Trees are Isomorphic
  38. Disjoint Sets using union by rank and path compression Graph Algorithm
  39. Sum of given range | Segment tree construction and update | Simplest explanation
  40. Rotate Image
  41. Add Binary Strings (See Java Answer)
  42. An Interesting Method to Generate Binary Numbers from 1 to n
  43. Gas Station
  44. https://practice.geeksforgeeks.org/tracks/md-tree/?batchId=144
  45. Lowest Common Ancestor in a Binary Tree | Set 1
    Lowest Common Ancestor in a Binary Tree | Set 2 (Using Parent Pointer)
  46. Expression Tree
  47. Course Schedule
  48. Word Ladder
  49. Reverse a stack using recursion : Interview Question: Reverse Stack
  50. Count number of inversions in array
  51. https://practice.geeksforgeeks.org/problems/clone-a-linked-list-with-next-and-random-pointer/1/?track=sp-linked-list&batchId=152
  52. Reverse Bits
  53. Activity Selection
  54. Egg Dropping Puzzle (Variation 1) : Solution
  55. Eggs dropping puzzle | Variation 2 : Solution
  56. Converting Decimal Number into Roman Numerals
  57. The Painter’s Partition Problem
  58. https://practice.geeksforgeeks.org/problems/allocate-minimum-number-of-pages0937/1/?track=dp-divide-and-conquer&batchId=152
  59. Exponents of large numbers
  60. Print all subarrays with 0 sum
  61. Maximum Path Sum in a Binary Tree
  62. Populating Next Right Pointers in Each Node — — 1 &&&& each-node-2
  63. N-Queens
  64. Reverse a Linked List in groups of given size | Set 1
  65. Flattening a Linked List
  66. The Stock Span Problem
  67. Morris Inorder Tree Traversal
  68. First Missing Positive
  69. Median of Two Sorted Arrays
  70. Sort a nearly sorted (or K sorted) array
  71. Sliding Window Maximum (Maximum of all subarrays of size k)
  72. Find median in a stream
  73. Delete Nodes And Return Forest
  74. Find the Missing Number
  75. Find K Closest Elements : See solution
  76. Box Stacking
  77. Hamming Distance
  78. Word Break
  79. Next larger element
  80. Rearrange characters in a string such that no two adjacent are same
  81. Merge k Sorted Lists
  82. Sequences of given length where every element is more than or equal to twice of previous
  83. Modular Exponentiation (Power in Modular Arithmetic)
  84. Linked List Cycle and detect starting point of the cycle
  85. Rectangle Overlap : Check Comments for the solution
  86. Sorting elements by frequency
  87. Lowest Common Ancestor in a Binary Tree | Set 2 (Using Parent Pointer)
  88. Find n-th node of inorder traversal
  89. Google | Phone | Find K-th node in inorder traversal
  90. Wiggle Sort II
  91. Maximal Square O(n)
  92. Wave Array : Check out O(n) solution
  93. Count Primes : How is the time complexity of Sieve of Eratosthenes is n*log(log(n))?
    https://www.youtube.com/watch?v=pKvGYOnO9Ao
  94. Possible Bipartition : Solution
  95. Add Digits : See Solution
  96. Edit Distance
  97. Longest palindromic substring | Dynamic programming
  98. How to calculate Catalan Number | Find Nth catalan number in most efficient ways (3 methods)
  99. Two City Scheduling : https://leetcode.com/problems/two-city-scheduling/discuss/280173/Java-4-lines-intuitive-solution
  100. All Nodes Distance K in Binary Tree
  101. Kth Smallest Element in a BST : See follow up in solution
  102. Reverse Words in a String : Solution
  103. Check If It Is a Straight Line
  104. Find the Duplicate Number : See Solution(Video Solution)
  105. How to solve DP — String? Template and 4 Steps to be followed. Dynamic Programming Patterns
  106. DP for Beginners [Problems | Patterns | Sample Solutions]
  107. Graph Problems For Beginners Practice [Problems and Sample Solutions]
  108. Sliding Window for Beginners [Problems | Template | Sample Solutions]
  109. Important and Useful links from all over the Leetcode
  110. K Closest Points to Origin
  111. Counting Bits
  112. Longest array with equal number of zeros and ones
  113. Rotting OrangesSolution (O(n)) | Solution (O(n3))
  114. Number of Islands
  115. Difference between sums of odd level and even level nodes of a Binary Tree
  116. Integer to English Words
  117. Converting Decimal Number lying between 1 to 3999 to Roman Numerals
  118. Check Completeness of a Binary Tree
  119. Deepest Leaves Sum
  120. Maximum Depth of N-ary Tree
  121. Stone Game : See its solution (Method 2)
  122. Coin Change
  123. Unique Binary Search Trees
  124. Count of Smaller Numbers After Self
  125. Majority Element
  126. Single Number II : Solution
  127. https://www.youtube.com/watch?v=BXCEFAzhxGY&t=90s
  128. Symmetric Tree
  129. Remove Duplicates from Sorted List II
  130. Largest Rectangular Area in a Histogram | Set 2
  131. A program to check if a binary tree is BST or not
  132. Construct BST from given preorder traversal
  133. Partition Equal Subset Sum
  134. Remove K Digits : Keep all edge cases in mind (There are many edge cases)
  135. Shortest Unsorted Continuous Subarray
  136. Must do Math for Competitive Programming
  137. Sort an array of 0s, 1s and 2s (Dutch National Flag Algorithm)
  138. BigInteger Class in Java
  139. Print nodes at K distance from root
  140. Container With Most Water
  141. Print unique rows in a given boolean matrix
  142. Search a 2D Matrix
  143. Odd Even Linked List
  144. Unique Binary Search Trees
  145. https://leetcode.com/problems/insert-delete-getrandom-o1/
  146. Word Search 1 & 2 [GRAPH]
  147. Additive Number [DFS]
  148. Unique ways to make a change from coins : See Reduced Complexity Solution
  149. House Robber [Dynamic Programming]
  150. Cutting Binary String (GFG) [Dynamic Programming]
  151. Maximum Product Cutting [GFG]
    A Tricky Solution: If we see some examples of these problems, we can easily observe the following pattern. The maximum product can be obtained by repeatedly cutting parts of size 3 while size is greater than 4, keeping the last part as size of 2 or 3 or 4. For example, n = 10, the maximum product is obtained by 3, 3, 4. For n = 11, the maximum product is obtained by 3, 3, 3, 2.
  152. Jump Game [Different type of DP]
  153. Optimal Strategy for a Game | DP-31
  154. Josephus Problem (Recursion, By Pattern)
  155. Subsets
  156. Print all possible words from phone digits
  157. Java Binary Search O(lgN) : clear, easy, explained, no tricks
  158. Sort Characters By Frequency
  159. Stock buy and sell
  160. Top K Frequent Words
  161. Lowest common ancestor in Binary Tree
  162. Pairwise Swap leaf nodes in a binary tree
  163. Swap Nodes in Pairs
  164. Broken Calculator
  165. Subarray Sum Equals K
  166. Add Two Numbers II
  167. Preimage Size of Factorial Zeroes Function https://leetcode.com/problems/preimage-size-of-factorial-zeroes-function/discuss/117821/Four-binary-search-solutions-based-on-different-ideas
  168. Remove Nth Node From End of List
  169. Top K Frequent Elements : https://leetcode.com/problems/top-k-frequent-elements/
  170. Group Anagrams
  171. Kth Ancestor of a Tree Node
  172. A program to check if a binary tree is BST or not
  173. Binary Search Tree | Set 2 (Delete)
  174. Maximum Width of Binary Tree
  175. Extract Leaves of a Binary Tree in a Doubly Linked List
  176. https://practice.geeksforgeeks.org/problems/kth-smallest-element/
  177. Merge two sorted arrays with O(1) extra space
  178. Replace Words
  179. Merge Intervals
  180. Elimination Game
  181. Search a 2D Matrix II
  182. Diagonal Traversal of a matrix
  183. Minimum Number of Platforms Required for a Railway/Bus Station
  184. Trapping Rain Water Also see space efficient solution : https://www.geeksforgeeks.org/trapping-rain-water/
  185. Median of Two Sorted Arrays
  186. Noble Integer (See the use of keyword continue in its solution) : Noble Integer
  187. Maximum Product Subarray
  188. My Calendar
  189. Largest Number
  190. Number of 1 Bits
  191. Program to find whether a number is power of two
  192. Minimum number of jumps to reach end
  193. Flatten a Multilevel Doubly Linked List
  194. Count number of bits to be flipped to convert A to B
  195. Count Number of SubTrees having given Sum
  196. Minimum XOR Value Pair
  197. Equal
  198. Max Distance
  199. K’th smallest element in BST using O(1) Extra Space
  200. K’th Smallest/Largest Element in Unsorted Array | Set 2 (Expected Linear Time) K’th Smallest/Largest Element in Unsorted Array | Set 3 (Worst Case Linear Time)
  201. Jump Game — — Youtube Video Solution
  202. Jump Game II
  203. Multiply Strings
  204. Zig-Zag traversal of Binary tree
  205. Diagonal Traversal of Binary Tree
  206. Vertical order traversal of binary tree — O(n) time
  207. Level Order Binary Tree && N-ary Tree Traversal
  208. PreOrder (log(n), log(h)), PostOrder(1 stack, 2 stacks), InOrder (Recursive and iterative)
  209. Boundary Traversal of binary tree
  210. Bottom view of binary tree — O(n) time
  211. Top View of Binary Tree — O(n) time
  212. Left View of Binary Tree — O(n) time {Recursive and Iterative}
  213. Right View of Binary Tree — O(n) time {Recursive and Iterative}
  214. Detect Cycle in Undirected Graph
  215. Topological sort

These Documents will contain the placement information about all the companies visiting IITs, NITs, IIITs, and BITS.

Placement 2019: https://goo.gl/tn7mRx

Interview exp 2019: https://goo.gl/vpdNNG

Placement 2018: https://goo.gl/FNziKM

Placement 2017: https://goo.gl/Xs3LdG

Placement 2016: https://goo.gl/NJXvVU

Placement 2016: https://goo.gl/yDRnCF

--

--

Anmol Jain
Anmol Jain

No responses yet