Top 80 Coding Interview Questions (2026)

Practice the most frequently asked Coding interview questions. Each question includes expert tips, sample answers, and AI-powered practice.

29 Easy
45 Medium
6 Hard
Updated July 2026
01

How do you implement binary search on a sorted array?

Binary search is a fundamental algorithm that tests your grasp of divide-and-conquer strategies and index manipulation. Interviewers use it to check if you understand time complexity constraints (O(log n)) and edge cases like empty arrays or elements not present. It also evaluates your coding style, including loop conditions and boundary handling, which are critical for avoiding infinite loops or off-by-one errors.

Easy
Microsoft
02

What is Object-Oriented Programming in Java and its key features?

Java is widely used at Google, so understanding OOP is essential for writing clean, maintainable code. Interviewers want to ensure you can leverage these principles to create modular and extensible software architectures. It also reveals your ability to think in terms of objects and relationships.

Easy
Google
03

What is Object-Oriented Programming in Java and why is it important?

This question checks your fundamental understanding of Java, a language widely used at Google. Interviewers want to ensure you can leverage OOP principles like encapsulation, inheritance, and polymorphism to write clean, maintainable code. It also tests your ability to explain technical concepts clearly to non-experts or peers.

Easy
Google
04

What is the binary representation of a given integer?

This question tests understanding of binary systems and bitwise operations. Interviewers want to see if candidates know how to perform manual conversion or use built-in functions effectively. It also checks handling of negative numbers and leading zeros.

Easy
Infosys
05

How do you check if an array is sorted in code?

Interviewers ask this to verify that candidates understand fundamental array traversal and comparison operations. They want to see if you can handle edge cases like empty arrays or single elements. Additionally, it assesses your ability to write clean, readable code with optimal time complexity for simple tasks.

Easy
Infosys
06

What is the difference between value type and reference type?

Understanding value vs. reference types is crucial for preventing bugs related to mutation and memory leaks. Interviewers ask this to assess your grasp of language fundamentals. It reveals how you manage state and pass data between functions or classes.

Easy
TCS
07

How do you perform binary search on a sorted array efficiently?

Binary search is a foundational algorithm used extensively in production code for searching and sorting operations. Interviewers ask this to verify that the candidate understands the prerequisites for binary search, such as the necessity of a sorted array. They are also testing the candidate's ability to write clean, bug-free iterative or recursive code without off-by-one errors, which are common in this specific algorithm.

Easy
Goldman Sachs
08

How do you check if an array is sorted in a coding interview?

Interviewers ask this to assess fundamental programming skills and the ability to write clean, efficient code quickly. They want to see if the candidate understands how to traverse data structures and implement logical conditions correctly. This problem serves as a baseline to evaluate attention to edge cases, such as empty arrays or single-element inputs, which often trip up junior developers.

Easy
Infosys
09

Can you explain how to generate Fibonacci numbers iteratively?

This classic problem checks if candidates know how to avoid the exponential time complexity of naive recursion. Interviewers want to see optimization skills and the ability to manage state variables effectively. It also reveals their grasp of dynamic programming concepts even at a basic level.

Easy
Infosys
10

How do you implement binary search on a sorted array?

Binary search is a classic algorithm that demonstrates efficiency and logical thinking. Interviewers use it to verify if you can handle boundary conditions and loop invariants correctly. It also tests your knowledge of O(log n) complexity versus O(n) linear search.

Easy
Microsoft Corporation
11

What is Kadane's Algorithm and how does it work?

Kadane's Algorithm is a staple interview question because it elegantly demonstrates the power of dynamic programming. Interviewers want to verify if you can identify overlapping subproblems and make locally optimal choices that lead to a global optimum. It also checks your ability to implement the solution concisely and correctly handle all-negative number arrays.

Easy
Microsoft
12

How do you implement binary search to find a target in a sorted array?

Binary search is a foundational concept for financial trading systems and large datasets. Interviewers ask this to ensure you understand how to reduce search space exponentially. They evaluate your coding precision, especially regarding boundary conditions and index calculations that often lead to off-by-one errors in production code.

Easy
Goldman Sachs
13

How do you perform binary search on a sorted array to find a target index?

