TOPIC-WISE INTERVIEW PRACTICE

Data Structures & Algorithms interview questions and quick answers

Arrays, linked lists, hashing, trees and patterns, with line-by-line code and complexity.

Review 671 questions and short answers on Data Structures & Algorithms. Start with real examples below, then search, practise and follow links to full explanations.

671 questionsFree revision22 topics
START HERE

Data Structures & Algorithms: questions worth revising first

These answers come from AI Tapri's existing question bank and published interview guides. Open each answer and read the linked in-depth guide for examples and context.

01What is the difference between an array and a linked list, and when would you choose each?

An array stores items contiguously, so indexing is O(1) but inserting in the middle is O(n). A linked list stores nodes connected by pointers, so insertion at a known node is O(1) but reaching the kth item is O(n).

Read the full explanation
02How do you find the maximum profit from buying and selling a stock once?

Scan once while tracking the lowest price so far. At each day, the best profit if you sell today is price minus that lowest price. Keep the maximum of those.

Read the full explanation
03What is the difference between BFS and DFS, and when would you use each?

BFS (breadth-first search) explores a graph level by level using a queue, so it finds the shortest path in an unweighted graph. DFS (depth-first search) goes as deep as possible along one path before backtracking, using a stack or recursion, and suits cycle detection, topological sort and exploring all paths. Both take O(V + E) time.

Read the full explanation
04How do you implement binary search, and what are the common bugs?

On a sorted array, keep two pointers low and high, check the middle element, and throw away the half that cannot contain the target. Repeat until found or low passes high. It runs in O(log n). The classic bugs are computing mid as (low + high) / 2, which can overflow in Java or C++, and off-by-one errors in the loop condition and pointer updates.

Read the full explanation
05How do you check if one string is a rotation of another?

They must have the same length, and the second string must appear inside the first string written twice. For example, "waterbottle" doubled contains "erbottlewat".

Read the full explanation
06How do you check whether two strings are anagrams of each other?

Two strings are anagrams if they have the same letters with the same counts. Count the characters of the first string, subtract using the second, and check that every count ends at zero.

Read the full explanation
07What is a common pitfall related to "What is the difference between an array and a linked list, and when would you choose each"?

Saying linked list insertion is always O(1): finding the position is still O(n).

Read the full explanation
08How would you explain "What is the difference between an array and a linked list, and when would you choose each" in an interview?

"Arrays give O(1) random access but costly middle inserts; linked lists give O(1) inserts once you hold the node but O(n) lookup and extra memory for pointers. I pick an array when I read by index a lot and a linked list when I insert and delete at the ends or at known nodes often."

Read the full explanation
YOUR PRACTICE SPACE

Find your next answer.

Pick a topic, search a keyword, or open a question to reveal the answer.

671 questions available
DATA STRUCTURES & ALGORITHMS

Data Structures & Algorithms quick answers

Showing 18 of 671
653 remaining

Free to practise. No account needed. Made for quick revision, not rote memorisation.

Keep preparing for Data Structures & Algorithms

Quick answers help with recall; detailed guides explain the reasoning, examples and common mistakes behind each answer.

More topics to practise