DEV Community

Cover image for 100+ Programming and Coding Questions for Technical Interviews
javinpaul
javinpaul

Posted on • Edited on

100+ Programming and Coding Questions for Technical Interviews

Disclosure: This post includes affiliate links; I may receive compensation if you purchase products or services from the different links provided in this article.

Hello folks, if you are preparing for your next Software Development Job interview and looking for frequently asked Coding or Programming questions to practice then you have come to the right place.

In the past, I have shared many questions on topics like System Design, Dynamic Programming, SQL and Database, and Linux and this article, I am going to share some of the most commonly asked Coding questions from past Programming Job interviews.

In order to do well on the Coding interview you need practice, you just can't go there and try to solve the coding problems in a limited time, that's actually one of the most common reasons to fail your programming Job interviews. 

Sometimes, the interviewer also asks a little bit easier coding questions on a telephonic interview like revering array in place or reversing a string in place.

Talking from my own experience, when you hear these coding questions very first time in the real interview, most of us stumble because of nervousness and lack of preparation and that's where knowledge of popular coding questions and how to solve them is important for any Software engineer.

Most of the coding questions are based upon System Design and data structures like an array, string, linked list, binary tree, etc, but sometimes you also get algorithmic, tricky, logical, and scenario-based questions like how to swap two integers without using a temp variable or how to check if two rectangles overlap on each other or not, which is also a popular technique for collision detection and frequently used in games to check if two object collided or not.

That's why I have divided this list of coding problems into six categories , I mean array-based coding questions, string-based questions, linked list questions, binary tree questions, System Design Questions, and other miscellaneous questions, where you will find questions on bit manipulation, software design, tricky, logical and other miscellaneous topics.

Btw, solid knowledge of Data Structure and Algorithm is essential, and even though you will learn a lot of new concepts by solving these questions, I suggest you first refresh your knowledge of Data Structure and algorithms before attempting these questions by joining a comprehensive course like Data Structures and Algorithms: Deep Dive Using Java on Udemy.

Data Structure and Algorithm cheat sheet

There is no point in attempting these questions if you don't have sufficient knowledge of data structure and Algorithms, for example you don't know how much time it take to get an element from array if you know index.


100 Programming, Software Design and Coding Interview Questions for Technical Interviews

Here is my list of some of the most popular coding questions and system design questions to crack any programming job interview.

The questions are more like you find in the popular book Cracking the Coding Interview by Gayle Lakmann Mcdowell,  one of the essential books to do well on a Job interview, but more focus on Data Structure and Coding rather than touching every single possible topic required for a programming job interview like SQL, UNIX, Database, Networking, etc, for that, you need to read books and you can find many good titles here.

We'll start the list by first exploring array-based questions like finding pairs whose sum is given a number and then move to string-based questions, linked list-based questions, binary tree questions, and finally tackler other topics.

1. Array-based Programming Interview Questions

If you ask me just one topic to prepare really well for coding interviews, I would pick the array. It's one of the essential data structures and favorite darling of coding interviews.

There are so many popular coding interview questions that are based upon the array, some of them are easy and some are tough but you can be sure that you will see some questions based upon the array in your next programming job interview.

If you don't know, an array is a data structure that holds other objects like String, int, float, etc. It holds them in a contiguous location in memory which makes them easily searchable and retrieval in O(1) time using the index.

Insertion and deletion of an array are tough because you cannot change the size of an array once created and you need to create a new array and copy elements from old to new.

Things to remember before you attempt array based coding problems:

  1. array elements are stored at contiguous location.
  2. time complexity to get element from array is O(1) with index
  3. adding and removing element from array is difficult because array is fixed size and adding more element means allocating new array and then copying all data from one to other array.
  4. array are good for search
  5. array is used in many data structure like Hash table, stack, or queue.

Anyway, here are some of the most popular array-based coding interview questions for your preparation:

1. How to find the missing number in a given integer array of 1 to 100? (solution)

2. How to find the duplicate number on a given integer array? (solution)

3. How to find the largest and smallest number in an unsorted integer array? (solution)

4. How to find all pairs of integer arrays whose sum is equal to a given number? (solution)

5. How to find duplicate numbers in an array if it contains multiple duplicates? (solution)

