0% found this document useful (0 votes)
65 views

Technical Skilling - Competitive Coding: Linked List

The document provides an overview of linked list problems and solutions discussed in a technical skilling session on competitive coding. It lists 13 linked list problems from LeetCode along with high-level descriptions and ideologies for solving each. The problems cover a range of linked list operations and patterns like converting to integers, finding the middle node, reversing, merging, removing duplicates, and more. Sample code snippets are included to demonstrate approaches like using pointers, counting nodes, and traversing lists. The document aims to help participants learn and practice common linked list algorithms.
Copyright
© © All Rights Reserved
Available Formats
Download as PPTX, PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
65 views

Technical Skilling - Competitive Coding: Linked List

The document provides an overview of linked list problems and solutions discussed in a technical skilling session on competitive coding. It lists 13 linked list problems from LeetCode along with high-level descriptions and ideologies for solving each. The problems cover a range of linked list operations and patterns like converting to integers, finding the middle node, reversing, merging, removing duplicates, and more. Sample code snippets are included to demonstrate approaches like using pointers, counting nodes, and traversing lists. The document aims to help participants learn and practice common linked list algorithms.
Copyright
© © All Rights Reserved
Available Formats
Download as PPTX, PDF, TXT or read online on Scribd
You are on page 1/ 43

Technical Skilling – Competitive Coding

Week 2

Linked List

1
List of Problems

2
3
Problem Title: Convert Binary Number in a Linked List to Integer
Problem Link: https://leetcode.com/problems/convert-binary-number-in-a-
linked-list-to-integer/

4
5
Ideology
// Convert Binary Number in a Linked List to Integer
1. Count the number of nodes in the linked list
2. Traverse the list till end
2.1. Calculate the answer at each node using the following
expression
res = res+pow(2, --count)* nodevalue

6
Problem Title: Middle of the Linked List
Problem Link: https://leetcode.com/problems/middle-of-the-linked-list/

7
8
Ideology
// Middile of the linked list
1. Count the number of nodes in the linked list
2. Calculate middle position (mid=count/2)
3. Traverse the list till mid
While(count!=mid) { temp=temp->next count=count+1 }
4. Return next node value (return temp->next)

9
Problem Title: Delete node in a linked list
Link: https://leetcode.com/problems/delete-node-in-a-linked-list/

10
11
Ideology
1. Given address of node
2. Update the address part of previous node with the next node
address

12
Problem Title: Reverse Linked List
Problem Link: https://leetcode.com/problems/reverse-linked-list/

13
14
Ideology
// Reverse the linked list
1:Initialize three pointers prev as Null, curr as head and next as
null
2. Iterate through linked list and Do the following in loop
2.1. Before changing next of current store next (next=curr->next)
2.2. Now change next of current (cur->next=prev)
2.3. move prev and curr one step forward (prev=curr and
curr=next) Initialize three pointers prev as NULL, curr
as head and next as NULL.

15
Problem Title: Merge Two Sorted Lists
Link: https://leetcode.com/problems/merge-two-sorted-lists/

16
You are given the heads of two sorted linked lists list1 and list2.
Merge the two lists in a one sorted list. The list should be made by splicing together
the nodes of the first two lists.
Return the head of the merged linked list.
 
Example 1:

17
Input: list1 = [1,2,4], list2 = [1,3,4] Output: [1,1,2,3,4,4]
Example 2:
Input: list1 = [], list2 = [] Output: []
Example 3:
Input: list1 = [], list2 = [0] Output: [0]
 
Constraints:
•The number of nodes in both lists is in the range [0, 50].
•-100 <= Node.val <= 100
•Both list1 and list2 are sorted in non-decreasing order.

18
Problem Title: Remove Duplicates from Sorted List
Link: https://leetcode.com/problems/remove-duplicates-from-sorted-
list/

19
Given the head of a sorted linked list, delete all
duplicates such that each element appears only once.
Return the linked list sorted as well.
 
Example 1:
Input: head = [1,1,2] Output: [1,2]

20
Example 2:
Input: head = [1,1,2,3,3] Output: [1,2,3]

21
Problem Title: Next Greater Node In Linked List
Link: https://leetcode.com/problems/next-greater-node-in-linked-list/

22
You are given the head of a linked list with n nodes.
For each node in the list, find the value of the next
greater node. That is, for each node, find the value of the
first node that is next to it and has a strictly larger value
than it.
Return an integer array answer where answer[i] is the
value of the next greater node of the ith node (1-indexed).
If the ith node does not have a next greater node,
set answer[i] = 0.
 
Example 1:
Input: head = [2,1,5] Output: [5,5,0]

23
24
Example 2:
Input: head = [2,7,4,3,5] Output: [7,0,5,5,0]
 
Constraints:
•The number of nodes in the list is n.
•1 <= n <= 104
•1 <= Node.val <= 109

25
Problem Title: Flatten a Multilevel Doubly Linked List
Link: https://leetcode.com/problems/next-greater-node-in-linked-list/

26
You are given a doubly linked list, which contains nodes that have a next
pointer, a previous pointer, and an additional child pointer. This child
pointer may or may not point to a separate doubly linked list, also
containing these special nodes. These child lists may have one or more
children of their own, and so on, to produce a multilevel data
structure as shown in the example below.
Given the head of the first level of the list, flatten the list so that all the
nodes appear in a single-level, doubly linked list. Let curr be a node with
a child list. The nodes in the child list should
appear after curr and before curr.next in the flattened list.
Return the head of the flattened list. The nodes in the list must have all of
their child pointers set to null.

27
Example 1:

Input: head =
[1,2,3,4,5,6,null,null,null,7,8,9,10,null,null,11,12]
Output: [1,2,3,7,8,11,12,9,10,4,5,6]
Explanation: The multilevel linked list in the input is
shown.

28
After flattening the multilevel linked list it becomes:

29
Example 2:

Input: head = [1,2,null,3] Output: [1,3,2]


Explanation: The multilevel linked list in the input is shown.
After flattening the multilevel linked list it becomes:

30
Problem Title: Swap Nodes in Pairs
Link: https://leetcode.com/problems/swap-nodes-in-pairs//

31
32
Ideology

33
Problem Title: Linked List in Binary Tree
Link : https://leetcode.com/problems/linked-list-in-binary-tree/

34
35
Ideology

36
Problem Title: Kth Smallest Number in Multiplication Table
Link : https://leetcode.com/problems/kth-smallest-number-in-
multiplication-table/

37
38
Ideology

39
Problem Title: Smallest Range Covering Elements from K Lists
Link : https://leetcode.com/problems/smallest-range-covering-
elements-from-k-lists/

40
41
Ideology

42
THANK YOU

43

You might also like