Top 250 Data Structures Interview Questions and Answers

Updated 15 Jul 2025

Asked in HSBC Group

1d ago

Q. Palindromic Linked List Problem Statement

Given a singly linked list of integers, determine if it is a palindrome. Return true if it is a palindrome, otherwise return false.

Example:

Input:
1 -> 2 -> 3 -> 2 -> 1 -> NULL
Output:
tr...read more
Ans.

Check if a given singly linked list of integers is a palindrome or not.

  • Traverse the linked list to find the middle element using slow and fast pointers.

  • Reverse the second half of the linked list.

  • Compare the first half with the reversed second half to...read more

4d ago

Q. Validate Binary Tree Nodes Problem

You are provided with 'N' binary tree nodes labeled from 0 to N-1, where node i has two potential children, recorded in the LEFT_CHILD[i] and RIGHT_CHILD[i] arrays. Determine whether all the node...read more

Ans.

The task is to determine if the given binary tree nodes form exactly one valid binary tree.

  • Check if there is only one root node (a node with no parent)

  • Check if each node has at most one parent

  • Check if there are no cycles in the tree

  • Check if all nodes...read more

Asked in Accenture

1d ago

Q. Write a function to remove duplicate elements from an array.

Ans.

Remove duplicate elements from an Array

  • Use the Set object to remove duplicate elements

  • Convert the Set back to an array using the spread operator

  • If the array contains objects, use a custom comparison function

Asked in Unisys

1d ago

Q. What are the differences between a Stack and a Queue, and can you provide a real-time example for each?

Ans.

Stack is LIFO and Queue is FIFO data structure. Stack is like a stack of plates and Queue is like a queue of people.

  • Stack is Last In First Out (LIFO) and Queue is First In First Out (FIFO)

  • Stack is like a stack of plates where the last plate added is ...read more

Are these interview questions helpful?

Asked in Amazon

4d ago

Q. Given a Binary Search Tree (BST), find the nearest greater value of a given value in the BST.

Ans.

Find the nearest greater value of a given value in a Binary Search Tree (BST).

  • Start from the root node and compare the given value with the current node's value.

  • If the given value is less than the current node's value, move to the left subtree.

  • If the...read more

Asked in NetApp

4d ago

Q. Suggest a suitable combination of array and hashmap to design the underlying data structures behind an educational institution’s website. The website supports selection of a particular department, a particular course in the depart...

read more
Ans.

A combination of array and hashmap can be used to design the underlying data structures for an educational institution's website.

  • Use an array to store the departments available in the institution.

  • Each department can be represented as a key in the has...read more

Share interview questions and help millions of jobseekers 🌟
man with laptop
5d ago

Q. What data structure uses a Tree? Give examples.

Ans.

A data structure that uses a Tree is a hierarchical structure that consists of nodes connected by edges.

  • Examples include Binary Trees, AVL Trees, Red-Black Trees, B-Trees, and Trie Trees.

  • Trees are used in computer science for efficient searching, sor...read more

Asked in e2open

2d ago

Q. Explain the data structure algorithm for tree traversal.

Ans.

DS algorithm for tree traversal is used to visit each node of a tree exactly once.

  • Depth First Search (DFS) - Preorder, Inorder, Postorder

  • Breadth First Search (BFS)

  • DFS is recursive while BFS uses a queue

  • Preorder - Root, Left, Right

  • Inorder - Left, Root...read more

Asked in Paytm

1d ago

Q. Can you implement a stack using a queue?

Ans.

Yes, we can implement a stack using two queues.

  • Push operation: Enqueue the element to the first queue.

  • Pop operation: Dequeue all elements from the first queue and enqueue them to the second queue until the last element. Dequeue and return the last el...read more

Asked in HighRadius

4d ago

Q. How do you create a custom read-only list?

Ans.

To create a custom read-only list, use the ReadOnlyCollection class in C#.

  • Create a List<T> object with the desired elements.

  • Use the AsReadOnly() method to create a read-only wrapper around the list.

  • Use the ReadOnlyCollection<T> class to create a trul...read more

Data Structures Jobs

Robert Bosch Engineering and Business Solutions Private Limited logo
Android developer 6-10 years
Robert Bosch Engineering and Business Solutions Private Limited
4.1
Hosur
Apple India Pvt Ltd logo
DevOps Engineer 5-10 years
Apple India Pvt Ltd
4.3
Hyderabad / Secunderabad
SANOFI HEALTHCARE INDIA PRIVATE LIMITED logo
Data Engineer 4-5 years
SANOFI HEALTHCARE INDIA PRIVATE LIMITED
4.1
Hyderabad / Secunderabad
2d ago

