TOP 48 algorithm and programming interview questions, awesome!

Java technology stack

www.javastack.cn

Follow to read more quality articles

Author: javinpaul

Original: https://hackernoon.com/50-data-structure-and-algorithms-interview-questions-for-programmers-b4b1ac61f5b0

This article is reprinted with authorization from the heart of the machine (WeChat public account: almosthuman2014). Reprinting is prohibited

Many computer science graduates and programmers go to Uber, unicorn companies like Toutiao, or tech giants like Amazon, Microsoft, and Google to apply for programming and software development positions. When you apply for these jobs, you must be wondering what questions the interviewer will ask.

In this article, the author will share some common programming interview questions, these questions come from the interview for programmers of different levels of experience-from fresh graduates to programmers with one or two years of experience.

Programming interview questions usually contain data structure and algorithm-based questions, as well as some logical questions, such as: How to exchange two integers without using temporary variables?

For clarity, programming interview questions need to be divided into different topics. The areas that we often see in interviews are arrays, linked lists, strings, binary trees, and related algorithms (such as string algorithms, quick sorting or radix sorting and other sorting algorithms). This article will introduce these.

Although this article cannot cover all the questions you will face in the interview, it can provide you with enough ideas to prepare you for various challenges during the interview.

Once these problems are solved, you can face any phone interview or on-site interview with confidence.

Of course, if you do not have sufficient knowledge of basic data structures and algorithms, then direct contact with the following questions will not help you.

Algorithm and programming interview questions TOP 48

Without further ado, here is a "list of the most common questions in programming interviews":

1. Array Programming Interview Questions

Array is the most basic data structure, it stores elements in a continuous memory space. Arrays are also one of the interviewers' favorite topics. You can hear many questions about arrays in any programming interview, such as reversing arrays, sorting arrays, or searching array elements.

The main advantage of the data structure of the array is that if an index is given, it will provide a search of O(1) complexity, which is very fast. But adding or removing elements from the array is slow, because once the array is created, it is difficult to change its size. If we need a longer or shorter array, we need to recreate the new array and copy all the elements of the old array to the new array.

The key to solving the array problem is to have a deeper understanding of the data structure of the array. At the same time, you also need to understand the common programming structures such as loops, recursion, and basic operators. Here are some common array programming interview questions:

1. How to search for missing elements in an integer array with elements from 1 to 100?

  • Solution: http://javarevisited.blogspot.com/2014/11/how-to-find-missing-number-on-integer-array-java.html

2. Given an array, how to search for duplicate elements?

  • Solution: http://javarevisited.blogspot.com/2014/01/how-to-remove-duplicates-from-array-java-without-collection-API.html

3. Given an out-of-order array, how to search for the largest and smallest elements?

  • Solution: http://java67.blogspot.com/2014/02/how-to-find-largest-and-smallest-number-array-in-java.html

4. Given a value, how to search for the paired elements in an integer array whose sum is the value?

  • Solution: http://javarevisited.blogspot.com/2014/08/how-to-find-all-pairs-in-array-of-integers-whose-sum-equal-given-number-java.html

5. If the array contains multiple duplicate values, how to search for all duplicate values?

  • Solution: http://javarevisited.blogspot.com/2014/03/3-ways-to-find-first-non-repeated-character-String-programming-problem.html

6. Given an array, how to delete duplicate elements in Java? How to remove duplicate elements in an array without using the library?

  • Solution: http://javarevisited.blogspot.com/2014/01/how-to-remove-duplicates-from-array-java-without-collection-API.html

7. How to sort an integer array using the quick sort algorithm?

  • Solution: http://javarevisited.blogspot.com/2014/08/quicksort-sorting-algorithm-in-java-in-place-example.html

8. How to reverse an array using Java?

  • Solution: http://javarevisited.blogspot.com/2013/03/how-to-reverse-array-in-java-int-String-array-example.html

These problems not only help us improve our ability to solve problems, but also improve our understanding of array data structures.

If you need to learn more about array-based in-depth issues, you can find more courses and materials about data structures on GitHub or Coursera. For example, there are a lot of learning materials about arrays in GitHub. Below we introduce one A Chinese version of Google’s interview materials, it has more than 60,000 collections on GitHub.

Project address: https://github.com/jwasham/coding-interview-university/blob/master/translations/README-cn.md