This is a classic test of basic algorithmic knowledge and implementation precision. Interviewers want to see if the candidate understands the prerequisites for binary search, such as the requirement for a sorted array. It also evaluates their ability to handle boundary conditions correctly, avoid infinite loops, and achieve the optimal logarithmic time complexity.

Easy
Goldman Sachs
14

What is the best way to sort characters in a string alphabetically?

This question checks basic sorting knowledge and the ability to apply it to strings. Interviewers want to see if the candidate knows standard sorting algorithms like QuickSort or MergeSort, or if they rely on built-in functions appropriately. It also tests understanding of time complexity.

Easy
Infosys
15

How do you reverse words in a given string?

It serves as a warm-up to check coding fluency and attention to detail. Interviewers assess how you handle whitespace and word boundaries. It also reveals your ability to choose between built-in functions and manual implementation.

Easy
Goldman Sachs
16

How would you solve the Two Sum problem with optimal performance?

The Two Sum problem is frequently asked because it effectively tests a candidate's ability to trade space for time. It distinguishes between brute-force thinking and optimized approaches using hash maps. Interviewers want to see if you can identify patterns and utilize data structures to reduce complexity from quadratic to linear. It also serves as a gateway to more complex array and hashing problems in later rounds.

Easy
Infosys
17

How do you search for a target in a sorted array efficiently?

This question assesses whether a candidate knows the most efficient algorithm for searching sorted data. Binary search is fundamental in computer science, reducing search time from linear to logarithmic. Interviewers want to verify that the candidate understands the prerequisites (sorted input) and can implement the divide-and-conquer strategy correctly. It also checks attention to detail regarding off-by-one errors and boundary conditions which are common pitfalls in binary search implementations.

Easy
Goldman Sachs
18

How do you implement binary search on a sorted array efficiently?

Binary search is a classic algorithm that demonstrates a candidate's ability to optimize search operations from linear to logarithmic time. Interviewers look for clean implementation, correct boundary conditions, and the ability to handle cases where the element is not present. It also tests basic proficiency in array manipulation and loop control.

Easy
Microsoft Corporation
19

What is Object-Oriented Programming in Java and why is it used?

Java is widely used at Google. This question checks if you grasp core OOP concepts like encapsulation, inheritance, polymorphism, and abstraction. Interviewers look for clear explanations and practical examples of how these principles improve code maintainability and scalability.

Easy
Google
20

How do you merge two sorted linked lists into one sorted list?

Interviewers ask this to verify your comfort with pointer manipulation and iterative merging techniques. It is a building block for more complex algorithms like Merge Sort. Efficiency and correctness in handling null pointers are key evaluation criteria.

Easy
Goldman Sachs
21

How do you check if an array is sorted in linear time?

Interviewers ask this to assess a candidate's ability to write clean, efficient code for fundamental data manipulation tasks. They want to see if the candidate understands the definition of a sorted array and can implement a solution with O(n) time complexity. This simple problem also reveals attention to edge cases, such as empty arrays or single-element inputs, which are often overlooked by junior developers.

Easy
Infosys
22

How do you delete a node given only a pointer in a singly linked list?

It reveals if you understand memory management and the limitations of singly linked lists without a previous pointer. In finance, memory leaks can be costly, so efficient deletion is key. It also tests creative problem-solving when standard approaches fail.

Easy
Goldman Sachs
23

How do you check if two matrices are identical element-wise?

Interviewers ask this to assess basic array comparison skills. It checks if candidates can handle 2D structures and iterate correctly to find any differences. The question also tests optimization by breaking early upon finding a mismatch.

Easy
Infosys
24

What is the most efficient way to count digits in a number?

This question probes the candidate's knowledge of different approaches to solve a simple mathematical problem. Interviewers look for awareness of both string conversion and mathematical division methods. They evaluate which method the candidate deems more efficient and why. It also checks if the candidate considers negative numbers and zero correctly.

Easy
Infosys
25

How do you add two matrices programmatically?

Interviewers use this to assess basic programming skills with 2D data structures. It checks if the candidate understands matrix dimensions and can iterate correctly over rows and columns. The question also verifies error handling for mismatched dimensions.

Easy
Infosys
26