6. How to remove duplicates from a given array in Java? (solution)

7. How to sort an integer array in place using the QuickSort algorithm? (solution)

8. How to remove duplicates from an array in place? (solution)

9. How to reverse an array in place in Java? (solution)

10. How to find multiple missing numbers in a given integer array with duplicates? (solution)

I have linked all the solutions but you should try to solve them by yourself before looking at the solution, especially if you have time. That's the only sure way to learn to program by solving these coding questions.

If you find these questions difficult to solve then once again I suggest you first refresh your knowledge of fundamental data structures like an array by going through a comprehensive course. If you need recommendations, Master the Coding Interview: Data Structures + Algorithms* and Master the Coding Interview: System Design + Architecture on ZTM Academy are two of the best course to start with. You will also learn about Big(O) notation and how to calculate time and space complexity.

Array based Programming Interview Questions Answers

If you think these 10 questions from the array are not enough and you are interested in solving more array-based programming problems then you can also check out these 30 array-based coding questions for more practice.


2. String-based Coding Interview Questions

After array, String is the next popular topic on Programming job interviews, but if you have a good understanding of array then you can easily deal with String programming questions because String is nothing but a character array.

The string is implemented differently in a different programming language like in C it's a NULL-terminated character array but in Java, it's an object. However, you can still get access to the underlying array to apply your logic.

Things to remember before solving String questions

  1. String is like a character array so you can apply most of the tricks you learn while solving array problem with string by converting it to character array.
  2. String is Immutable in Java which means adding or removing character create new String, better use StringBuilder which provides mutable string.

Here is a list of some of the frequently asked coding questions which are based on String. Though some of them are quite old, you can still expect this in your programming job interview:

11. How to Print duplicate characters from String? (solution)

12. How to check if two Strings are anagrams of each other? (solution)

13. How to print the first non-repeated character from String? (solution)

14. How to reverse a given string using recursion? (solution)

15. How to check if a string contains only digits? (solution)

16. How to find duplicate characters in a String? (solution)

17. How to count a number of vowels and consonants in a given String? (solution)

18. How to count the occurrence of a given character in String? (solution)

19. How to find all permutations of String? (solution)

20. How to reverse words in a given sentence without using any library method? (solution)

21. How to check if two String is a rotation of each other? (solution)

22. How to check if the given String is Palindrome? (solution)

Similar to an array, I have also linked to a solution for all of these String problems but if you want to get most of this article, you better solve these questions without looking at the answers. Only when you are stuck and running out-of-time, you can look at the solution.

And, if you find these frequently asked String problems difficult to solve, maybe it's time to go back to the drawing board and learn the fundamentals of String data structure again.  If you need resources then Data Structures and Algorithms Specialization on Coursera is one of the best online resources you can use to make your foundations rock solid.

Top 50 Coding Interview Questions

You can also learn from it by comparing your solution with the solution I have given. It's not necessarily to be the same but you can learn a lot by comparing them and if you need more practice, here is another list of 20 String algorithm questions.


3. Linked list based Programming Interview Questions

Along with array and string, a linked list is another popular data structure in the programming world as well as on coding interviews.

You will find a lot of questions on a linked list like reversing a linked list, adding a new element, removing an element from the middle, etc.

It's also the counterpart of an array data structure. While array stores elements on contiguous memory locations, the linked list stores them at different locations and finds them by storing their address. a linked list is made of nodes, an internal data structure that holds the value as well as the address of the next node.

Because of its structure, it's easier to add and remove elements from the linked list like on O(1) time if you are adding or removing from the head but the search is equally difficult and takes O(n) time, as you have to literally walk through each element.

Things to remember before solving LinkedList questions:

  1. LinkedList is a recursive data structure which means you can use recursion and stack to solve most of LinkedList problems.
  2. It's easy to add/remove from LinkedList but search is difficult takes O(n) time where n is number of nodes in linked list.
  3. There are many types of linked list like singly and doubly linked list which contains two pointers to both next and previous nodes.
  4. LinkedList uses memory more efficiently than array which means you can create a big LinkedList with scattered memory where a big array is not possible.

Anyway, here is a collection of some of the simple and tricky linked list based coding questions for your practice:

23. How to find the middle element of a singly linked list in one pass? (solution)

24. How to check if a given linked list contains a cycle? How to find the starting node of the cycle? (solution)

25. How to reverse a linked list? (solution)

26. How to reverse a single linked list without recursion? (solution)

27. How to remove duplicate nodes in an unsorted linked list? (solution)

28. How to find the length of a singly linked list? (solution)

29. How to find the 3rd node from the end in a singly linked list? (solution)

30. How do you find the sum of two linked lists using Stack? (program)

Similar to array and string, I have also linked to all the solutions but you should only look at them once you solved the problem on your own or you feel stuck.

A key to solving the linked list is a good understanding of recursion because a linked list is a naturally recursive data structure, for example, if you take one node out of the linked list, the result is another linked list, but many programmers struggle to understand recursion.

That was the case with me as well but after practice and visualizing how recursion really works, I overcome that deficiency.

If you are in the same boat, I strongly suggest you go through a visual course like Visualizing Data Structures and Algorithms in Java to learn Recursion and data structure. That will help you a lot in your thought process and problem-solving skills.

Top 99 Programming Interview Questions and Solutions

Once you understand recursion, most of the linked list based problems have an easy recursive solution than their iterative version.

And if you need more practice, here is another list of 30 linked list programming questions for your reference.


4. Binary Tree-based Coding Interview Questions

A tree is another popular data structure in the programming world and coding interviews. Unlike array and linked list, which are considered linear data structures, a tree is considered a hierarchical data structure and used to arrange information in hierarchical order.

There are a lot of different types of trees e.g. a binary tree, binary search tree, AVL tree, Red-Black tree, etc but Binary and Binary search trees are also known as BST are two of the most popular ones and most of the questions are based upon them.

Some questions are also based upon theoretical knowledge of tree data structure e.g. finding the height of the tree, finding leaf nodes, checking if the tree is balanced or not, etc, hence you should also spend some time learning the basics, along with practicing coding questions.

Things to remember before solving Tree based questions:

  1. Similar ot LinkedList, Tree is also recursive data structure which means you take one element from Tree and remaining is still a tree.
  2. You can use recursion and stack to solve many tree based coding problems.
  3. Tree is hierarchical data structure compared to array and linked list which are linear data structure.
  4. Binary tree has at most two children but can have one, zero, or two.
  5. Binary Search tree is a binary tree where value of left tree nodes are less than root and values of right sub-tree nodes are higher than root node.
  6. There are many tree traversal algorithms but divided in two main categories, depth first or level first, which means either you first go deep and cover every node in one path or you go level by level.

Anyway, here is a list of popular binary tree and binary search tree based coding questions to practice before your job interview:

30. Can you write a program to implement a binary search tree?  (solution)

31. How do you perform Pre-order traversal in a given binary tree? (solution)

32. Write a Program to traverse a given binary tree in Pre-order without recursion (solution)

33. How to perform an In order traversal in a given binary tree? (solution)

34. How to print all nodes of a given binary tree using inorder traversal without recursion (solution)

35. How to implement a Post-order traversal algorithm? (solution)

36. How to traverse a binary tree in Postorder traversal without recursion (solution)

37. How to Print all leaves of a binary search tree? (solution)

38. How to count a number of leaf nodes in a given binary tree? (solution)

39. How to perform a binary search in a given array? (solution)

40. How to merge two sorted array in Java? (solution)

Like an array, linked list, and string questions, I have also linked to all solutions for binary tree questions but you should only look at them once you have tried it yourself.

One trick I would like to share with you while solving tree questions is to remember that, similar to a linked list, the tree is also a recursive data structure and most of the tree based problems has an easy recursive solution.

For example, a subtree is also a tree which means you can apply the same steps to a subtree can devise a recursive solution. In the above list, many popular tree algorithms e.g. pre-order, post-order, in-order are implemented recursively as well as iterative.

If you don't feel confident to solve these problems and want to refresh your knowledge of binary tree and other data structure before attempting these questions, then you should check out Data Structures and Algorithms: Deep Dive Using Java from Udemy.

Top 75 Essential Programming Interview Questions to Crack Any Coding Interview


5. System Design Interview Questions

