# Top Most Data Structures and Algorithm Question in Interview

# Life, Competitive Programming

Being a Programmer, it will gradually increase the thinking capacity, logical solving and optimization for every solution. If you are a Novice, then start solving the simpler problem and find the solution, but it’ll really suck every programmer (Novice, Intermediate, Expert and Pro) to find a solution for each and every problem. It will take more time to solve any problem for all the levels of the programmer, and it will be degraded if you get some issues of your code but be motive and try to solve any of the problems makes you motivate yourself and enjoy to enter into the new problem to solve.

If you ever talked to a great programmer, you’ll find they know their tools like an artist knows their paintbrushes —

Bill Gates.

# What is Data Structures and Algorithms?

Data Structures is the type of arrangement of the data in the computer memories and also in the external storage. Few popular data structures are Array, LinkedList, Queue, Stack, Tree, and Graphs so on. In other hands, Algorithms are used to manipulate data contained in these data structures as in Searching and Sorting.

In many algorithms, they are applied directly to specific data structures and also whenever working with the data structures you must need to know the pieces of stuff like, to **Insert the data, search for and delete an item**.

# Tutorial, Data Structures & Algorithms

Topmost DS & Algorithms Questions in Interview

# Array Interview Questions with Solutions

**Definition:**

Stores data elements based on a sequential, most commonly 0 based, index. Based on tuples from set theory. They are one of the oldest, most commonly used data structures.

**What you need to know:**Optimal for indexing: Bad at searching, inserting, and deleting (except at the end). Linear arrays, or one-dimensional arrays, are the most basic. Are static in size, meaning that they are declared with a fixed size.

Dynamic arrays are like one-dimensional arrays but have reserved space for additional elements. If a dynamic array is full, it copies contents to a larger array. Two-dimensional arrays have x and y indices like a grid or nested arrays.

**Big O efficiency:**Indexing: Linear array: O(1), Dynamic array: O(1)

Search: Linear array: O(n), Dynamic array: O(n)

Optimized Search: Linear array: O(log n), Dynamic array: O(log n)

Insertion: Linear array: n/a Dynamic array: O(n)

**Solved Questions:**

**How to find the missing number in integer array of 1 to 100?**(solution)**How to find the duplicate number on Integer array in Java?**(solution)**How to check if an array contains a number in Java?**(solution)**How to find the largest and smallest number in an unsorted array?**(solution)**How to find all pairs on integer array whose sum is equal to a given number?**(solution)**How to find repeated numbers in an array if it contains multiple duplicates?**(solution)**Write a program to remove duplicates from an array in Java?**(solution)**How to sort an array in place using QuickSort algorithm?**(solution)**How to find the top two numbers from an integer array?**(solution)**How to remove duplicates from an array in place?**(solution)**How to remove a given element from an array in Java?**(solution)**How to reverse an array in place in Java?**(solution)**Difference between array and linked list data structure?**(answer)**How to check if an array contains a duplicate number?**(answer)

# Unsolved Questions:

**Given an array of size n and a number k, find all elements that appear more than n/k times?****How to find the minimum value in a rotated sorted array?****How to find subarray with the largest product in an array of both positive and negative number?****How to merge sorted array?****How to find if there is a sub-array with the sum equal to zero?**

These questions will help you to develop your problem-solving skills as well as improve your knowledge of the linked list data structure.

# Linked List Interview Questions with Solutions

**Definition:** Stores data with nodes that point to other nodes. Nodes, at its most basic it has one datum and one reference (another node). A linked list

*chains*nodes together by pointing one node’s reference towards another node.

**What you need to know:**Designed to optimize insertion and deletion, slow at indexing and searching. A doubly linked list has nodes that reference the previous node. The circularly linked list is a simple linked list whose tail, the last node, references the head, the first node.

**Big O efficiency:**Indexing: Linked Lists: O(n)

Search: Linked Lists: O(n)

Optimized Search: Linked Lists: O(n)

Insertion: Linked Lists: O(1)

# Solved Questions

**How to find the middle element of a singly linked list in one pass?**(solution)**How to check if a linked list contains a loop in Java? How to find the starting node of the loop**(solution)**How to reverse a linked list in Java?**(solution)**How to reverse a singly linked list without recursion in Java?**(solution)**How to find the length of a singly linked list in Java?**(solution)**How to find the Kth node from the end in a singly linked list?**(solution)**Write a method in Java to sort a given linked list? Also, write Unit tests**. (solution)**What is the difference between an array and linked list in Java?**(answer)**How to implement a linked list using Generics in Java?**(solution)

# Unsolved Questions

**How would you remove a node from a doubly linked list?****Write a Program to convert a binary tree into a doubly linked list?****Write code to print out the data stored in each node in a singly linked list?****How to delete a node from a Singly linked list in O(1) time?****How do you find first intersection node of two linked list in Java?****How do you merge two sorted lists into a single sorted linked list?****How to swap every two nodes in a linked list?****How to delete alternate nodes of a Linked List?****How to find the frequency of a given number in a Linked List?****Difference between singly and doubly linked list in Java?****How to insert a node at the beginning of the list?****How to insert a node at the end of the list?****How do you traverse a linked list in Java?****How do you convert a sorted doubly linked list to a balanced binary search tree in Java?****How to implement LRU cache in Java using a linked list?**