How do you delete a node given only a pointer to it in a linked list?

Interviewers use this to see if candidates understand the limitations of singly linked lists. It tests creative problem-solving when standard deletion methods (accessing previous node) are unavailable. It also checks attention to detail regarding the last node scenario.

Easy
Goldman Sachs
27

Can you explain how to reverse a string efficiently in Java?

This question helps interviewers gauge familiarity with language-specific features and data structures. Since strings are immutable in languages like Java, they want to see if you know how to use StringBuilder or char arrays effectively. It also reveals your ability to optimize for both time and space complexity in common tasks.

Easy
Infosys
28

How do you search for a target value in a sorted array efficiently?

Employers ask this to verify that candidates understand the importance of algorithmic efficiency, particularly reducing search time from linear to logarithmic. It is a classic test of whether a candidate can recognize when a sorted structure allows for optimization. The interviewer also evaluates coding precision, specifically handling boundary conditions and avoiding off-by-one errors in loop implementations.

Easy
Goldman Sachs
29

What is the best strategy to reverse a string efficiently?

Reversing a string is a common interview question used to gauge a candidate's familiarity with low-level operations and memory management. Interviewers look for solutions that avoid unnecessary space allocation while maintaining readability. It also tests if you know built-in language functions versus implementing the logic manually, which demonstrates depth of understanding. The question helps distinguish between junior developers who might use inefficient methods and those who understand pointer arithmetic or swapping mechanics.

Easy
Infosys
30

What is Sling model code and how is it used in AEM?

Infosys has significant AEM projects. This question filters for candidates with specific frontend/backend integration skills in the AEM ecosystem. It tests knowledge of dependency injection and model mapping in a CMS context.

Hard
Infosys
31

How do you reverse a linked list in groups of size k?

Reversing in groups requires careful handling of partial lists and maintaining connections between groups. Interviewers assess the candidate's ability to manage complex pointer updates without losing references.

Hard
Amazon
32

How would you merge two sorted arrays without extra space?

Interviewers ask this to test advanced array manipulation and in-place sorting capabilities. It distinguishes candidates who know standard merge sort from those who can optimize space usage. It also probes understanding of gap algorithms or similar efficient in-place strategies.

Hard
Infosys
33

How do you convert a Binary Tree to a Doubly Linked List?

Tests pointer manipulation skills and understanding of in-order traversal sequences.

Hard
Amazon
34

How do you convert a binary tree into a doubly linked list?

This question assesses advanced pointer manipulation skills and the ability to restructure data without allocating new nodes. It demonstrates whether a candidate can perform complex in-place transformations efficiently.

Hard
Amazon
35

What is the strategy to reverse a linked list in groups of size k?

Interviewers use this to gauge your comfort with complex pointer arithmetic and edge case handling in linked lists. It reveals whether you can manage state across multiple segments of a list without losing references. It is a standard test for logical thinking and code correctness under constraints.

Hard
Amazon
36

How do you add two numbers represented by linked lists?

Representing numbers as linked lists removes the limitation of integer overflow. Interviewers want to see if candidates can implement basic arithmetic logic manually and handle carries correctly across list nodes.

Medium
Amazon
37

Write Selenium and Java code to automate an Amazon search

This question evaluates a candidate's hands-on experience with automated testing tools and their ability to write functional scripts for real-world scenarios. It assesses knowledge of DOM manipulation, element locators, and browser control within the Selenium framework. The interviewer wants to see if the candidate can translate a business requirement, like searching a product, into executable code that captures results and handles screenshots.

Medium
Infosys
38

How would you rotate a matrix by 90 degrees in place?

This problem evaluates your ability to think geometrically and implement in-place transformations without extra space. It tests your grasp of array indexing and nested loops. Interviewers often use this to distinguish candidates who can optimize space complexity effectively.

Medium
Amazon
39

Can you find a triplet such that a squared equals b squared plus c squared?

This question evaluates a candidate's mathematical intuition and their ability to optimize search operations. Interviewers look for solutions that go beyond brute force O(N^3) approaches. They want to see if you can apply hashing or sorting with two pointers to reduce complexity significantly.

Medium
Amazon
40