The following are the top System Design interview questions you can prepare before your next Interview. These are pretty basic question and as a developer you should already be familiar with them but if not then make sure you practice before going for any system design interview.

41. What is System Design?
Answer: System Design is a process of defining the elements of a system such as the modules, components, various interfaces and architecture.

42. How do you design a web crawler? (solution]
Answer: A web crawler service collects information/crawl from the entire internet and fetches millions of web documents. Things to keep in mind while designing a web crawler are:

  • The approach is taken to find new web pages
  • The approach to prioritize web pages that can change in a dynamic way
  • To ensure that the web crawler service is bounded on the same domain

You can try solving the question but if you stuck, I recommend you to checkout Grokking the System Design Interview course on Educative, it provides a step by step solution to not just this question but also other System design question.

Here is a nice system design diagram for web crawler:

Top 20 System Design Interview Questions With Answers

43. What are the three important skills of system designer?
Answer:

  • Good knowledge of Computer Fundamentals
  • Familiar with API Integration
  • User interaction
  • Familiar with how to deploy and scale systems

In general, System designer should have broad view of different technology and how they work and when to use them to make correct choices while designing system.

44. Which is the primary tool used for structured Design?
Answer: Structure charts is a primary tool used for structured Design.

45. How do you design YouTube?  [Solution]

Designing a YouTube is an interesting System design question as everyone is familiar with YouTube but a lot goes to design a video streaming service like YouTube.  There are a lot of challenges related to storing data, indexing data, and providing streaming service.

Scalability is another major challenge as it needs to be fast and should be able to support millions of users. You can start designing YouTube on your own but if you stuck or need guidance you can see this free tutorial by Alex Xu from his popular System Design Interview Course on ByteByteGo.

Here is a nice flow diagram to explain video upload process:

how to design YouTube for System Design interview

46. In System Design process, what is Requirements Determination?\
Answer: A requirement is most important for a new system which includes processing or capturing of data, controlling the activities of a business, producing information and supporting the management. Requirement determination helps you to study the existing system and to gather details to find out what are the requirements, how it works, and what kind of improvements should be made.

47. How do you design a URL Shortner like bit.ly or goo.gl?
This is another popular System design question which is often asked during FAANG interview. This question poses a lot of challenge like where are the short URL and target URL will be stored. How should you create a unique short URL every time for different target URL and return the same short URL for same target URL.

You can try solving this problem on your own but if you stuck then you can also checkout this step by step solution of URL shortner on DesignGuru, one of my favorite portal for preparing System design interview.

URL Shortner System Design Problem solution

If you like their teaching style, I also recommend you to checkout their* System Design Interview Bundle* where they share their best System design courses for discount.

48. How can you design autocomplete functionality?
Answer: Here are important things for developing autocomplete functionality:

  • Typeahead suggestion to be provided.
  • Queries per second handled by the system.
  • Support personalization with the suggestions.
  • Amount of data to be stored.

49. In the system design process, where is problem analysis done?\
Answer: Problem analysis is done at the systems analysis phase.

50. How is Horizontal scaling different from Vertical scaling in Software Engineering?\
Here is the key difference between Horizontal and Vertical scaling in Software engineering:

  • Horizontal scaling refers to the addition of more computing machines to the network that shares the processing and memory workload across a distributed network of devices. In simple words, more instances of servers are added to the existing pool and the traffic load is distributed across these devices in an efficient manner.
  • Vertical scaling refers to the concept of upgrading the resource capacity such as increasing RAM, adding efficient processors etc of a single machine or switching to a new machine with more capacity. The capability of the server can be enhanced without the need for code manipulation.

If you want to learn more about Scalability concepts then I highly recommend you to checkout Frank Kane's System Design Course on Udemy where he shared all these key System design concepts in detail.

software design interview questions with answers

51. What do you understand by load balancing? Why is it important in system design?
Answer: Load balancing refers to the concept of distributing incoming traffic efficiently across a group of various backend servers. These servers are called server pools. Modern-day websites are designed to serve millions of requests from clients and return the responses in a fast and reliable manner. In order to serve these requests, the addition of more servers is required. 

