100+ Essential Coding Interview Questions to Ace Your Next Tech Interview [Updated]

Coding Interview Questions

Feeling Stressed About Coding Interviews? Youโ€™re Not Alone!

Letโ€™s be realโ€”coding interview questions can be nerve-wracking. The pressure, the whiteboard coding, the algorithm-heavy challengesโ€ฆitโ€™s enough to make anyone break a sweat. Iโ€™ve been there. You spend weeks grinding LeetCode, watching YouTube tutorials, and still feel unprepared when the big day arrives. Sound familiar?

Thatโ€™s exactly why I created this ultimate list of 100+ essential coding interview questionsโ€”so you donโ€™t waste time on random problems that might not even matter. These common coding interview questions cover everything: arrays, linked lists, trees, dynamic programming, and even system designโ€”everything tech companies love to ask.

Whether youโ€™re a seasoned candidate or just starting out, these coding interview questions for freshers will help you build a strong foundation and develop confidence.

Letโ€™s dive in and take the stress out of your prep.

100+ Essential Coding Interview Questions

Coding Interview Questions
100+ Essential Coding Interview Questions

Array-Based Coding Interview Questions for Freshers

  1. How do you find the missing number in an array from 1 to n? Use the formula sum = n*(n+1)/2. Subtract actual array sum from it to get the missing number. Time complexity is O(n).
  2. How do you find the duplicate number in an array? Use Floydโ€™s Tortoise and Hare (Cycle Detection) algorithm for efficient results. Time complexity is O(n), space O(1).
  3. How do you rotate an array by k positions? Reverse the whole array, reverse first k and then reverse the rest. Time complexity is O(n), space O(1).
  4. How do you find the maximum subarray sum? Use Kadaneโ€™s Algorithm. Maintain a current max and update global max accordingly.
  5. How do you merge two sorted arrays? Use two pointers to merge them into a third array. Time complexity is O(n + m).
  6. Find the intersection of two arrays. Use a HashSet to store one array, then check the second. Time complexity is O(n).
  7. How do you sort an array of 0s, 1s, and 2s? Use the Dutch National Flag algorithm. It runs in O(n) time.
  8. Find the leader elements in an array. Traverse from the right, track max so far. Elements greater than all to their right are leaders.
  9. How do you find the majority element in an array? Use Moore’s Voting Algorithm. Time complexity O(n), space O(1).
  10. How do you rearrange array elements in alternating positive and negative items? Partition the array, then swap alternately. Time complexity is O(n).

String-Based Coding Interview Questions for Freshers

  1. Check if a string is a palindrome. Use two pointers from start and end. Compare characters until middle.
  2. Find the first non-repeating character in a string. Use a frequency counter, then iterate again to find the first. Time complexity is O(n).
  3. Reverse a string without affecting special characters. Use two-pointer technique while skipping non-alphabetic. Swap only letters.
  4. Check if two strings are anagrams. Sort and compare or use frequency arrays. Time complexity is O(n log n) or O(n).
  5. Implement strstr (substring search). Use the KMP algorithm for efficient matching. Time complexity is O(n + m).
  6. Find the longest common prefix. Sort and compare first and last strings. Check character by character.
  7. Find the longest palindrome substring. Use dynamic programming or center expansion. Time complexity is O(n^2).
  8. How do you compress a string (aabcc becomes a2b1c2)? Iterate and count consecutive characters. Concatenate character and count.
  9. Check if string has all unique characters. Use a set or boolean array. Time complexity is O(n).
  10. Remove duplicate characters in a string. Use a set to track seen characters. Build a new string skipping duplicates.

Linked List Coding Interview Questions for Freshers

  1. Detect a loop in a linked list. Use Floydโ€™s cycle detection algorithm. Tortoise and hare pointer method.
  2. Find the middle element of a linked list. Use slow and fast pointer. Slow will be at middle when fast reaches end.
  3. Reverse a linked list. Iteratively change next pointers. Use three pointers: prev, curr, next.
  4. Check if a linked list is a palindrome. Find middle, reverse second half, compare halves. Time complexity is O(n).
  5. Merge two sorted linked lists. Use a dummy node and iterate. Compare node values and attach accordingly.

Tree-Based Coding Interview Questions for Freshers

  1. What is the height of a binary tree? Recursively find the height of left and right subtrees. Return max height + 1.
  2. Check if two trees are identical. Recursively check if both roots, left, and right match. Base case is when both nodes are null.
  3. Print in-order traversal of a binary tree. Use recursion: Left -> Root -> Right. You can also use a stack for iterative approach.
  4. Check if a binary tree is a BST. Use recursion with valid range limits. Ensure left < root < right.
  5. Find lowest common ancestor in BST. Use recursion based on value comparison. If root lies between two nodes, it’s LCA.