What is the most efficient way to count paths in a grid?

Recruiters use this to evaluate logical reasoning and algorithmic thinking. It reveals whether you can model real-world pathfinding scenarios mathematically. Candidates must demonstrate they understand both brute force and optimized approaches.

Medium
Microsoft
41

How do you automate Amazon search using Selenium and Java?

For a Software Quality Engineer role, practical experience with automation tools is critical. This question evaluates the candidate's ability to write clean, functional code to interact with web elements, handle browser drivers, and capture screenshots for verification. It tests both theoretical knowledge of Selenium architecture and hands-on coding skills necessary for maintaining automated test suites.

Medium
Infosys
42

How do you implement a stack with push pop and min operations in constant time?

Amazon asks this to verify deep understanding of stack internals and auxiliary data structures. They want to see if you can achieve O(1) for all operations, including getMin(), which is non-trivial. This reveals your ability to think about caching state or using secondary stacks to track history. It is a fundamental test of algorithmic design patterns.

Medium
Amazon
43

Can you explain how to find the largest word by deleting characters?

This question checks a candidate's ability to implement efficient string matching algorithms. It evaluates logical thinking regarding subsequence problems and the trade-off between checking every dictionary word versus optimizing the search.

Medium
Google
44

How do you sort an array of 0s, 1s, and 2s in linear time?

Standard sorting takes O(N log N), but this specific case allows for O(N). Interviewers ask this to see if you recognize the limited range of values and can apply counting sort or the Dutch National Flag partitioning logic. It demonstrates attention to detail and optimization capabilities.

Medium
Microsoft
45

What strategy do you use to solve the Kadane's Algorithm problem?

Kadane's Algorithm is a staple interview question to test a candidate's grasp of dynamic programming and greedy strategies. It reveals how well they can optimize a brute-force O(n^2) solution to O(n). Interviewers look for insights into maintaining running sums and resetting them when negative totals threaten to reduce the maximum.

Medium
Infosys
46

Find the maximum sum subarray such that no elements are consecutive.

This tests your grasp of dynamic programming and the ability to define states for inclusion/exclusion decisions. It is a variation of the House Robber problem, common in Amazon interviews.

Medium
Amazon
47

What is the approach to find common divisors of two numbers?

Interviewers ask this to test knowledge of Greatest Common Divisor (GCD) algorithms like Euclid's algorithm. They want to see if candidates can derive common divisors from the GCD efficiently rather than brute-forcing all pairs.

Medium
Infosys
48

Given two numbers represented by linked lists, how do you return their sum?

This tests your ability to simulate arithmetic operations on non-standard data representations. It evaluates your understanding of traversal, carry management, and creating new data structures dynamically.

Medium
Amazon
49

What are the steps to count all paths in an mXn matrix grid?

This question evaluates logical reasoning and the ability to handle grid-based traversal problems. Interviewers look for candidates who can identify constraints and choose between recursion, dynamic programming, or mathematical approaches. It also checks if the candidate considers edge cases like blocked cells or boundary conditions effectively.

Medium
Microsoft
50

How can you implement a stack with push, pop, and min operations in constant time?

Implementing O(1) min operations challenges candidates to think beyond standard stack implementations. It evaluates creativity in space-time trade-offs and understanding of stack mechanics.

Medium
Amazon
51

How do you arrange buildings to ensure clear sea views optimally?

This problem tests your ability to optimize time complexity and think about spatial relationships in linear data structures. It evaluates your skill in reducing a geometric problem to a simple iteration with state tracking. Interviewers look for solutions that avoid brute-force O(n^2) approaches in favor of efficient O(n) passes.

Medium
Microsoft
52

What is the best way to generate all binary strings from a pattern?

This problem evaluates a candidate's mastery of recursive backtracking algorithms. Interviewers look for clean code structure and the ability to explore all possibilities systematically. It also checks understanding of base cases and state management during recursion.

Medium
Google
53

What is the method to find the largest word in a dictionary by deletion?

This question evaluates a candidate's ability to process sequences and implement greedy algorithms. Interviewers want to see if you can efficiently compare a target string against a list of candidates without resorting to expensive operations. It also tests attention to detail regarding lexicographical ordering when multiple words have the same maximum length.