In such a scenario, it is essential to distribute request traffic efficiently across each server so that they do not face undue loads. Load balancer acts as a traffic police cop facing the requests and routes them across the available servers in a way that not a single server is overwhelmed which could possibly degrade the application performance.

52. What is Sharding?
Answer: Sharding is a process of splitting the large logical dataset into multiple databases. It also refers to horizontal partitioning of data as it will be stored on multiple machines. By doing so, a sharded database becomes capable of handling more requests than a single large machine. 

Consider an example - in the following image, assume that we have around 1TB of data present in the database, when we perform sharding, we divide the large 1TB data into smaller chunks of 256GB into partitions called shards.

53. What are the various Consistency patterns available in system design?\
Here is the list of popular consistency patterns for Software Design:

  • Consistency from the CAP theorem states that every read request should get the most recently written data. When there are multiple data copies available, there arises a problem of synchronizing them so that the clients get fresh data consistently. Following are the consistency patterns available:
  • Weak consistency: After a data write, the read request may or may not be able to get the new data. This type of consistency works well in real-time use cases like VoIP, video chat, real-time multiplayer games etc. For example, when we are on a phone call, if we lose network for a few seconds, then we lose information about what was spoken during that time.
  • Eventual consistency: Post data write, the reads will eventually see the latest data within milliseconds. Here, the data is replicated asynchronously. These are seen in DNS and email systems. This works well in highly available systems.
  • Strong consistency: After a data write, the subsequent reads will see the latest data. Here, the data is replicated synchronously. This is seen in RDBMS and file systems and are suitable in systems requiring transactions of data.

54. What are the most important aspects of the System Study?\
Answer: System Study has three most important aspects which are as follows:

  • Identifying current issues and establishing new goals.
  • Study of an existing system.
  • Documenting the existing system.

55. As a system designer, how you can design a universal file sharing and storage apps like Google Drive or Dropbox?
Answer: The above mention apps are used to store and share files, photos, and other media. We can design things like allowing users to upload/search/view files or photos. It checks permissions for file sharing and enables multiple users to make changes in the same document.

56. What feature allows one class to derive features from another class?
Answer: The Inheritance feature allows one class to derive features from another class. But more often than not you should use Composition to reuse code from another class instead of Inheritance.

Composition is flexible than Inheritance and there are many benefits of using Composition like easier to test. You can also see my post 5 Reasons to choose Composition over Inheritance for more details.

57. Which language was the first language to be developed as a purely object-oriented programming language?
Answer: Smalltalk was the first programming language to be developed as a purely object-oriented programming language. While there are many great programming language which support OOP like Java, C++, JavaScript, Python, and C#, none of them are pure object oriented programming language, if you think wearing a purist shoes.

58. How do you design a Trade position aggregator or Portfolio Manager?

You need to design a system which can accept Trade and then shows the position for each symbol, much like a Portfolio Manager. Your system needs to support multiple symbols and it should be fast enough to calculate position in real time. 

In order to test your system, you can input a set of trades, both buy and sell side and then query the system to see the live position. You can first try solving this problem yourself but if you stuck you can see my solution of implementing Trade position aggregator in Java for guidance. 

system design problems with solution

59. Which is an OOP language but does not support all inheritance types?
Java is an OOP programming language, but it does not support all inheritance types.

60. Name different types of constructors in C++ ?
There are three types of constructors in C++, which are as follows:

  • Default Constructors: It does not take any argument and has zero parameters.
  • Parameterized Constructors: These types of constructors take some argument.
  • Copy Constructors: It is a member function, and its basic function is to initialize the object using another object of the same class.

61. What is RAID? 
RAID stands for a redundant array of independent disks. RAID is the technology that specializes in data storage that combines various physical disk drive components within one or numerous logical units as data redundancy and performance improvement.

62. How do you design a Vending Machine in Java?
This is a common object oriented analysis and design question which is also asked on System design interview. You need to design a Vending Machine which can vend a couple of products like Coke, Biscuits, Chocolates,  and Cake. It can accept coins (Nickle, Dime, Pence, and Cent), and small denomination notes  

There are multiple ways to solve this problem but solution using State Design Pattern is the simplest one. You can try yourself but if you stuck you can also see my post How to design Vending Machine in Java for step by step solution of this OOP Design problem. 