2. Linked List Programming Interview Questions

Linked lists are another common data structure that supplements the array data structure. Similar to an array, it is also a linear data structure, storing elements in a linear manner.

However, unlike an array, it does not store elements in consecutive locations; instead, it stores them scattered in memory and connected to each other through nodes. The linked list is a list of nodes, where each node contains the stored value and the address of the next node.

Due to this structure, adding or deleting elements in the linked list becomes very simple, because you only need to change the link instead of creating an array, but this will make the search difficult, and often requires O(n) time complexity. An element is found in a single linked list.

This article (https://javarevisited.blogspot.com/2013/07/difference-between-array-and-linked-list-java.html) provides more information about the differences between array and linked list data structures.

There are also many variants of linked lists, such as singly linked lists, which allow you to traverse in one direction (forward or reverse); double-linked lists allow you to traverse in two directions (forward or backward); the last is circular linked lists, It forms a loop.

To solve problems about linked lists, it is important to master recursive knowledge, because linked lists are recursive data structures.

If you take a node from the linked list, the remaining data structure is still a linked list. Therefore, the recursive solution of many linked list problems is simpler than iterative solutions.

The following are some common problems and solutions about linked lists:

9. How to find the middle element of the singly linked list in one pass?

  • Solution: http://javarevisited.blogspot.sg/2012/12/how-to-find-middle-element-of-linked-list-one-pass.html

10. How to check whether a given linked list contains cycles? How to find the starting node of the loop?

  • Solution: http://javarevisited.blogspot.sg/2013/05/find-if-linked-list-contains-loops-cycle-cyclic-circular-check.html

11. How to reverse a linked list?

  • Solution: http://www.java67.com/2016/07/how-to-reverse-singly-linked-list-in-java-example.html

12. How to reverse a singly linked list without recursion?

  • Solution: http://javarevisited.blogspot.sg/2017/03/how-to-reverse-linked-list-in-java-using-iteration-and-recursion.html

13. How to delete duplicate nodes in the disorderly linked list?

  • Solution: https://www.geeksforgeeks.org/remove-duplicates-from-an-unsorted-linked-list/

14. How to measure the length of a singly linked list?

  • Solution: http://javarevisited.blogspot.sg/2016/05/how-do-you-find-length-of-singly-linked.html

15. How to find the third node from the end of the singly linked list?

  • Solution: http://javarevisited.blogspot.sg/2016/07/how-to-find-3rd-element-from-end-in-linked-list-java.html

16. How to use the stack to calculate the sum of two linked lists?

  • Solution: https://www.geeksforgeeks.org/sum-of-two-linked-lists/

These questions help you develop problem-solving skills and improve your understanding of linked list data structures. There are many resources available to help us understand linked lists. For example, in an interactive coding practice on GitHub, it uses Jupyter Notebook to provide various exercises on data structures and algorithms, including many linked list problems and practices.

Project address: https://github.com/donnemartin/interactive-coding-challenges

3. String encoding interview questions

In addition to arrays and linked list data structures, strings are another hot topic in programming job interviews. Most of the coding interviews I participated in have asked questions about strings. 5 tricky String interview questions , I recommend you to read them.

If you understand arrays, then you can easily solve string-based problems, because a string is an array of characters. Therefore, all the skills you learn by solving array programming problems can also be used to solve string programming problems.

The following is a list of string programming questions frequently asked in programming job interviews:

17. How to print repeated characters in a string?

  • Solution: http://java67.blogspot.sg/2014/03/how-to-find-duplicate-characters-in-String-Java-program.html

18. How to check whether two strings are in reverse order?

  • Solution: http://javarevisited.blogspot.sg/2013/03/Anagram-how-to-check-if-two-string-are-anagrams-example-tutorial.html

19. How to print the first non-repeated character in a string?

  • Solution: http://javarevisited.blogspot.sg/2014/03/3-ways-to-find-first-non-repeated-character-String-programming-problem.html

20. How to reverse a given string using recursion?

  • Solution: http://javarevisited.blogspot.sg/2012/01/how-to-reverse-string-in-java-using.html

21. How to check whether a string contains only numbers?

  • Solution: http://javarevisited.blogspot.sg/2012/10/regular-expression-example-in-java-to-check-String-number.html

22. How to search for repeated characters in a string?

  • Solution: http://java67.blogspot.sg/2014/03/how-to-find-duplicate-characters-in-String-Java-program.html

23. Given a string, how to count the number of vowels and consonants?

  • Solution: http://java67.blogspot.sg/2013/11/how-to-count-vowels-and-consonants-in-Java-String-word.html

24. Given a character, like counting the number of times it appears in a string?

  • Solution: http://javarevisited.blogspot.sg/2012/12/how-to-count-occurrence-of-character-in-String.html

25. How to search for all permutations of a string?

  • Solution: http://javarevisited.blogspot.com/2015/08/how-to-find-all-permutations-of-string-java-example.html

26. How to reverse the words in a given sentence without using any library?

  • Solution: http://java67.blogspot.com/2015/06/how-to-reverse-words-in-string-java.html

27. How to check whether two strings are rotations?

  • Solution: http://www.java67.com/2017/07/string-rotation-in-java-write-program.html

28. Given a string, how to check whether it is a palindrome?

  • Solution: http://java67.blogspot.com/2015/06/how-to-check-is-string-is-palindrome-in.html

These questions can improve your understanding of string data structures. If you can solve all these string problems independently, you are in good shape.

If you want to learn more about more complex problems, I recommend you to read Steven Skiena's "The Algorithm Design Manual", this book contains the most difficult algorithm problems.

The PDF version of the book is also available online, download address: http://citeseerx.ist.psu.edu/viewdoc/download?doi=10.1.1.471.4772&rep=rep1&type=pdf

If you need more practice, here are another 20 questions about string programming:

http://javarevisited.blogspot.sg/2015/01/top-20-string-coding-interview-question-programming-interview.html

4. Binary tree programming interview questions

Now we only understand the problem of linear data structure, but all the information in the real world cannot be all linear, which requires a tree data structure.

The tree data structure allows data to be stored in a hierarchical form. According to the way of storing data, there are many types of trees, such as binary trees.

Like its close relative, binary search tree, it is also one of the most popular tree data structures. Therefore, you will see many related and interesting questions. For example, how to traverse the tree, count the number of nodes, find out the depth, and check for balance.

The key to solving the binary tree problem lies in deep theoretical knowledge, such as the size or depth of the binary tree, what is a leaf node, what is a node, and understanding popular traversal algorithms.

The following are the common binary tree-related programming questions in software engineer or development job interviews:

29. How to implement a binary search tree?

  • Solution: http://javarevisited.blogspot.sg/2015/10/how-to-implement-binary-search-tree-in-java-example.html#axzz4wnEtnNB3

30. How to perform preorder traversal on a given binary tree?

  • Solution: http://javarevisited.blogspot.sg/2016/07/binary-tree-preorder-traversal-in-java-using-recursion-iteration-example.html#axzz5ArdIFI7y

31. How to perform preorder traversal on a given binary tree without recursion?

  • Solution: http://www.java67.com/2016/07/binary-tree-preorder-traversal-in-java-without-recursion.html

32. How to perform in-order traversal of a given binary tree?

  • Solution: http://www.java67.com/2016/08/binary-tree-inorder-traversal-in-java.html

33. How to print all nodes by performing an in-order traversal on a given binary tree without recursion?

  • Solution: http://www.java67.com/2016/08/binary-tree-inorder-traversal-in-java.html

34. How to implement the post-order traversal algorithm?

  • Solution: http://www.java67.com/2016/10/binary-tree-post-order-traversal-in.html

35. How to perform post-order traversal on a given binary tree without recursion?

  • Solution: http://www.java67.com/2017/05/binary-tree-post-order-traversal-in-java-without-recursion.html

36. How to print all leaf nodes of a binary search tree?

  • Solution: http://www.java67.com/2016/09/how-to-print-all-leaf-nodes-of-binary-tree-in-java.html

37. How to calculate the number of leaf nodes in a given binary tree?

  • Solution: http://javarevisited.blogspot.sg/2016/12/how-to-count-number-of-leaf-nodes-in-java-recursive-iterative-algorithm.html

38. How to perform a binary search in a given array?

  • Solution: http://javarevisited.blogspot.sg/2015/10/how-to-implement-binary-search-tree-in-java-example.html#axzz4wnEtnNB3

If you think that you have insufficient knowledge of binary tree programming to solve these problems, I suggest you to master data structure and algorithm knowledge first, for example, you can take this course "From 0 to 1: Data Structures & Algorithms in Java". Similarly, you can also refer to a complete set of manuals for preparing for Google interviews. This set of GitHub manuals has been introduced before, but it really has a lot of cases and tutorials on data structures such as binary trees.

Project address: https://github.com/jwasham/coding-interview-university

If you need more recommendations, you can refer to:

  • http://javarevisited.blogspot.sg/2015/07/5-data-structure-and-algorithm-books-best-must-read.html

  • http://javarevisited.blogspot.sg/2018/01/top-5-free-data-structure-and-algorithm-courses-java—c-programmers.html

5. Other programming interview questions

In addition to data structure questions, most programming job interviews will also ask questions about algorithms, design, bit operations, and general logic. Paying attention to the WeChat public account Java technology stack can also get the N algorithm and data structure tutorials I have compiled, all of which are dry goods.

Targeted exercises are important because sometimes they can be a bit difficult to understand in actual interviews. Practice beforehand will not only familiarize you with these questions, but also make you more confident when explaining the answers to the interviewer.

39. How to realize the bubble sort algorithm (bubble sort algorithm)?

  • Solution: http://javarevisited.blogspot.sg/2014/08/bubble-sort-algorithm-in-java-with.html#axzz5ArdIFI7y

40. How to implement iterative quicksort algorithm?

  • Solution: http://javarevisited.blogspot.sg/2016/09/iterative-quicksort-example-in-java-without-recursion.html#axzz5ArdIFI7y

41. How to implement insertion sort algorithm (insertion sort algorithm)?

  • Solution: http://www.java67.com/2014/09/insertion-sort-in-java-with-example.html

42. How to implement merge sort algorithm (merge sort algorithm)?

  • Solution: http://www.java67.com/2018/03/mergesort-in-java-algorithm-example-and.html

43. How to implement the bucket sort algorithm (bucket sort algorithm)?

  • Solution: http://javarevisited.blogspot.sg/2017/01/bucket-sort-in-java-with-example.html

44. How to implement counting sort algorithm (counting sort algorithm)?

  • Solution: http://www.java67.com/2017/06/counting-sort-in-java-example.html

45. How to implement the radix sort algorithm?

  • Solution: http://www.java67.com/2018/03/how-to-implement-radix-sort-in-java.html

46. ​​How to exchange two numbers without using the third variable?

  • Solution: http://www.java67.com/2015/08/how-to-swap-two-integers-without-using.html

47. How to confirm whether two rectangles overlap?

  • Solution: http://javarevisited.blogspot.sg/2016/10/how-to-check-if-two-rectangle-overlap-in-java-algorithm.html

48. How to design a vending machine?

  • Solution: http://javarevisited.blogspot.sg/2016/06/design-vending-machine-in-java.html

If you want to see more such programming questions, you can read this book "Cracking the Coding Interview: 189 Programming Questions and Solutions", which is suitable for preparing for a programming job interview in a short time.

Download link: http://lib1.org/_ads/fcb49f53d5e943ce8acdc4469f63dc5d

The more questions you practice, the more prepared you will be. Therefore, if you think 48 questions are not enough, you can check:

  • https://javarevisited.blogspot.com/2015/02/50-programmer-phone-interview-questions-answers.html

  • http://javarevisited.blogspot.sg/2016/06/top-5-books-for-programming-coding-interviews-best.html

  • http://javarevisited.blogspot.sg/2018/02/10-courses-to-prepare-for-programming-job-interviews.html

Now you are ready for the interview

This part will introduce some common problems other than data structures and algorithms, which can help you achieve better performance in the interview.

There are many such questions in my blog, please see: http://www.java67.com/

These common programming, data structure and algorithm problems are what you must know when you go to any company for an interview, whether it is a large company or a small company, regardless of the position of the interview.

If you are looking for programming or software development work, then you can use these programming questions to get started. This list provides some good interview preparation topics that can help you assess whether your interview preparation is adequate.

Proficiency in data structure and algorithm knowledge is the key to successful programming job interview, you should pay more attention to these issues.

Pay attention to the Java technology stack to see more dry goods

Click the original text to get more benefits!

Guess you like

Origin blog.csdn.net/youanyyou/article/details/108480375