Recursion-Based Coding Interview Questions for Freshers

  1. Find factorial using recursion. Base case is 1. Return n * factorial(n-1). Time complexity is O(n).
  2. Generate Fibonacci series using recursion. Return fib(n-1) + fib(n-2) with base cases. Inefficient; better with memoization.
  3. Reverse a string using recursion. Base case is empty string. Return reverse(substring) + first character.
  4. Check if a number is a power of 2. Recursively divide by 2 and check if equals 1. Base case is 1.
  5. Find GCD using recursion. Use Euclidean algorithm: gcd(a, b) = gcd(b, a % b). Base case is when b == 0.

Sorting and Searching Coding Interview Questions for Freshers

  1. Implement binary search. Compare mid element with target. Use divide-and-conquer on sorted array.
  2. Implement bubble sort. Swap adjacent elements if out of order. Time complexity is O(n^2).
  3. Implement insertion sort. Insert elements in sorted position one by one. Best case O(n), worst case O(n^2).
  4. Implement quick sort. Choose pivot, partition array, and sort recursively. Average case is O(n log n).
  5. Implement merge sort. Divide array into halves, sort and merge them. Time complexity is O(n log n).

Graph-Based Coding Interview Questions for Freshers

  1. Implement depth-first search (DFS). Use stack or recursion to visit nodes. Mark nodes as visited to avoid cycles.
  2. Implement breadth-first search (BFS). Use queue to explore neighbors layer by layer. Track visited nodes to prevent repetition.
  3. Detect a cycle in an undirected graph. Use DFS and track parent of each node. Cycle exists if a visited node is not parent.
  4. Detect a cycle in a directed graph. Use DFS with recursion stack. Back edge indicates a cycle.
  5. Topological sort of a DAG. Use DFS or Kahnโ€™s Algorithm. Order tasks with no cyclic dependencies.

Stack and Queue Coding Interview Questions for Freshers

  1. Implement a stack using two queues. Push to one queue, pop by transferring to other. Maintain latest element at front.
  2. Implement a queue using two stacks. Push to one stack, pop by reversing to other. Use amortized O(1) operations.
  3. Check for balanced parentheses. Use stack to track opening brackets. Match with closing ones.
  4. Evaluate a postfix expression. Use stack to store operands. Apply operators as encountered.
  5. Implement LRU cache. Use HashMap and Doubly Linked List. Maintain order of usage.

Dynamic Programming Coding Interview Questions for Freshers

  1. Find nth Fibonacci number using DP. Use memoization or bottom-up approach. Time complexity is O(n).
  2. 0/1 Knapsack Problem. Use DP table to choose max value within capacity. Time complexity is O(nW).
  3. Longest common subsequence. Fill DP table based on character match. Result is in last cell.
  4. Longest increasing subsequence. Use DP to track increasing order. Update max for each element.
  5. Minimum edit distance between two strings. Use DP to calculate insert, delete, replace. Choose min of all operations.

Object-Oriented Programming Coding Interview Questions for Freshers

  1. What is encapsulation in OOP? Binding data and methods together. Achieved using classes and access modifiers.
  2. What is inheritance in OOP? One class acquires properties of another. Supports code reusability.
  3. What is polymorphism in OOP? Same function behaves differently in contexts. Overloading and overriding are types.
  4. What is abstraction in OOP? Hides internal details, shows essential features. Done using abstract classes or interfaces.
  5. Difference between interface and abstract class? Interfaces have only abstract methods (till Java 7). Abstract class can have concrete methods too.

Bit Manipulation Coding Interview Questions

  1. Check if a number is a power of two.
    Use n & (n – 1) to check. If result is 0 and n > 0, it’s a power of two.
  2. Count set bits in an integer.
    Use Brian Kernighanโ€™s algorithm. Subtract 1 and AND it with the original number until 0.
  3. Find the only non-repeating element.
    Use XOR across all numbers. Duplicate elements cancel out.
  4. Add two numbers without using ‘+’ operator.
    Use bitwise XOR for addition and AND + shift for carry. Repeat until carry is zero.
  5. Swap two numbers using bitwise operators.
    Use XOR: a = a ^ b, b = a ^ b, a = a ^ b.
  6. Find position of rightmost set bit.
    Use n & -n. This isolates the rightmost set bit in binary.