system design questions with answers

63. Can a Java application be created without implementing the OOPs concept?
A Java application cannot be created without implementing the OOPs concept. Java applications are completely based on the Object-oriented programming concept.

64. What are the Types of Documentation in System Design?\
Answer: Four types of documentation are:

  • Program documentation
  • System documentation
  • Operations documentation
  • User documentation

6. Miscellaneous Programming Interview Questions

Even though data structure and System Design based questions make the bulk of the Coding Interview, there are always some questions from topics like sorting algorithms, bit manipulation, software design, Dynamic Programming, and other logical and tricky questions.

In this list below, you will find most of the common searching and sort questions as well as a couple of design and bit manipulation questions.

65. How to implement the Bubble Sort algorithm? (solution)

66. How to implement Iterative QuickSort Algorithm? (solution)

67. How to implement the Insertion Sort Algorithm? (solution)

68. How to implement Merge Sort Algorithm? (solution)

69. How to implement the Bucket Sort Algorithm? (solution)

70. How to implement the Counting Sort Algorithm? (solution)

71. How to implement Radix Sort Algorithm? (solution)

72. How to swap two numbers without using the third variable? (solution)

73. How to check if two rectangles overlap with each other? (solution)

74. How to design a Vending Machine? (solution)

75. How to implement an LRU Cache in your favorite programming language? (solution)

76. How to check if a given number is a Palindrome? (solution)

77. How do you check if a given number is an Armstrong number? (solution)

78. How do you find all prime factors of a given number? (solution)

79. How do you check if a given number is positive or negative in Java? (solution)

80. How to find the largest prime factor of a given integral number? (solution)

81. Write a Program to print all prime numbers up to a given number? (solution)

82. Write a Program to print Floyd's triangle? (solution)

83. Write a Program to print Pascal's triangle? (solution)

84. How to calculate the square root of a given number? (solution)

85. How to check if the given number is a prime number? (solution)

86. How to implement the Sieve of Eratosthenes Algorithm? (solution)

87. How to add two numbers without using the plus operator in Java? (solution)

88. Write a Program to subtract two binary numbers? (solution)

89. Write a Program to transpose a Matrix? (solution)

90. Write a Program to add or subtract two Matrices? (solution)

91. Write a Program to multiply two Matrices in Java? (solution)

92. How to calculate the average of all numbers in a given array? (solution)

93. How to check if a given number is even/odd without using an Arithmetic operator? (solution)

94. Write a Program to find the GCD of two numbers using Euclid's Algorithm? (solution)

95.  How to find the number of 1s (the Set bit) in a given Bit Sequence? (solution)

96. Write a Program to a given Pyramid structure? (solution)

97. How to find the highest repeating world from a given file in Java? (solution)

98. How to reverse a given Integer in Java? (solution)

99. How to convert a decimal number to binary in Java? (solution)

100. How to check if a given year is a leap year in Java? (solution)

Like previous topics, I have provided links to a solution but you should only look at them once you tried to solve the questions yourself. That's important for learning.

That's all about some of the essential Programming and Coding Interview questions to crack any programming Job interview. This list covers the most important topics like an array, string, linked list, binary tree, and several others.

Once you have gone through all these coding questions, you can not only solve them when you see them in the interview but also develop the coding sense and problem-solving ability which will help you to solve new and slightly modified versions of these questions in real programming interviews.

Though, if you are not in a rush and want to hone your coding skill further, here are some more resources to practice questions

Some Useful Resources for Coding Interviews

P.S. - As I have said before, good knowledge of data structure and algorithms is the most important thing to do well on interviews, and if you feel that you have forgotten those concepts or want to fill gaps in your understanding, here are a useful list of books and courses to learn Data Structure and Algorithms.

Top comments (2)

Collapse
 
gloriajoycee profile image
Joyce Gloria

I'm glad the question base is helpful for your software developer interview preparation.
Here are a couple of interview questions relevant to get hired as a developer in 2024:

  1. What is your experience developing a real-time chat application?
  2. How to GenAI for Software Development in 2024?
Collapse
 
bestinterviewquestions123 profile image
Best Interview Question

Hey, a good set of questions. Here are few more questions from best interview question which might help!