Ajay Sharvesh M P

Top Most Data Structures and Algorithm Question in Interview

Life, Competitive Programming

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?

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.

Topmost DS & Algorithms Questions in Interview

Array Interview Questions with Solutions

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:

  1. How to find the duplicate number on Integer array in Java? (solution)
  2. How to check if an array contains a number in Java? (solution)
  3. How to find the largest and smallest number in an unsorted array? (solution)
  4. How to find all pairs on integer array whose sum is equal to a given number? (solution)
  5. How to find repeated numbers in an array if it contains multiple duplicates? (solution)
  6. Write a program to remove duplicates from an array in Java? (solution)
  7. How to sort an array in place using QuickSort algorithm? (solution)
  8. How to find the top two numbers from an integer array? (solution)
  9. How to remove duplicates from an array in place? (solution)
  10. How to remove a given element from an array in Java? (solution)
  11. How to reverse an array in place in Java? (solution)
  12. Difference between array and linked list data structure? (answer)
  13. How to check if an array contains a duplicate number? (answer)

Unsolved Questions:

  1. How to find the minimum value in a rotated sorted array?
  2. How to find subarray with the largest product in an array of both positive and negative number?
  3. How to merge sorted array?
  4. 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

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

  1. How to check if a linked list contains a loop in Java? How to find the starting node of the loop (solution)
  2. How to reverse a linked list in Java? (solution)
  3. How to reverse a singly linked list without recursion in Java? (solution)
  4. How to find the length of a singly linked list in Java? (solution)
  5. How to find the Kth node from the end in a singly linked list? (solution)
  6. Write a method in Java to sort a given linked list? Also, write Unit tests. (solution)
  7. What is the difference between an array and linked list in Java? (answer)
  8. How to implement a linked list using Generics in Java? (solution)

Unsolved Questions

  1. Write a Program to convert a binary tree into a doubly linked list?
  2. Write code to print out the data stored in each node in a singly linked list?
  3. How to delete a node from a Singly linked list in O(1) time?
  4. How do you find first intersection node of two linked list in Java?
  5. How do you merge two sorted lists into a single sorted linked list?
  6. How to swap every two nodes in a linked list?
  7. How to delete alternate nodes of a Linked List?
  8. How to find the frequency of a given number in a Linked List?
  9. Difference between singly and doubly linked list in Java?
  10. How to insert a node at the beginning of the list?
  11. How to insert a node at the end of the list?
  12. How do you traverse a linked list in Java?
  13. How do you convert a sorted doubly linked list to a balanced binary search tree in Java?
  14. 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

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

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

Unsolved Questions

  1. How do you find all permutations of a string?
  2. How do you reverse words in a given sentence without using any library method?
  3. How do you check if two strings are a rotation of each other?
  4. 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

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

  1. How do you perform preorder traversal in a given binary tree? (solution)
  2. How do you traverse a given binary tree in preorder without recursion? (solution)
  3. How do you perform an inorder traversal in a given binary tree? (solution)
  4. How do you print all nodes of a given binary tree using inorder traversal without recursion? (solution)

Unsolved Questions

  1. How do you traverse a binary tree in postorder traversal without recursion?
  2. How are all leaves of a binary search tree printed?
  3. How do you count a number of leaf nodes in a given binary tree?
  4. 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

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

  1. How is an iterative quicksort algorithm implemented? (solution)
  2. How do you implement an insertion sort algorithm? (solution)
  3. How is a merge sort algorithm implemented? (solution)
  4. How do you implement a bucket sort algorithm? (solution)
  5. How do you implement a counting sort algorithm? (solution)

Unsolved Questions

  1. How do you swap two numbers without using the third variable?
  2. How do you check if two rectangles overlap with each other?
  3. 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/

Author • Freelancer • Full Stack • Designer • Android • GSoC