Medium
Google
54

What is the best way to generate binary strings from a pattern?

This question evaluates a candidate's grasp of recursive backtracking algorithms. Interviewers want to see if the candidate can systematically explore all possibilities without missing any combinations. It also tests their ability to manage state during recursion and prune invalid branches efficiently.

Medium
Google
55

How do you check if a number is a power of another number?

Interviewers ask this to test mathematical logic and the ability to handle edge cases like 0, 1, and negative bases. They want to see if candidates can use logarithms or repeated division effectively.

Medium
Infosys
56

What is the strategy to generate all binary strings from a given pattern?

This question is designed to test a candidate's comfort with recursion and backtracking algorithms. Interviewers look for the ability to explore all possible paths in a decision tree without missing any valid combinations. It also assesses code clarity and the capacity to manage state during recursive calls, which is crucial for complex string manipulation tasks.

Medium
Google
57

What is the strategy to find the largest word by deleting characters?

This question assesses a candidate's ability to implement efficient string matching algorithms. Interviewers want to see if the candidate can avoid brute-force substring generation and instead use a two-pointer or greedy strategy. It also evaluates understanding of lexicographical ordering when multiple words have the same maximum length.

Medium
Google
58

Focus on Java 8 features and explain where you have used them.

Java 8 introduced major paradigm shifts. Interviewers ask this to verify your proficiency with modern Java syntax and functional programming concepts. It distinguishes developers who stay updated from those relying on older versions.

Medium
TCS
59

Can you find a triplet where a squared equals b squared plus c squared?

Amazon interviewers use this to evaluate a candidate's ability to combine mathematical logic with efficient algorithmic design. They look for understanding of the two-pointer technique or hashing strategies to reduce time complexity from cubic to quadratic. The variation with sum zero further tests adaptability to similar problems like 3Sum.

Medium
Amazon
60

How do you find the first non-repeating character in a string?

Interviewers ask this to assess fundamental algorithmic thinking and proficiency with hash maps or arrays for counting frequencies. They want to see if you can optimize space and time, aiming for O(n) solutions rather than nested loops. This problem is common in fintech coding rounds where performance on large datasets matters.

Medium
Goldman Sachs
61

How do you determine if a sentence is a palindrome ignoring punctuation?

Interviewers ask this to evaluate a candidate's ability to preprocess data before applying logic. It tests attention to detail regarding character filtering and case sensitivity. The question also checks if the candidate can combine multiple string operations efficiently.

Medium
Infosys
62

How do you arrange buildings to ensure a clear view of the sea?

It tests your ability to optimize for time complexity while maintaining logical correctness. The problem is a variation of the 'next greater element' pattern, common in technical interviews.

Medium
Microsoft
63

What is the strategy to generate all binary strings from a pattern?

This question probes your ability to implement recursive solutions and manage state during exploration of a solution space. Google values candidates who can systematically explore possibilities without missing cases or creating infinite loops. It also tests your understanding of backtracking, a critical skill for combinatorial problems often found in real-world applications like parsing or constraint satisfaction.

Medium
Google
64

How do you find the First Non-Repeating Character in a Stream?

Streaming data processing is common in analytics. Interviewers ask this to evaluate your ability to maintain state efficiently. It demonstrates proficiency with data structures for dynamic inputs.

Medium
Flipkart
65

How would you implement a stack with push, pop, and min operations in constant time?

Interviewers ask this to verify if you understand how to trade space for time complexity. It checks your ability to design data structures that support multiple operations efficiently. A correct solution demonstrates deep knowledge of stack mechanics and the utility of tracking state via a secondary structure.

Medium
Amazon
66

How would you sort an array of 0s, 1s, and 2s in linear time?

Standard sorting algorithms take O(n log n), but this question challenges candidates to achieve O(n). Interviewers want to see if you know the three-pointer technique and can implement it without extra space. It evaluates your attention to detail in boundary conditions and loop invariants.

Medium
Microsoft
67

What is the most efficient way to count all paths in an mXn grid?

Candidates are asked this to evaluate their grasp of combinatorics and basic recursion. Microsoft interviewers look for the ability to derive the mathematical formula nCr rather than just writing a brute-force recursive code. It demonstrates whether a candidate can optimize a solution from exponential time to constant time using mathematical insights.

