Top 26 Coding Interview Questions (2026)

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

9 Easy
15 Medium
2 Hard
Updated April 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 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
03

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
04

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
05

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
06

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
07

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
08

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
09

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
10

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
11

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
12

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
13

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
14

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
15

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
16

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
17

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
18

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
19

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
20

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
21

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
22

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
23

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
24

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
25

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
26

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

Ready to practice coding questions?

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

Start Free Practice