These questions will help you to develop your Linked List problems, by solving this will improve your skills and may increase your confidence to solve the complex questions asked by an interviewer.

# String Interview Question

**Definition:**A String

*is any finite sequence of*

*characters*

*(i.e., letters, numerals, symbols, and punctuation marks).*

**What you need to know:** String in Java is a very special class and most frequently used class as well. There are lot many things to learn about String in Java than any other class, and having a good knowledge of different String functionalities makes you use it properly.

**Solved Questions**

**How do you print duplicate characters from a string? (****solution****)****How do you check if two strings are anagrams of each other? (****solution****)****How do you print the first non-repeated character from a string? (****solution****)****How can a given string be reversed using recursion? (****solution****)****How do you check if a string contains only digits? (****solution****)****How are duplicate characters found in a string? (****solution****)****How do you count a number of vowels and consonants in a given string? (****solution****)**

# Unsolved Questions

**How do you count the occurrence of a given character in a string?****How do you find all permutations of a string?****How do you reverse words in a given sentence without using any library method?****How do you check if two strings are a rotation of each other?****How do you check if a given string is a palindrome?**

These questions help improve your knowledge of string as a data structure. If you can solve all these String questions without any help then you are in good shape.

# Binary Tree Interview Questions

**Definition:** Is a tree-like data structure where every node has at most two children. There is the one left and right child node.

**What you need to know:**Designed to optimize searching and sorting.

A degenerate tree is an unbalanced tree, which is entirely one-sided is an essentially a linked list. They are comparably simple to implement than other data structures. Used to make binary search trees.

A binary tree that uses comparable keys to assign which direction a child is. The left child has a key smaller than it’s parent node.

The right child has a key greater than it’s parent node.

There can be no duplicate node.

Because of the above, it is more likely to be used as a data structure than a binary tree.

**Big O efficiency:**Indexing: Binary Search Tree: O(log n)

Search: Binary Search Tree: O(log n)

Insertion: Binary Search Tree: O(log n)

**Solved Questions**

**How is a binary search tree implemented? (****solution****)****How do you perform preorder traversal in a given binary tree? (****solution****)****How do you traverse a given binary tree in preorder without recursion? (****solution****)****How do you perform an inorder traversal in a given binary tree? (****solution****)****How do you print all nodes of a given binary tree using inorder traversal without recursion? (****solution****)**

# Unsolved Questions

**How do you implement a postorder traversal algorithm?****How do you traverse a binary tree in postorder traversal without recursion?****How are all leaves of a binary search tree printed?****How do you count a number of leaf nodes in a given binary tree?****How do you perform a binary search in a given array?**

If you feel that your understanding of binary tree coding is inadequate and you can’t solve these questions on your own, I suggest you go back and pick a good data structure and algorithm course like **From 0 to 1: Data Structures & Algorithms in Java**.

# Miscellaneous Interview Questions

Since apart from the Data structures and Algorithms, the job interviews are expecting some types of topics like Design, Bit Manipulations, Algorithms, and General Logic-Based Questions.

It’s important that you practice these concepts because sometimes they become tricky to solve in the actual interview. Having practiced them before not only makes you familiar with them but also gives you more confidence in explaining the solution to the interviewer.

# Solved Questions

**How is a bubble sort algorithm implemented? (****solution****)****How is an iterative quicksort algorithm implemented? (****solution****)****How do you implement an insertion sort algorithm? (****solution****)****How is a merge sort algorithm implemented? (****solution****)****How do you implement a bucket sort algorithm? (****solution****)****How do you implement a counting sort algorithm? (****solution****)**

# Unsolved Questions

**How is a radix sort algorithm implemented?****How do you swap two numbers without using the third variable?****How do you check if two rectangles overlap with each other?****How do you design a vending machine?**

By the way, the more questions you solve in practice, the better your preparation will be. So, if you think this is not enough and you need more, then check out these additional **50 programming questions**** **for telephone interviews and these books and courses for more thorough preparation.

# Voila, Now You are READY!

These are some of the most common questions are asked outside of data structure and algorithms that help you to do really well in your interview process.

These **Programming, Data Structure, and Algorithm Questions** are the ones you need to know to successfully interview with any company, big or small, for any level of programming job.

If you are looking for a programming or software development job in 2019, you can start your preparation with this list of coding questions.

Good knowledge of data structure and algorithms is important for success in coding interviews and that’s where you should focus most of your attention on your preparations.

I wish you for your Programming Interviews and it’s not gonna be so easy but I swear by following this article make you a step into to becoming a DevOps engineer.

PS: If you got struggle in any of the concepts, don’t hesitate to contact me. Feel free to connect with me at any of the social media.

Facebook:https://facebook.com/Green.Little.Roboo

Twitter:https://twitter.com/AjaySharvesh_

LinkedIN:https://www.linkedin.com/in/ajay-sharvesh/