Important Coding Questions for Technical Interview
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.
- Special Numbers
- Count complete tree nodes
- Convert a Ternary expression to a Binary tree structure?
GFG’s Java solution is wrong. C++ solution is correct. - Maximum sum subarray removing at most one element
- Compare Version Numbers
- Repeated Substring Pattern
- Longest Increasing Path in a Matrix
- Binary Search Tree (BST) — Interview Questions & Practice Problems
- Check if given keys represents same BSTs or not without building the BST
- Find distance between two nodes of a Binary Tree
- Sink nodes containing zero to the bottom of a binary tree
- Permutations
- Number of occurrence of maximum grid
- Minimum Number of Platforms Required for a Railway/Bus Station
- Next Permutation
- Longest Common Prefix
- Find size of the largest BST in a Binary Tree
- Consecutive 1’s not allowed
- Decode Ways
- Product of Array Except Self
- Search in Rotated Sorted Array
- Minimum sum partition
- Two City Scheduling
- Minimum Insertion Steps to Make a String Palindrome
- Interleaving String
- Triangle
- Fixing Two nodes of a BST
- Applications of Catalan Numbers
- How to check whether the number is an Integer ?
- In Java, we check if a number is an integer by taking the decimal part
(using % 1) and checking if it is 0. - If floor(number)==ceil(number), it is an integer
- Find Peak Element (See binary search solution)
- Valid Sudoku — — See this solution
- Find three closest elements from given three sorted arrays
- Is Subsequence | Leetcode #392 | Binary search + Map | 2 Pointer
- Union find method to detect cycle in graph.
- Check if two Binary Trees are Isomorphic
- Disjoint Sets using union by rank and path compression Graph Algorithm
- Sum of given range | Segment tree construction and update | Simplest explanation
- Rotate Image
- Add Binary Strings (See Java Answer)
- An Interesting Method to Generate Binary Numbers from 1 to n
- Gas Station
- https://practice.geeksforgeeks.org/tracks/md-tree/?batchId=144
- Lowest Common Ancestor in a Binary Tree | Set 1
Lowest Common Ancestor in a Binary Tree | Set 2 (Using Parent Pointer) - Expression Tree
- Course Schedule
- Word Ladder
- Reverse a stack using recursion : Interview Question: Reverse Stack
- Count number of inversions in array
- https://practice.geeksforgeeks.org/problems/clone-a-linked-list-with-next-and-random-pointer/1/?track=sp-linked-list&batchId=152
- Reverse Bits
- Activity Selection
- Egg Dropping Puzzle (Variation 1) : Solution
- Eggs dropping puzzle | Variation 2 : Solution
- Converting Decimal Number into Roman Numerals
- The Painter’s Partition Problem
- https://practice.geeksforgeeks.org/problems/allocate-minimum-number-of-pages0937/1/?track=dp-divide-and-conquer&batchId=152
- Exponents of large numbers
- Print all subarrays with 0 sum
- Maximum Path Sum in a Binary Tree
- Populating Next Right Pointers in Each Node — — 1 &&&& each-node-2
- N-Queens
- Reverse a Linked List in groups of given size | Set 1
- Flattening a Linked List
- The Stock Span Problem
- Morris Inorder Tree Traversal
- First Missing Positive
- Median of Two Sorted Arrays
- Sort a nearly sorted (or K sorted) array
- Sliding Window Maximum (Maximum of all subarrays of size k)
- Find median in a stream
- Delete Nodes And Return Forest
- Find the Missing Number
- Find K Closest Elements : See solution
- Box Stacking
- Hamming Distance
- Word Break
- Next larger element
- Rearrange characters in a string such that no two adjacent are same
- Merge k Sorted Lists
- Sequences of given length where every element is more than or equal to twice of previous
- Modular Exponentiation (Power in Modular Arithmetic)
- Linked List Cycle and detect starting point of the cycle
- Rectangle Overlap : Check Comments for the solution
- Sorting elements by frequency
- Lowest Common Ancestor in a Binary Tree | Set 2 (Using Parent Pointer)
- Find n-th node of inorder traversal
- Google | Phone | Find K-th node in inorder traversal
- Wiggle Sort II
- Maximal Square O(n)
- Wave Array : Check out O(n) solution
- Count Primes : How is the time complexity of Sieve of Eratosthenes is n*log(log(n))?
https://www.youtube.com/watch?v=pKvGYOnO9Ao - Possible Bipartition : Solution
- Add Digits : See Solution
- Edit Distance
- Longest palindromic substring | Dynamic programming
- How to calculate Catalan Number | Find Nth catalan number in most efficient ways (3 methods)
- Two City Scheduling : https://leetcode.com/problems/two-city-scheduling/discuss/280173/Java-4-lines-intuitive-solution
- All Nodes Distance K in Binary Tree
- Kth Smallest Element in a BST : See follow up in solution
- Reverse Words in a String : Solution
- Check If It Is a Straight Line
- Find the Duplicate Number : See Solution → (Video Solution)
- How to solve DP — String? Template and 4 Steps to be followed. Dynamic Programming Patterns
- DP for Beginners [Problems | Patterns | Sample Solutions]
- Graph Problems For Beginners Practice [Problems and Sample Solutions]
- Sliding Window for Beginners [Problems | Template | Sample Solutions]
- Important and Useful links from all over the Leetcode
- K Closest Points to Origin
- Counting Bits
- Longest array with equal number of zeros and ones
- Rotting Oranges — Solution (O(n)) | Solution (O(n3))
- Number of Islands
- Difference between sums of odd level and even level nodes of a Binary Tree
- Integer to English Words
- Converting Decimal Number lying between 1 to 3999 to Roman Numerals
- Check Completeness of a Binary Tree
- Deepest Leaves Sum
- Maximum Depth of N-ary Tree
- Stone Game : See its solution (Method 2)
- Coin Change
- Unique Binary Search Trees
- Count of Smaller Numbers After Self
- Majority Element
- Single Number II : Solution
- https://www.youtube.com/watch?v=BXCEFAzhxGY&t=90s
- Symmetric Tree
- Remove Duplicates from Sorted List II
- Largest Rectangular Area in a Histogram | Set 2
- A program to check if a binary tree is BST or not
- Construct BST from given preorder traversal
- Partition Equal Subset Sum
- Remove K Digits : Keep all edge cases in mind (There are many edge cases)
- Shortest Unsorted Continuous Subarray
- Must do Math for Competitive Programming
- Sort an array of 0s, 1s and 2s (Dutch National Flag Algorithm)
- BigInteger Class in Java
- Print nodes at K distance from root
- Container With Most Water
- Print unique rows in a given boolean matrix
- Search a 2D Matrix
- Odd Even Linked List
- Unique Binary Search Trees
- https://leetcode.com/problems/insert-delete-getrandom-o1/
- Word Search 1 & 2 [GRAPH]
- Additive Number [DFS]
- Unique ways to make a change from coins : See Reduced Complexity Solution
- House Robber [Dynamic Programming]
- Cutting Binary String (GFG) [Dynamic Programming]
- 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. - Jump Game [Different type of DP]
- Optimal Strategy for a Game | DP-31
- Josephus Problem (Recursion, By Pattern)
- Subsets
- Print all possible words from phone digits
- Java Binary Search O(lgN) : clear, easy, explained, no tricks
- Sort Characters By Frequency
- Stock buy and sell
- Top K Frequent Words
- Lowest common ancestor in Binary Tree
- Pairwise Swap leaf nodes in a binary tree
- Swap Nodes in Pairs
- Broken Calculator
- Subarray Sum Equals K
- Add Two Numbers II
- 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
- Remove Nth Node From End of List
- Top K Frequent Elements : https://leetcode.com/problems/top-k-frequent-elements/
- Group Anagrams
- Kth Ancestor of a Tree Node
- A program to check if a binary tree is BST or not
- Binary Search Tree | Set 2 (Delete)
- Maximum Width of Binary Tree
- Extract Leaves of a Binary Tree in a Doubly Linked List
- https://practice.geeksforgeeks.org/problems/kth-smallest-element/
- Merge two sorted arrays with O(1) extra space
- Replace Words
- Merge Intervals
- Elimination Game
- Search a 2D Matrix II
- Diagonal Traversal of a matrix
- Minimum Number of Platforms Required for a Railway/Bus Station
- Trapping Rain Water Also see space efficient solution : https://www.geeksforgeeks.org/trapping-rain-water/
- Median of Two Sorted Arrays
- Noble Integer (See the use of keyword continue in its solution) : Noble Integer
- Maximum Product Subarray
- My Calendar
- Largest Number
- Number of 1 Bits
- Program to find whether a number is power of two
- Minimum number of jumps to reach end
- Flatten a Multilevel Doubly Linked List
- Count number of bits to be flipped to convert A to B
- Count Number of SubTrees having given Sum
- Minimum XOR Value Pair
- Equal
- Max Distance
- K’th smallest element in BST using O(1) Extra Space
- 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)
- Jump Game — — Youtube Video Solution
- Jump Game II
- Multiply Strings
- Zig-Zag traversal of Binary tree
- Diagonal Traversal of Binary Tree
- Vertical order traversal of binary tree — O(n) time
- Level Order Binary Tree && N-ary Tree Traversal
- PreOrder (log(n), log(h)), PostOrder(1 stack, 2 stacks), InOrder (Recursive and iterative)
- Boundary Traversal of binary tree
- Bottom view of binary tree — O(n) time
- Top View of Binary Tree — O(n) time
- Left View of Binary Tree — O(n) time {Recursive and Iterative}
- Right View of Binary Tree — O(n) time {Recursive and Iterative}
- Detect Cycle in Undirected Graph
- 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