Q. What data structure would you use for a dictionary?

Ans.

An array of key-value pairs is the best data structure for a dictionary.

  • Use a hash table or a balanced tree to implement the dictionary.

  • Keys should be unique and immutable.

  • Values can be any data type.

  • Access time should be O(1) or O(log n) depending o...read more

Asked in Amazon

5d ago

Q. Squares of a Sorted Array Problem Statement

You are given an array/list ARR consisting of N integers. Your task is to generate a new array/list containing the squares of each element in ARR, with the resulting array/list sorted in...read more

Ans.

Given an array of integers, generate a new array with the squares of each element sorted in increasing order.

  • Iterate through the array and square each element

  • Sort the squared elements in increasing order

  • Return the sorted array

Asked in Amazon

6d ago

Q. Triplet Count in a Sorted Doubly Linked List Problem

Count the number of triplets in a sorted doubly linked list such that their sum equals a given integer 'X'. The list is composed of distinct node values.

Explanation:

A sorted d...read more

Ans.

Count the number of triplets in a sorted doubly linked list such that their sum equals a given integer 'X'.

  • Iterate through the linked list and for each node, use two pointers to find the other two nodes that sum up to 'X'.

  • Keep track of the count of t...read more

3d ago

Q. Could you implement that in code?

Ans.

Yes, I can implement those in code.

  • I have experience in coding and implementing various algorithms and data structures.

  • I am proficient in programming languages such as Java, Python, and C++.

  • I can provide examples of my previous coding projects upon r...read more

Asked in Walmart

4d ago

Q. What would be the ideal data structure to represent people and friend relations in Facebook?

Ans.

Graph

  • Use a graph data structure to represent people as nodes and friend relations as edges

  • Each person can be represented as a node with their unique identifier

  • Friend relations can be represented as directed edges between nodes

  • This allows for efficien...read more

Asked in Amadeus

5d ago

Q. Matrix Transformation Problem Statement

Given a 2-dimensional matrix of size NxN containing 0s and 1s, the task is to modify the matrix such that, if an element is 1, set its entire row and column to 1. In the end, determine how m...read more

Ans.

Modify a matrix by setting entire row and column to 1 if an element is 1, then count the number of 1s.

  • Iterate through the matrix to find elements with value 1

  • Use two arrays to keep track of rows and columns to be modified

  • Update the matrix by setting ...read more

Q. Which data structure is better for your use case: a B Tree or a Hash Table?
Ans.

Hash Table is better for fast lookups and insertions, while B Tree is better for range queries and ordered traversal.

  • Use Hash Table for fast lookups and insertions with O(1) average time complexity.

  • Use B Tree for range queries and ordered traversal w...read more

Asked in Suma Soft

3d ago

Q. What is an ArrayList and where is it used?

Ans.

ArrayList is a dynamic array that can store objects of any type. It is used to store and manipulate collections of data.

  • ArrayList is part of the System.Collections namespace in .NET.

  • It can store objects of any type, including value types and referenc...read more

3d ago

Q. What is the first-in, first-out (FIFO) method?

Ans.

First in first out (FIFO) is a method of inventory valuation based on the assumption that the first goods purchased are the first goods sold.

  • FIFO assumes that the oldest inventory items are sold first

  • It is commonly used in industries where the produc...read more

Asked in HSBC Group

4d ago
Q. Which data structures are used for implementing an LRU cache?
Ans.

The data structures used for implementing an LRU cache are doubly linked list and hash map.

  • Doubly linked list is used to maintain the order of recently used elements.

  • Hash map is used for fast lookups to check if an element is present in the cache or ...read more

Asked in Visa

4d ago

Q. Design autocomplete in IDEs

Ans.

Autocomplete in IDEs helps developers write code faster by suggesting code snippets and completing code as they type.

  • Autocomplete should suggest code snippets based on the context of the code being written

  • Autocomplete should prioritize suggestions ba...read more

Asked in Amazon

3d ago

Q. What is DSA and why do we use it?

Ans.

DSA stands for Data Structures and Algorithms. It is used to efficiently store and manipulate data in computer programs.

  • DSA helps in organizing and managing data effectively.

  • It provides efficient algorithms for searching, sorting, and manipulating da...read more