Medium
Microsoft
68

What is the method to sum all prime numbers up to N?

This question tests knowledge of prime number algorithms and efficiency. Interviewers want to see if candidates can implement the Sieve of Eratosthenes for better performance compared to checking each number individually. It also checks loop optimization.

Medium
Infosys
69

What is the approach to find the largest word by deleting characters?

This question evaluates your ability to design efficient string processing algorithms. It checks if you can implement a greedy approach to validate subsequence relationships quickly. Google interviewers want to see how you handle multiple queries against a dictionary and optimize for both time and readability.

Medium
Google
70

Can you generate all binary strings from a given pattern?

This question evaluates a candidate's grasp of recursive backtracking and state management. Interviewers look for the ability to explore the entire solution space systematically without missing combinations. It also tests how well a candidate handles string manipulation and manages the call stack depth in recursive implementations.

Medium
Google
71

How do you identify Armstrong numbers programmatically?

Armstrong numbers are a classic problem to test mathematical logic and loop control. Interviewers want to see if candidates can extract digits, compute powers, and sum them correctly. It also checks handling of multi-digit numbers and edge cases.

Medium
Infosys
72

How do you sort an array in wave form?

It tests your ability to follow specific patterns and constraints in data manipulation. Interviewers look for efficient sorting strategies versus simple swaps. It also checks if you understand the definition of a wave array (a[i] >= a[i+1] <= a[i+2]).

Medium
Goldman Sachs
73

Can you describe the steps to merge two sorted arrays without extra space?

Merging without extra space demonstrates advanced understanding of memory constraints and algorithmic efficiency. Interviewers want to see if you can manipulate data structures directly without relying on auxiliary storage. This skill is crucial in environments with limited memory resources or high-performance computing scenarios.

Medium
Infosys
74

How do you sort an array containing only 0s, 1s, and 2s?

It checks if you can implement specialized sorting algorithms rather than relying on built-in sorts. Interviewers value the O(n) time and O(1) space solution demonstrated here.

Medium
Microsoft
75

How do you find the largest word in a dictionary by deleting characters?

This question assesses a candidate's ability to design efficient string comparison algorithms. Interviewers look for a solution better than brute force, often involving sorting or two-pointer techniques. It also evaluates attention to tie-breaking rules like lexicographical order.

Medium
Google
76

How do you determine if a binary tree is height-balanced?

Interviewers use this to gauge your proficiency with recursion and tree properties. A balanced tree is crucial for efficient operations like search and insert. They want to see if you can optimize the solution to avoid redundant calculations, moving beyond a naive O(n^2) approach to an optimal O(n) one.

Medium
Microsoft
77

What is the process to convert a number from any base to decimal?

Base conversion is a common algorithmic problem that tests mathematical understanding of number systems. Interviewers want to see if candidates can implement the positional value summation logic correctly. It also checks handling of different bases and digit validity.

Medium
Infosys
78

How do you sort an array containing only 0s, 1s, and 2s efficiently?

Interviewers ask this to see if candidates can achieve O(n) time complexity with O(1) space complexity. It checks their ability to manipulate pointers correctly and handle edge cases in a single pass. Standard sorting algorithms like QuickSort are less efficient here due to higher overhead.

Medium
Microsoft
79

Can you print numbers from 1 to N without using loops?

Interviewers ask this to test creativity and deep understanding of recursion. It checks if candidates can replace iterative constructs with recursive calls and manage the base case correctly. It also highlights awareness of stack overflow risks.

Medium
Infosys
80

What is the most efficient way to count all paths in an mXn matrix?

This question probes the candidate's ability to translate a grid-based movement problem into a mathematical formula or an algorithmic solution. Interviewers look for awareness of both combinatorial approaches (using factorials) and DP approaches (summing previous cells). It helps them gauge if you can choose the right tool for the job based on constraints like obstacles or movement rules. It also tests basic knowledge of permutations and combinations in a practical context.

Medium
Microsoft

Ready to practice coding questions?

Get AI-powered feedback on your answers with our mock interview simulator.

Start Free Practice