50+ Data Structure and Algorithms Interview Questions for Programmers
Coding interviews are comprised mainly of data structure and algorithm-basedquestions as well as some of the logical questions such as, How do you swaptwo integers without using a temporary variable? These questions will not onlyhelp you develop your problem-solving skills but also improve your knowledgeof array data structure. It’s not guaranteed that you will be asked thesequestions, but they will give you enough of an idea of the kinds of questionsyou can expect in a real programming job interview.I am Java programmer, blogger on http://javarevisited.blogspot.com andhttp://java67.comCoding interviews are comprised mainly of data structure and algorithm-basedquestions as well as some of the logical questions such as, How do you swaptwo integers without using a temporary variable?There are a lot of computer science graduates and programmers applying forprogramming, coding, and software development roles at startups like Uber and Netflix. Big organizations like Amazon, Microsoft, and Google; andservice-based companies like Infosys or Luxsoft, but many of them have no ideaof what kind of programming interview questions to expect when you’re applyingfor a job with these companies.In this article, I’ll share some frequently asked programming interviewquestions from different interviews for programmers at different levels ofexperience, from people who have just graduated from college to programmerswith one to two years of experience.I think it’s helpful to divide coding interview questions into different topic areas. The topic areas I’ve seen most often in interviews are array,linked list, string, binary tree, as well as questions from algorithms (e.g.string algorithm, sorting algorithms like quicksort or radix sort, and othermiscellaneous ones), and that’s what you will find in this article.It’s not guaranteed that you will be asked these coding or data structure andalgorithmic questions, but they will give you enough of an idea of the kindsof questions you can expect in a real programming job interview.Once you have gone through these questions, you should feel confident enoughto attend any telephonic or face-to-face interviews.Btw, there is no point in attempting these questions if you don’t havesufficient knowledge of essential Data Structure and Algorithms or you havenot touched them from ages.In that case, you should take a good course like Algorithms and DataStructures Part 1 and 2 By Robert Horvick to refresh your DS and algorithmsskills.Check out this related video on programming below.VIDEO
50 Common Algorithms Interview Questions
Without any further ado, here is my list of some of the most frequently askedcoding interview questions from programming job interviews:
2. Linked List Programming Interview Questions
A linked list is another common data structure that complements the array datastructure. Similar to the array, it is also a linear data structure and stores elements in a linear fashion.However, unlike the array, it doesn’t store them in contiguous locations;instead, they are scattered everywhere in memory, which is connected to eachother using nodes.A linked list is nothing but a list of nodes where each node contains thevalue stored and the address of the next node.Because of this structure, it’s easy to add and remove elements in a linkedlist, as you just need to change the link instead of creating the array, butthe search is difficult and often requires O(n) time to find an element in thesingly linked list.This article provides more information on the difference between an array andlinked list data structures.It also comes in varieties like a singly linked list, which allows you totraverse in one direction (forward or reverse); a doubly linked list, which allows you to traverse in both directions (forward and backward); and finally, the circular linked list, which forms a circle.In order to solve linked list-based questions, a good knowledge of recursionis important, because a linked list is a recursive data structure.If you take one node from a linked list, the remaining data structure is still a linked list, and because of that, many linked list problems have simpler recursive solutions than iterative ones.Here are some of the most common and popular linked list interview questionsand their solutions: 1. How do you find the middle element of a singly linked list in one pass? (solution) 2. How do you check if a given linked list contains a cycle? How do you find the starting node of the cycle? (solution) 3. How do you reverse a linked list? (solution) 4. How do you reverse a singly linked list without recursion? (solution) 5. How are duplicate nodes removed in an unsorted linked list? (solution) 6. How do you find the length of a singly linked list? (solution) 7. How do you find the third node from the end in a singly linked list? (solution) 8. How do you find the sum of two linked lists using Stack? (solution)These questions will help you to develop your problem-solving skills as well as improve your knowledge of the linked list data structure.If you are having trouble solving these linked list coding questions then I suggest you refresh your data structure and algorithms skill by going through Data Structures and Algorithms: Deep Dive Using Java course.You can also check out this list of 30 linked list interview questions formore practice questions.
Now You’re Ready for the Coding Interview
These are some of the most common questions outside of data structure and algorithms that help you to do really well in your interview.I have also shared a lot of these questions on my blog, so if you are reallyinterested, you can always go there and search for them.These common coding, data structure, and algorithm questions are the ones youneed to know to successfully interview with any company, big or small, for anylevel of programming job.If you are looking for a programming or software development job in 2018, you can start your preparation with this list of coding questions.This list provides good topics to prepare and also helps assess your preparation to find out your areas of strength and weakness.A 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.Further Learning Data Structures and Algorithms: Deep Dive Using Java 10 Books to Prepare Technical Programming/Coding Job Interviews 10 Algorithm Books Every Programmer Should Read Top 5 Data Structure and Algorithm Books for Java Developers From 0 to 1: Data Structures & Algorithms in Java Data Structure and Algorithms Analysis — Job Interview
Key skills for programmers and software developers to learn in 2021
Hello friends, If you have been doing software development for some time andthinking about what makes a good programmer? What should a programmer learn in2021 to become a better developer? What should computer science graduates canlearn in advance for a career in software development and programming?> What are the skills expected of a junior developer are some of the common> questions I receive from many students on Facebook and Emails who follows> me.These are mostly college graduates and beginners who now have access to awealth of information thanks to the internet and eager to learn skills inadvance to prepare for their programming job interviews.In this article, I’ll share 11 skills, which I believe, every programmershould know or learn in 2021.This includes a programming language like C++ or Java, essential computerscience concepts like Data Structures, Algorithms and Computer Network basics,crucial tools like Git, Docker, Kubernetes and containers in general, Cloudcomputing concepts and platforms like AWS, GCP, Microsoft Azure, and evergreenskills like SQL and UNIX, editors like Eclipse or Visual Studio Code, and texteditors, like VIM and NotePad++, etc.This list is by no means complete, but it provides you a good starting pointfor skills a programmer should know. If you are aiming for a career insoftware development and looking for a programming job, then these are thingsyou can learn and improve to stay ahead of your competition.
2. Data Structure and Algorithms
If you want to become a programmer, then you ought to know Data Structure andAlgorithms well; there is no escape. This is one of the important topics ofany programming job interview, and without you knowing basic data structures,like an array, linked list, map, set, it’s not possible to write a real-worldapplication.That’s why every programmer should put a serious effort into learning the Datastructure and Algorithm during their computer science course.If you are a self-taught programmer, then also you must know Data structureand algorithm; in fact, many programming bootcamp will teach you Datastructure and algorithm as the first thing. If you need a course then I highlyrecommend checking out Data Structures and Algorithms: Deep Dive Using Javacourse by Tim Buchalaka on Udemy.And, if you need free resources to learn Data Structure and Algorithms thenyou can check these free Algorithms courses on Medium.
9. Object-Oriented Programming
8, I have asked you to learn a Programming language, and here I am
asking you to learn a scripting language? Why? Can the same programminglanguage not be used as a scripting language?Well, there is undoubtedly some language which is suitable for both OOP codingand scripting like Python, and that’s why I asked you to learn it at least,but if you happen to learn C/C++ or Java, then you can’t whip out something asquickly as a Python or Perl developer can do.If you want to learn Python and need a course, The Complete Python Bootcamp isa great course to start with.The scripting language makes it easy to create tools and scripts to solvecommon problems in the programming world. If you have a good command over ascripting language, like Python, then you can automate mundane stuff easily.Once again, I suggest you to learn Python to kill two birds in one stone, andif you need some more resources, this list of free Python tutorials fromMicrosoft and Google is also beneficial.That’s all about 11 skills every Programmer should learn. Computer sciencegraduates and people who aspire to become programmers can use this list tofind out about things like tools and skills to become a successful programmer.Btw, if you are interested to learn more about things programmers should know,there is a lot of guidance available in terms of essential stuff forprogrammers, and you can find man great advice on the internet like 97 ThingsProgrammer should know, a must-read for every serious programmer.Other Programming articles you may like 10 Algorithm Books Every Programmer Should Read 10 Tools Every Software Engineer should know The 2021 Java Developer RoadMap 10 High Paying Career Options for Programmers and developers 10 Tips to become a better Java developer The Complete Web Developer RoadMap 10 Tips to Improve your Programming Skill 10 OOP Design Principles Every Programmer Should Know 100+ Data Structure and Algorithm Questions for Programmers 10 Unit testing tools for Java ProgrammersThanks for reading this article so far. If you find this article useful, thenplease share it with your friends and colleagues. If you have any questions orfeedback, then please drop a note.If you think I have missed a critical skill which is beneficial for aprogrammer and one should learn it, feel free to suggest and I would be happyto incorporate it into this article. After all, Programming is a journey, andevery day we learn something important.
Top 20 Searching and Sorting Algorithms Interview Questions
I am Java programmer, blogger on http://javarevisited.blogspot.com andhttp://java67.com
A Collection of common coding problems from Interviews based on basic
algorithms like searching, sorting, and string algorithmsHello All, If you are preparing for Programming job interviews or looking fora new job then you know that it’s not an easy process. You got to be lucky toget the call and make to the first round of interview, not just when you are abeginner but at any stage of your career.But, Yes, it is the most difficult at the beginner level when you aresearching for your first job.> That’s why you can’t just take your chance lightly. You got to be prepared> to grab that chance and for that, you must know that is expected from you on> the interview. What is asked, what topics should you prepare, etc?I have blogged a lot about what you can find helpful articles in this blog butto recap let me tell you that apart from data structure questions, SystemDesign Questions, and Programming language specific questions like Java, C++,or Scala, most of the programming job interviews also ask algorithm basedquestions. These are based upon common searching and sorting algorithms like Stringalgorithms, binary search, graph algorithms, etc.It’s important that you practice these Algorithms based questions because eventhough they seem obvious and easy, sometimes they become tricky to solve inthe actual interview, especially if you have never coded them by yourself.> Practising these problems before interview not only makes you familiar with> them but also gives you more confidence in explaining the solution to the> interviewer, which plays a very important role in your selection.It also makes you ready for any twisted questions and alternative problemslike Interviewers often like to ask you to solve a particular coding problemusing Recursion or Iteration. Sometime, if you use a data structure like the one I have used in findingduplicate characters on String, they will ask you to solve that problemwithout using the Set data structure. That’s just some common example andthat’s why practice matters a lot. Btw, if you are a complete beginner in the world of Data Structure andAlgorithms, then I suggest you to first go through a comprehensive Algorithmcourse like Data Structures and Algorithms: Deep Dive Using Java on Udemywhich will not only teach you basic data structure and algorithms but also howto use them on the real world and how to solve coding problems using them.Data Structures and Algorithms: Deep Dive Using JavaOn the other hand, if you like to read books or prefer books over onlinecourses then you must read a comprehensive book like Introduction toAlgorithms by Thomas H. Cormen to get an understanding of common ComputerScience Algorithms like Searching, Sorting, Cryptography, Graph Algorithms andsome common ones like Fourier Transform.Introduction to Algorithms, 3rd Edition (The MIT Press)
20+ Searching and Sorting Algorithms Questions from Coding Interviews
Anyway, here is some of the frequently asked Searching and Sorting Algorithmsquestions from Interviews. I have linked the solution but you should try tosolve the problem before looking at the solution.The purpose of this article is that you should know how to solve theseproblems on your own, but, yes, if you got stuck and want to compare yoursolution, you can see the solution. 1. Can you implement a Binary Search Algorithm? (solution) It’s easy, binary search is a divide and conquers algorithm, where the problemis divided into sub-problem and those are solved. It’s a search algorithmwhich means it is used to find things like a number in an integer array or anitem in a catalog. The easiest way to implement a binary search algorithm is by using Recursion,which is what the solution link contains but you should try it yourself beforeseeing the solution. One of the worth noting this is that the input must be sorted, I mean you canonly implement binary search in a sorted array. 2. Write a program to implement Linear search Algorithm? (solution) It is even easier than binary search, all you need to do is go through allelements in the array using a for loop or recursive method and compare eachelement with the one you want to search. when an element matches you eitherreturn index or true/false depending upon your requirement. For example, if you are writing a contains() method you can return true orfalse to indicate whether an element is present in the array or not. Since youneed to scan the whole array to find the element, the time complexity of thisalgorithm is O(n).Btw, if you have trouble calculating and understanding time and spacecomplexity of algorithms then you should see a course like Data Structures &Algorithms — Interview to understand them better before going for aninterview. 3. Can you implement a Binary search Algorithm without recursion? (solution) You might know that you can replace a recursive algorithm to an iterative oneby using a loop and sometimes using a Stack data structure. For binary searchalso you can do this, just divide the array and compare the middle elementuntil you find the target element or there is no more element into an array.> If the target element is greater than middle than you got to move towards> the right, or otherwise towards left.Btw, if you have trouble understanding recursive algorithm or converting arecursive one to iterative one then I suggest you go through a good onlinecourse like Algorithms and Data Structures — Part 1 and Part 2 in Pluralsightto learn fundamentals better.These courses will also teach you about how to calculate time and spacecomplexity which is very important from both Coding Interview perspective aswell as improving the performance of an Algorithm.5. Implement the Bubble sort Algorithm? (solution) Isn’t this was the first sorting algorithm you learn? Well, I did and that’swhy I remember that bubble sort is about comparing each number with everyother number in an array so that after each pass the largest or smallestelement bubble up to the top.I mean the number has found it’s placed in the sorting order. This is one ofthe fundamental sorting algorithms and most of us started learning aboutsorting using this algorithm.> The time complexity of this is O(n ^2) which makes it unusable for a large> set of numbers but it does well for a small set of numbers.4. Write Code to implement Level Order Search in a Binary Tree? (solution) In level order search you first visit sibling nodes than going down into thenext level. You can use a Queue to implement level order search in a binarytree.If you want to learn more, you can check any of these free data structureand algorithms courses on freeCodeCampAnd, if you are really serious about doing well, you can also check this listof courses to crack your programming job interviews10 Data Structure, Algorithms, and SQL Courses to Crack Any Programming JobInterview6. Difference between a stable and unstable sorting algorithm? (answer) This one was a tricky concept which I didn’t know until long ago. I haven’tcome across any practical use case of this one yet but just knowing theconcept is Ok from the interview perspective.In a stable sorting algorithm, the order of the same element remains the sameeven after sorting but during the unstable sorting algorithm, this changes.A good example is a quicksort and mergesort where former is unstable whilelater is a stable algorithm. 7. What is Depth First Search Algorithm for a binary tree? (solution) It’s another popular searching algorithm which is mainly used in tree andgraphs. This algorithm first visits nodes in depth before searching in thesame level, that’s why the name Depth-first search algorithm.It’s tricky to implement but you can use a Stack to implement DFS or Depth-first search algorithm. If you need more information on this topic, I suggestyou check the Grokking Algorithms book by Aditya Bhargava, his explanation isprobably the best explanation of this topic8. How is an iterative quicksort algorithm implemented? (solution) Obviously without recursion:-). If you remember, I have told you before thatyou can use a Stack to convert a recursive algorithm into an iterative one andthat’s what you can do as well to implement Quicksort algorithm withoutrecursion. You can further see the solution if you need more help with respectto implementation. 9. How do you implement a counting sort algorithm? (solution) Just like we have done with other O(n) sorting algorithms like Radix sort andBucket sort.If you don’t know Counting sort is another integer sorting algorithm forsorting a collection of objects according to keys that are small integers.It has O(n) time complexity which makes it faster than likes of Quicksort andMergesort for a particular set of input. See the solution for more details.10. How do you swap two numbers without using the third variable? (solution) Another tricky question which is easy if you know the trick 🙂 Well you canswap two numbers without using a temporary or third variable if you can storethe sum of numbers in one number and then minus the sum with other numbersomething like a = 3; b = 5; a = a + b; //8 b = a — b; // 3 a = a — b; //5 now you have a = 5 and b = 3, so numbers are swapped without using a third ortemp variable. 11. How is a radix sort algorithm implemented? (solution) This is another integer sorting algorithm with O(n) time complexity. As perWikipedia, Radix sort is a non-comparative sorting algorithm that sorts datawith integer keys by grouping keys by the individual digits which share thesame significant position and value.You can further see Algorithms, Part I and Part II by Robert Sedgewick onCoursera to learn more about these O(n) or liner sorting algorithms. Thecourse is free for learning and exploring but you need to pay if you also wanta certification.12. How do you implement an insertion sort algorithm? (solution) Have you ever arranged the deck of cards, or maybe shirts in your cupboard?What is common between those two things? Well, you put the next card or shirtinto their proper position, or, should I say you insert the next element inits proper position. That’s the insertion sort for you. 13. Write Algorithm to check if two rectangles overlap with each other?(solution) This is a tricky Algorithm question but if you have to listen to your teacherin your 2D Maths class then you can solve this problem. There is anothertrick, check for all the conditions when rectangle will not overlap and if anycondition is false it means both rectangles are overlapping with each other.For example, if the upper side of one rectangle is below the lower side ofother rectangles then they won’t overlap as they are vertically aligned. 14. How is a merge sort algorithm implemented? (solution) Similar to Quicksort, merge sort is also a divide and conquer algorithm whichmeans you keep divides the problem until you can sort the smallest of them.For example to sort an array of numbers you divide the array into smallerparts until you know how to sort them like an array with one or zero elementsis already sorted. Once you sort small arrays you merge them to get the finalresult. The only difference between Quicksort and Mergesort is that mergesort isstable while Quicksort is not-stable. This means equal elements retain theirspot before and after sorting. Another worth noting difference is that even though both have O(NLogN) averagetime, it’s better to use quicksort than mergesort because Quicksort takes lesstime for the same number of input, the constant factor is less in Quicksortthan merge sort.15. How do you implement a bucket sort algorithm? (solution) The Bucket sort is another awesome algorithm which can sort an array withouteven comparing elements.It’s known as non-comparison sorting algorithm and can give O(n) performancefor the selected input.If you don’t know about the non-comparison based sorting Algorithm, please seeIntroduction to Algorithms book.16. Write Algorithms to Check if Two String are Anagram (Solution) An anagram is something where length and character matches but not the orderlike Army and Mary, both have the same number of characters.One trick is to solve this problem is to sort the character array and check ifthey are the same or not. 17. Implement the QuickSort Algorithm in your Favorite Programing language?(solution) This one is a very easy sorting algorithm, but only if you have practiced, ifnot then you may lose your way. Remember, Quicksort is a divide and conqueralgorithm which means you keep dividing array, also known as partitioning.Then you solve the problem at the smallest level, also known as a base caselike when your array contains just one or zero elements. 19, Difference between Comparison and Non-Comparison Sorting Algorithms?(answer) As the name suggests, in comparison based sorting algorithms you must compareelements to sort like quicksort, but in non-comparison based sorting algorithmlike Counting sort, you can sort elements without comparing it. Surprised?Well yes, then I suggest you check out this course to learn more about O(n)sorting algorithms like Radix Sort, Counting Sort, and Bucket Sort. You canfurther see Data Structures and Algorithms: Deep Dive if you want to learnmore about these O(n) sorting algorithms.Data Structures and Algorithms: Deep Dive Using Java19. How to check if two String is rotations of each other? (solution) There is a simple trick to solve this problem, just concatenate the Stringwith itself and check if the rotation exists there. You can do that by usingindexOf or substring method. If the concatenated String contains rotation thengiven String is a rotation of former. 20. Implement Sieve of Eratosthenes Algorithms for Prime Number? (solution) This is one of the tough algorithms to implement especially if you don’tremember it 🙂 Sometime interviewer gives you the explanation but other timesyou need to remember it. I hope these 20 questions should be enough to get you going on yourpreparation for Algorithms for Coding interviews. If you need more such codingquestions you can take help from books like Cracking The Code Interview, byGayle Laakmann McDowell which contains 189+ Programming questions andsolution. A good book to prepare for programming job interviews in a shorttime.By the way, the more questions you solve in practice, the better yourpreparation will be. So, if you think this list of questions is not enough andyou need more, then check out these additional 50 programming questions fortelephone interviews and these books and courses for more thoroughpreparation.
Now You’re Ready for the Coding Interview
These are some of the most common questions outside of data structure andalgorithms that help you to do really well in your interview. I have also shared a lot of these questions on my blog, so if you are reallyinterested, you can always go there and search for them. These common coding, data structure, and algorithms questions are the ones youneed to know to successfully interview with any company, big or small, for anylevel of programming job. If you are looking for a programming or software development job, you canstart your preparation with this list of coding questions. This list provides good topics to prepare and also helps assess yourpreparation to find out your areas of strength and weakness. Good knowledge of data structure and algorithms is important for success incoding interviews and that’s where you should focus most of your attention.”