Arrays, Strings and Hashing Interview Questions for Data Structures and Algorithms
25 Arrays, Strings and Hashing questions with answers for data structures and algorithms roles — 9 easy, 12 medium, 4 hard.
About Arrays, Strings and Hashing
Arrays and strings appear in most coding rounds. Learn two pointers, sliding window, prefix sums, Kadane's algorithm and in-place techniques, along with hash maps and hash sets for fast lookups. This topic also covers string matching, collisions, load factor and handling data that does not fit in memory.
What is the two pointer technique and when is it used?
Show answer
Strings are immutable in Java and Python. How does that affect algorithm complexity?
Show answer
What is the difference between a subarray, a subsequence and a substring?
Show answer
How would you check whether two strings are anagrams, and what changes if input can contain any Unicode characters?
Show answer
Solve two sum: return the indices of two numbers that add up to the target.
Show answer
Implement Kadane's algorithm for the maximum subarray sum.
Show answer
Check whether a string is a palindrome, ignoring case and non-alphanumeric characters.
Show answer
Describe a time you got stuck during a coding interview or contest. How did you recover?
Show answer
Explain the sliding window technique with fixed and variable windows.
Show answer
What are prefix sums and what problems do they solve?
Show answer
How does a hash table work, and how are collisions handled?
Show answer
What is Kadane's algorithm?
Show answer
What is the load factor of a hash table and why does it matter?
Show answer
What is the Dutch National Flag algorithm?
Show answer
An array of size 100000 must answer 100000 queries asking for the sum between two indices. What approach would you use?
Show answer
Your brute-force solution for the longest substring without repeating characters is O(n cubed). How would you improve it?
Show answer
You must merge two sorted arrays where the first array has enough empty space at the end for the second. How would you do it in place?
Show answer
Find the length of the longest substring without repeating characters.
Show answer
Rotate an array to the right by k steps in place.
Show answer
Tell me about a time you used the right data structure to solve a real problem in a project or job.
Show answer
How do the KMP and Rabin-Karp string matching algorithms work?
Show answer
You have a 100 GB file of integers and only 4 GB of RAM. How would you find the duplicates?
Show answer
A hash map lookup in your service suddenly becomes very slow under certain traffic. What could cause it?
Show answer
Return an array where each element is the product of all other elements, without using division.
Show answer
Frequently asked questions
How important is Arrays, Strings and Hashing in Data Structures and Algorithms interviews?
Arrays and strings appear in most coding rounds. Learn two pointers, sliding window, prefix sums, Kadane's algorithm and in-place techniques, along with hash maps and hash sets for fast lookups. This topic also covers string matching, collisions, load factor and handling data that does not fit in memory.
How should I use the Arrays, Strings and Hashing sheet?
Go top to bottom — easy to hard. Answer before opening each answer, tick what you solved and save misses to Last-Minute Revision.