11) Palindrome Linked List

This is our given problem, Given a singly linked list, determine if it is a palindrome. Example 1: Input: 1->2 Output: false Example 2: Input: 1->2->2->1 Output: true Follow up:Could you do it in O(n) time and O(1) space? How can we APPROACH this problem? By using two ways, we can solve this problem, Slow … Continue reading 11) Palindrome Linked List

10) Merge Two Sorted Lists

Merge two sorted linked lists and return it as a new list. The new list should be made by splicing together the nodes of the first two lists. Example: Input: 1->2->4, 1->3->4 Output: 1->1->2->3->4->4 Explanation L1 = 1->4 L2 = 2->3 Output = 1->2->3->4 Create a dummy node. ListNode dummy = new ListNode(0); //dummy = … Continue reading 10) Merge Two Sorted Lists

Becoming a Better developer by using the SOLID Design principles

Consider that you are working in good startup based company. There you were assigned with the role of Software Development Engineer. So that, you are the most responsible person for developing core features from end to end. But the problem is, in early stage startups, things are not very organized. So we ended up by … Continue reading Becoming a Better developer by using the SOLID Design principles

9) Linked List Cycle II

In this article we going to see about how to Detect Loop in a Linked List and Return the Loop Node. Below is our given problem from Leetcode, Given a linked list, return the node where the cycle begins. If there is no cycle, return null. To represent a cycle in the given linked list, we … Continue reading 9) Linked List Cycle II

8) Detect Loop in linked list

In this article, we going to see how to detect loop in a linked list. Here is our given problem, Given a linked list, determine if it has a cycle in it. To represent a cycle in the given linked list, we use an integer pos which represents the position (0-indexed) in the linked list where tail connects … Continue reading 8) Detect Loop in linked list

7) Reverse a Linked List – Iterative and Recursive approach

This is one of the most important interview question, How to reverse a linked list using iterative and recursive approach? In this article, I will help you to understand, how to approach and solve this problem. I'm going to make a diagrammatic representations, so that you can easily understand the problem well. Here is our … Continue reading 7) Reverse a Linked List – Iterative and Recursive approach

6) Swap Nodes in Pairs

Hi geeks! Today we going to see about how to swap the linked list nodes in a pair wise. Given a linked list, swap every two adjacent nodes and return its head. You may not modify the values in the list's nodes, only nodes itself may be changed. Example: Given 1->2->3->4, you should return the list as 2->1->4->3. … Continue reading 6) Swap Nodes in Pairs

5) Remove Duplicates from Sorted List II

Given a sorted linked list, delete all nodes that have duplicate numbers, leaving only distinct numbers from the original list. Example 1: Input: 1->2->3->3->4->4->5 Output: 1->2->5 Example 2: Input: 1->1->1->2->3 Output: 2->3 Solution: /** * Definition for singly-linked list. * public class ListNode { * int val; * ListNode next; * ListNode(int x) { val = x; … Continue reading 5) Remove Duplicates from Sorted List II

Singleton Design Pattern

The singleton pattern ensures that, "A class has only one instance and provides a global point of access to it". It comes under the creational design pattern. Just think about that, you have a class and singleton pattern helps you to make it impossible to instantiate that class except for a single time and whenever … Continue reading Singleton Design Pattern

4) Remove Zero Sum Consecutive Nodes from Linked List

Hi geeks! In this article, we going to play with Linked list and hash map by solving this interesting problem remove Zero Sum Consecutive Nodes from Linked List. Given the head of a linked list, we repeatedly delete consecutive sequences of nodes that sum to 0 until there are no such sequences. After doing so, return the head of … Continue reading 4) Remove Zero Sum Consecutive Nodes from Linked List

3) Next Greater Node In Linked List

Hi friends! In this article, we going to find next greater node in linked list after that we going to convert that into an array. Lets jump into problem. We are given a linked list with head as the first node.  Let's number the nodes in the list: node_1, node_2, node_3, ... etc. Each node may have a next larger value: for node_i, next_larger(node_i) is … Continue reading 3) Next Greater Node In Linked List

2) Rotate List

Hi Geeks! Today we going to see, how to rotate the linked list with fun. Given a linked list, rotate the list to the right by k places, where k is non-negative. Example 1: Input: 1->2->3->4->5->NULL, k = 2 Output: 4->5->1->2->3->NULL Explanation: rotate 1 steps to the right: 5->1->2->3->4->NULL rotate 2 steps to the right: 4->5->1->2->3->NULL Example 2: Input: 0->1->2->NULL, … Continue reading 2) Rotate List