20+ Linked List Interview Questions for Java, C++, and Python Programmers
Tags: java, programming, career
Published: 2019-07-25 15:31:38

---
title: 20+ Linked List Interview Questions for Java, C++, and Python Programmers
published: true
description: A collection of frequently asked linked list interview questions from Programming Job interviews for beginners and experienced Java, C++, and Python Programmers. 
tags: beginners,java,programming,career
cover_image: https://thepracticaldev.s3.amazonaws.com/i/kr0zywxh4qkf3rg2h1ia.png 
---
*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 all, I have been sharing a lot of coding interview questions for Programmers who are actively looking for Job as Java, Python or C++ developers,  particularly beginners, junior developers, and computer engineers who have just graduated and has no real job experience.

In the past, I have shared some [data structure questions](https://dev.to/javinpaul/50-data-structure-and-algorithms-problems-from-coding-interviews-4lh2), [string algorithms problems](https://dev.to/javinpaul/top-20-string-coding-problems-from-programming-job-interviews-493m), and some useful [online courses](https://hackernoon.com/10-data-structure-algorithms-and-programming-courses-to-crack-any-coding-interview-e1c50b30b927) to prepare for Programming Job Interview and today I am going to share a list of **frequently asked linked list problems from coding interviews**.

Data Structures are one of the most important parts of any programming Job interview and often the reason to select or reject a candidate, that's why reviewing and practicing these [data structure based problems](http://www.java67.com/2018/05/top-75-programming-interview-questions-answers.html) will give you an edge over your competitor.

It will also make you a better programmer because you develop logic and coding sense while solving these problems which goes a long way in your programming career.

Solving these coding problems not only help you learn your programming languages and your tools better but also hone your problem solving skill which is very important for any professional developer. 

After all you need to improve your problem solving skill to such an extent that you can solve any unknown problem and convert that into code, practicing these problems help you to achieve that goal. 

## What is a linked list?
A [linked list](http://www.java67.com/2017/06/5-difference-between-array-and-linked.html) is another common data structure that complements the array data structure. Similar to the array, it is also a linear data structure and stores elements in a linear fashion.

However, unlike the [array](http://www.java67.com/2014/08/what-is-array-data-structure-in-java.html), it doesn't store them in contiguous locations; instead, they are scattered everywhere in memory, which is connected to each other using nodes.

> **A linked list is nothing but a list of nodes** where each node contains the value stored and the address of the next node.

Because of this structure, **it's easy to add and remove elements in a linked list**, as you just need to change the link instead of creating the [array](https://javarevisited.blogspot.com/2015/06/top-20-array-interview-questions-and-answers.html), but the search is difficult and often requires O(n) time to find an element in the singly linked list.

Here are some important properties of a linked list data structure:

1. Linked list is a recursive data structure which means you can use recursion to solve linked list based problems.

2. In linked list, each node has address of next node in the list, which means you don't need a big chunk of contiguous memory like array to create a long linked list. You can still create them with scattered memory. 

3. It's easier to add or remove elements in linked list as you just need to remove or repoint the link unlike array where you need to shift elements. Adding an element to head takes O(1) time. 

4. Searching is difficult in linked list and it takes O(n) time to search a list because you need to traverse the list to reach to target node. 

This [article](http://javarevisited.blogspot.sg/2013/07/difference-between-array-and-linked-list-java.html) provides more information on the difference between an array and linked list data structures.

It also comes in varieties like a singly linked list, which allows you to traverse 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.


##How to solve linked list Coding Problems?
In order to solve linked list-based questions, a good knowledge of [recursion](https://javarevisited.blogspot.com/2017/03/how-to-reverse-linked-list-in-java-using-iteration-and-recursion.html) is 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](https://javarevisited.blogspot.com/2017/04/recursive-binary-search-algorithm-in-java-example.html) than iterative ones.

They are also solved using divide-and-conquer techniques, which break the problem into sub-problems until you can solve them.

> For example, to reverse a linked list, you break the linked list until you have got just one node, at that point, you know how to reverse that linked list of one node, it's nothing but the same node.

It's very similar to recursion and actually, that smallest sub-problem you can solve becomes the base case for recursive solutions.

Btw, there is no point in solving these linked list-based coding problems if you don't have basic knowledge of data structure or you have not refresh them in recent times. In that case, I suggest you first go through good [data structure and algorithm courses](https://javarevisited.blogspot.com/2018/11/top-5-data-structures-and-algorithm-online-courses.html) or [book](https://javarevisited.blogspot.com/2015/07/5-data-structure-and-algorithm-books-best-must-read.html) to revise the concept.

If you need recommendations, the following are some of my the tried and tested resources to learn Data Structure and Algorithms in-depth:

1.  [**Data Structures and Algorithms: Deep Dive Using Java**](https://click.linksynergy.com/fs-bin/click?id=JVFxdTr9V80&subid=0&offerid=323058.1&type=10&tmpid=14538&RD_PARM1=https%3A%2F%2Fwww.udemy.com%2Fdata-structures-and-algorithms-deep-dive-using-java%2F) for Java developers
2.  [**Algorithms and Data Structures in Python**](https://click.linksynergy.com/deeplink?id=JVFxdTr9V80&mid=39197&murl=https%3A%2F%2Fwww.udemy.com%2Falgorithms-and-data-structures-in-python%2F) for those who love Python
3.  [**JavaScript Algorithms and Data Structures Masterclass**](https://click.linksynergy.com/fs-bin/click?id=JVFxdTr9V80&subid=0&offerid=508237.1&type=10&tmpid=14538&RD_PARM1=https%3A%2F%2Fwww.udemy.com%2Fjs-algorithms-and-data-structures-masterclass%2F)by Colt Steele for JavaScript programmers
4.  [**Mastering Data Structures & Algorithms using C and C++**](https://click.linksynergy.com/deeplink?id=JVFxdTr9V80&mid=39197&murl=https%3A%2F%2Fwww.udemy.com%2Fdatastructurescncpp%2F) for those who are good at C/C++
5.  [**Data Structures in Java: An Interview Refresher**](https://www.educative.io/collection/5642554087309312/5724822843686912?affiliate_id=5073518643380224)to refresh important Data Structure and algorithms concepts in Java.

And, if you prefer books, there is no better than [**Introduction to Algorithms**](http://www.java67.com/2015/09/top-10-algorithm-books-every-programmer-read-learn.html) by Thomas H. Cormen. It's one of the most comprehensive books on Data Structure and Algorithms and useful for level programmers and software developers.

[![](https://miro.medium.com/max/665/1*OL5fM3TITTEkpbyDjWK9tQ.png)](https://www.amazon.com/Introduction-Algorithms-Edition-Thomas-Cormen/dp/0262033844?tag=javamysqlanta-20)





##20+ Frequently asked linked list Problems from Coding Interviews
Without wasting any more of your time, here are some of the most common and popular linked list interview questions from Coding interviews. I have linked to the solution wherever possible but I suggest you first try to solve the problem on your own, that will benefit you because you will think and learn. Once you have solved the problem or stuck after trying, you can look at the solution and learn from them.

1.  **How do you find the middle element of a singly linked list in one pass? (**[**solution**](http://javarevisited.blogspot.sg/2012/12/how-to-find-middle-element-of-linked-list-one-pass.html)**)**

2.  **How do you 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)**)**

3.  **How are duplicate nodes removed in an unsorted linked list? (**[**solution**](https://www.geeksforgeeks.org/remove-duplicates-from-an-unsorted-linked-list/)**)**

4.  **How do you find the length of a singly linked list? (**[**solution**](http://javarevisited.blogspot.sg/2016/05/how-do-you-find-length-of-singly-linked.html)**)**

5.  **How do you check if a given linked list contains a cycle? How do you find the starting node of the cycle? (**[**solution**]
(http://javarevisited.blogspot.sg/2013/05/find-if-linked-list-contains-loops-cycle-cyclic-circular-check.html)**)**

6.  **How do you reverse a linked list? (**[**solution**](http://www.java67.com/2016/07/how-to-reverse-singly-linked-list-in-java-example.html)**)**

7.  **How do you find the third node from the end in a singly linked list? (**[**solution**](http://javarevisited.blogspot.sg/2016/07/how-to-find-3rd-element-from-end-in-linked-list-java.html)**)**

8.  **How do you find the sum of two linked lists using Stack? (**[**solution**](https://www.geeksforgeeks.org/sum-of-two-linked-lists/)**)**

9.  **How do you reverse a linked list in place? (solution)**
(http://www.java67.com/2017/06/5-difference-between-array-and-linked.html)**)**

10. **How to remove Nth Node from the end of a linked list? (**[**solution**](https://leetcode.com/problems/remove-nth-node-from-end-of-list/solution/)**)**

11. **How to merge two sorted linked lists? (solution)**

12. **How to add an element at the middle of the linked list? (solution)**

13. **How do you sort a linked list in Java? (**[**solution**](http://www.java67.com/2016/02/how-to-sort-linkedlist-in-java-example.html)**)**

14. **What is the difference between array and linked list? (**[**answer**]

15. **How to convert a sorted list to a binary search tree? (**[**solution**](https://leetcode.com/problems/convert-sorted-list-to-binary-search-tree/solution/)**)**

16. **Given a linked list and a value *x*, partition it such that all nodes less than *x* come before nodes greater than or equal to *x*. (**[**solution**](https://leetcode.com/problems/partition-list/solution/)**)**

17. **How to remove all elements from a linked list of integers that match with the given value? (solution)** 

18. **How to find the node at which the intersection of two singly linked lists begins. (**[**solution**](https://leetcode.com/problems/intersection-of-two-linked-lists/solution/)**)**

19. **How to check if a given linked list is a palindrome? (solution)**

20. **How to remove duplicates from a sorted linked list? (**[**solution**](https://leetcode.com/problems/remove-duplicates-from-sorted-list/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**](https://click.linksynergy.com/fs-bin/click?id=JVFxdTr9V80&subid=0&offerid=323058.1&type=10&tmpid=14538&RD_PARM1=https%3A%2F%2Fwww.udemy.com%2Fdata-structures-and-algorithms-deep-dive-using-java%2F) course.

[![](https://miro.medium.com/max/875/1*odNs-yx5RYj8Vdhzm2GEsA.png)](https://click.linksynergy.com/fs-bin/click?id=JVFxdTr9V80&subid=0&offerid=323058.1&type=10&tmpid=14538&RD_PARM1=https%3A%2F%2Fwww.udemy.com%2Fdata-structures-and-algorithms-deep-dive-using-java%2F)


If these questions are not enough then you can also check out this list of[**30 linked list interview questions**](http://javarevisited.blogspot.sg/2017/07/top-10-linked-list-coding-questions-and.html) for more practice questions.



###Useful Resources for Coding Interviews
If you need some useful resources to do well on your programming and Coding Job interview, here are some of the online courses and books you should check out:

1.  [Data Structures and Algorithms: Deep Dive Using Java](https://click.linksynergy.com/fs-bin/click?id=JVFxdTr9V80&subid=0&offerid=323058.1&type=10&tmpid=14538&RD_PARM1=https%3A%2F%2Fwww.udemy.com%2Fdata-structures-and-algorithms-deep-dive-using-java%2F)
2.  [Grokking the Coding Interview: Patterns for Coding Questions](https://www.educative.io/collection/5668639101419520/5671464854355968?affiliate_id=5073518643380224)
3.  [Cracking the Coding Interview Book](http://www.amazon.com/Cracking-Coding-Interview-6th-Edition/dp/0984782850/?tag=javamysqlanta-20)
4.  [Master the Coding Interview: Data Structures + Algorithms](https://click.linksynergy.com/deeplink?id=JVFxdTr9V80&mid=39197&murl=https%3A%2F%2Fwww.udemy.com%2Fcourse%2Fmaster-the-coding-interview-data-structures-algorithms%2F)
5.  [Preparing For a Job Interview By John Sonmez](https://pluralsight.pxf.io/c/1193463/424552/7490?u=https%3A%2F%2Fwww.pluralsight.com%2Fcourses%2Fdeveloper-job-interviews)

I have shared a lot of resources in this article for [Java](https://javarevisited.blogspot.com/2018/07/top-5-websites-to-learn-coding-in-java.html), [Python](https://javarevisited.blogspot.com/2019/09/5-websites-to-learn-python-for-free.html), and [C++ developers](https://javarevisited.blogspot.com/2020/07/top-10-courses-to-learn-c-in-depth-best.html) to learn data structure and algorithms. 

Some of these resources are free and some of them are paid, for paid ones I'll get paid if you buy them using links in this article, but only buy them if you really need them and only after watching previews and reading sample chapters. 

They are the best resource but it's important for you to connect to the author or instructor to get the most of them, hence buy the resource on which you connect with them. 

###Now You're One step closer to your Programming 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 data structure and algorithms questions on my [blog](http://java67.com/), so if you are really interested, you can always go there and search for them.

These common [coding](http://www.java67.com/2018/05/top-75-programming-interview-questions-answers.html), [data structure](https://hackernoon.com/50-data-structure-and-algorithms-interview-questions-for-programmers-b4b1ac61f5b0), and [algorithms](https://dev.to/javinpaul/50-data-structure-and-algorithms-problems-from-coding-interviews-4lh2) question**s** 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 [Java](https://medium.com/javarevisited/10-best-places-to-learn-java-online-for-free-ce5e713ab5b2), [Python](https://medium.com/javarevisited/8-advanced-python-programming-courses-for-intermediate-programmer-cc3bd47a4d19), or [C++ Programming](https://javarevisited.blogspot.com/2020/07/top-10-courses-to-learn-c-in-depth-best.html) and software development job, 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.

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.

**Other Data Structure Articles You May Like**
[10 Algorithm Books Every Programmer Should Read](http://www.java67.com/2015/09/top-10-algorithm-books-every-programmer-read-learn.html)
[Top 5 Data Structure and Algorithm Books for Java Developers](http://javarevisited.blogspot.sg/2016/05/5-free-data-structure-and-algorithm-books-in-java.html)
[20+ String Coding Problems from Interviews](https://hackernoon.com/20-string-coding-interview-questions-for-programmers-6b6735b6d31c)
[100+ Data Structure and Algorithms Problems from Interviews](https://www.java67.com/2018/06/data-structure-and-algorithm-interview-questions-programmers.html)
[30+ Array-based Problems from Coding Interviews](https://javarevisited.blogspot.com/2015/06/top-20-array-interview-questions-and-answers.html)
[From 0 to 1: Data Structures & Algorithms in Java](https://click.linksynergy.com/fs-bin/click?id=JVFxdTr9V80&subid=0&offerid=323058.1&type=10&tmpid=14538&RD_PARM1=https%3A%2F%2Fwww.udemy.com%2Ffrom-0-to-1-data-structures%2F)
[Data Structure and Algorithms Analysis --- Job Interview](https://click.linksynergy.com/fs-bin/click?id=JVFxdTr9V80&subid=0&offerid=323058.1&type=10&tmpid=14538&RD_PARM1=https%3A%2F%2Fwww.udemy.com%2Fdata-structure-and-algorithms-analysis%2F)
[10 Books to Prepare Technical Programming/Coding Job Interviews](http://www.java67.com/2017/06/10-books-to-prepare-technical-coding-job-interviews.html)
[Grokking Dynamic Programming Patterns for Coding Interviews](https://www.educative.io/collection/5668639101419520/5633779737559040?affiliate_id=5073518643380224)
[Grokking the System Design Interview](https://www.educative.io/collection/5668639101419520/5649050225344512?affiliate_id=5073518643380224)


### Closing Notes
Thanks, You made it to the end of the article ... Good luck with your programming interview! It's certainly not going to be easy, but you are one step closer to the success and the job you always wanted, after practicing these questions.

If you like this article, then please share it with your friends and colleagues, and don't forget to follow [javinpaul](https://twitter.com/javinpaul) on Twitter!

P.S. --- If you need some FREE resources, you can check out this list of [free data structure and algorithm courses](http://javarevisited.blogspot.com/2018/01/top-5-free-data-structure-and-algorithm-courses-java--c-programmers.html) to start your preparation.