6d ago

Q. What is the difference between a collection and a map?

Ans.

Collection is a group of objects while Map is a key-value pair data structure.

  • Collection is used to store and manipulate a group of objects.

  • Map is used to store and retrieve data based on key-value pairs.

  • Collection classes include List, Set, and Queu...read more

Asked in DXC Technology and 3 others

1d ago

Q. Write a program to print your name.

Ans.

A program to print name using an array of strings.

  • Declare an array of strings with the name.

  • Assign the name to the array.

  • Loop through the array and print each string.

Asked in Amazon and 2 others

5d ago

Q. What is a Set?

Ans.

Set is a collection of unique elements with no specific order.

  • A set can be created using curly braces {} or the set() function.

  • Sets can only contain immutable objects like strings, numbers, and tuples.

  • Sets are useful for removing duplicates and perfo...read more

Asked in Amazon

5d ago

Q. Print the level order traversal of the binary tree in spiral form.

Ans.

Print the level order traversal of binary tree in spiral form

  • Perform level order traversal of the binary tree

  • Alternate the direction of traversal for each level

  • Use a stack to reverse the order of nodes in each level

  • Print the nodes in the order of tra...read more

Asked in Adobe

5d ago

Q. How do you find a loop in a Linked List and how do you remove it?

Ans.

To find and remove a loop in a Linked List, we can use Floyd's Cycle Detection Algorithm.

  • Use two pointers, slow and fast, to detect if there is a loop in the Linked List

  • If the two pointers meet at some point, there is a loop

  • To remove the loop, set on...read more

Asked in Walmart Labs

1d ago

Q. Write code to build a heap and explain its time complexity.

Ans.

A code for building a heap and its time complexity

  • A heap is a complete binary tree where each node is greater than or equal to its children

  • To build a heap, start from the last non-leaf node and heapify down each node

  • Time complexity: O(n) for building...read more

Asked in GS Lab

1d ago

Q. What is the difference between a Hashtable and a ConcurrentHashMap?

Ans.

Hashtable is not thread-safe while ConcurrentHashmap is thread-safe.

  • Hashtable is a legacy class while ConcurrentHashmap is a modern class.

  • Hashtable uses synchronized methods while ConcurrentHashmap uses lock striping.

  • ConcurrentHashmap allows multiple...read more

Asked in Springworks

1d ago

Q. Linear Probing in Hashing

Hashing is a technique to map large non-negative integers to smaller indices using a hash function. In the context of collision resolution in hash tables, 'Linear Probing' is employed, where the probe seq...read more

Ans.

Linear Probing in Hashing is a technique to resolve collisions in hash tables by linearly searching for the next available slot.

  • Implement a function that takes an array of non-negative integers and returns the corresponding hash table using linear pr...read more

1
2
3
4
5
6
7
Next

Interview Experiences of Popular Companies

TCS Logo
3.6
 • 11.1k Interviews
Accenture Logo
3.7
 • 8.7k Interviews
Infosys Logo
3.6
 • 7.9k Interviews
Wipro Logo
3.7
 • 6.1k Interviews
Cognizant Logo
3.7
 • 5.9k Interviews
Amazon Logo
4.0
 • 5.4k Interviews
Capgemini Logo
3.7
 • 5.1k Interviews
HCLTech Logo
3.5
 • 4.1k Interviews
Oracle Logo
3.7
 • 895 Interviews
View all
Interview Tips & Stories
Interview Tips & Stories
Ace your next interview with expert advice and inspiring stories
Data Structures Interview Questions
Share an Interview
Stay ahead in your career. Get AmbitionBox app
play-icon
play-icon
qr-code
Trusted by over 1.5 Crore job seekers to find their right fit company
80 Lakh+

Reviews

10L+

Interviews

4 Crore+

Salaries

1.5 Cr+

Users

Contribute to help millions

Made with ❤️ in India. Trademarks belong to their respective owners. All rights reserved © 2025 Info Edge (India) Ltd.

Follow Us
  • Youtube
  • Instagram
  • LinkedIn
  • Facebook
  • Twitter
Profile Image
Hello, Guest
AmbitionBox Employee Choice Awards 2025
Winners announced!
awards-icon
Contribute to help millions!
Write a review
Write a review
Share interview
Share interview
Contribute salary
Contribute salary
Add office photos
Add office photos
Add office benefits
Add office benefits