Greedy Algorithm Coding Interview Questions

  1. Activity selection problem.
    Sort by end time and choose non-overlapping intervals. Maximizes task completion.
  2. Minimum number of platforms required for trains.
    Sort arrival and departure separately, and simulate overlapping.
  3. Fractional Knapsack Problem.
    Sort by value/weight ratio. Take max possible items greedily.
  4. Job Sequencing Problem.
    Sort by profit and fill time slots greedily to maximize gain.
  5. Huffman Coding.
    Use priority queue to build optimal prefix tree for encoding.
  6. Minimum number of coins.
    Use highest denomination coins first (greedy) to reach the total amount.

Math and Logic Puzzle Coding Interview Questions

  1. Check if a number is prime.
    Check divisibility from 2 to โˆšn. Return false if divisible.
  2. Find GCD of two numbers.
    Use Euclidean algorithm: gcd(a, b) = gcd(b, a % b).
  3. Check if a number is palindrome.
    Reverse the number and compare with original.
  4. Find square root without library.
    Use binary search between 1 and n.
  5. Check if number is an Armstrong number.
    Sum of each digit raised to power of total digits equals number.
  6. FizzBuzz problem.
    Print “Fizz” for multiples of 3, “Buzz” for 5, and “FizzBuzz” for both.

Common Coding Interview Questions

  1. Reverse an integer.
    Extract digits and construct reversed number. Handle overflows.
  2. Convert integer to Roman numeral.
    Map integer values to Roman symbols. Greedily subtract values.
  3. Convert Roman numeral to integer.
    Add or subtract values based on symbol position.
  4. Excel sheet column number to title.
    Convert to base-26 and map to alphabet.
  5. Find majority element.
    Use Boyer-Moore voting algorithm for O(n) time.
  6. Find longest common prefix among strings.
    Use horizontal scanning or sort then compare first & last.
  7. Implement atoi function.
    Trim spaces, handle signs, and parse numbers character by character.
  8. Implement strstr function.
    Use two pointers or KMP algorithm for substring search.
  9. Implement pow(x, n).
    Use recursion or iterative fast exponentiation with log(n) complexity.
  10. Find missing number in 0 to n.
    Sum from 0 to n minus sum of array gives missing number.
  11. Find duplicate number in array.
    Use Floydโ€™s cycle detection algorithm or visited index marking.
  12. Detect cycle in an array.
    Floyd’s cycle detection technique using slow and fast pointers.
  13. Find kth largest element.
    Use heap or quickselect for average O(n) time.
  14. Longest consecutive sequence.
    Use HashSet and check sequence starts with n-1 not existing.
  15. Count primes less than n.
    Use Sieve of Eratosthenes for efficient counting.
  16. Valid Parentheses.
    Use stack to push on opening and pop on matching closing.
  17. Group Anagrams.
    Sort each string or use character frequency map as key in HashMap.
  18. Top K Frequent Elements.
    Use HashMap for count and Min Heap or Bucket Sort to find top k.
  19. Isomorphic Strings.
    Map characters from s to t and ensure consistent mapping.
  20. Minimum Window Substring.
    Use sliding window with frequency count comparison.
  21. Decode Ways.
    Use DP: ways[i] = ways[i-1] + ways[i-2] depending on digits.
  22. Find First and Last Position of Element in Sorted Array.
    Use binary search twice for left and right bounds.
  23. Search in Rotated Sorted Array.
    Use modified binary search with pivot consideration.
  24. Median of Two Sorted Arrays.
    Use binary search partitioning technique. Complex but optimal.
  25. Wildcard Matching.
    Use DP or greedy two-pointer technique with backtracking.
  26. Regular Expression Matching.
    Use recursion or DP to match ‘.’ and ‘*’ patterns.
  27. Implement LRU Cache.
    Use HashMap with Doubly Linked List for O(1) operations.
  28. Serialize and Deserialize Binary Tree.
    Use BFS or DFS with delimiters for nulls.
  29. Sliding Window Maximum.
    Use deque to maintain decreasing order of values within window.
  30. Trapping Rain Water.
    Use two-pointer technique or precompute left/right max arrays.
  31. Word Ladder.
    Use BFS to transform word by changing one letter at a time.
  32. Alien Dictionary (Topological Sort).
    Build graph from character orders and apply Kahnโ€™s algorithm.
Previous Article

Mastering if-else-if in JavaScript: A Beginner's Guide with Real-World Examples ๐Ÿš€

Next Article

How to Check if a File Exists in Python (With Easy Examples)

Write a Comment

Leave a Comment

Your email address will not be published. Required fields are marked *

Subscribe to our Newsletter

Subscribe to our email newsletter to get the latest posts delivered right to your email.
Pure inspiration, zero spam โœจ