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.

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:

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

Unsolved Questions:

  1. Given an array of size n and a number k, find all elements that appear more than n/k times?
  2. How to find the minimum value in a rotated sorted array?
  3. How to find subarray with the largest product in an array of both positive and negative number?
  4. How to merge sorted array?
  5. 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

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

Unsolved Questions

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

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

Unsolved Questions

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

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

Unsolved Questions

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

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

Unsolved Questions

  1. How is a radix sort algorithm implemented?
  2. How do you swap two numbers without using the third variable?
  3. How do you check if two rectangles overlap with each other?
  4. 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

Love podcasts or audiobooks? Learn on the go with our new app.

Recommended from Medium

Data encapsulation in Java

Making a custom Chrome extension

Human-centered Software Development

Introducing ‘copy’ feature for tasks & projects in Gridle!

How to maximize span ingestion while limiting writes per second to Scylla with Jaeger

How to bypass AT&T Router (completely)

Able to ping google but not Facebook

5 Tips for Learning How to Code

Get the Medium app

Ajay Sharvesh M P

Ajay Sharvesh M P

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

More from Medium

Signpost for a junior software engineer

Sorting Algorithms: Insertion Sort

Data Structures and How To Build It From Scratch Series #0

Stack Part 1 — Data Structure | Learn More CSE