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

DAY-3 Linked List

questions dsa
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as DOCX, PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
9 views

DAY-3 Linked List

questions dsa
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as DOCX, PDF, TXT or read online on Scribd
You are on page 1/ 4

Winning Camp Worksheet (Practice Questions)

Subject: IT Skills
Day 3 & 4:
Topics Covered: LINKED LIST

S.No Name of Problem Topic Difficulty


Level
Problem Link
1 Partition list Linked List https://leetcode.com/problems/partition-list/ Medium
description/
2 Insertion List Linked List https://leetcode.com/problems/insertion-sort-list/ Medium
description/
3 Add Two Numbers 11 Linked List https://leetcode.com/problems/add-two-numbers- Hard
ii/description/
4 Linked list-Cycle in a Linked List https://www.codechef.com/practice/course/linked- Hard
linked list. lists/LINKLISTF/problems/PREP58
5 Remove Duplicated Linked List https://www.codechef.com/practice/course/linked- Medium
From Sorted list lists/LINKLISTF/problems/PREP55
6 Stone Pile Linked list https://www.codechef.com/practice/course/stacks- Medium
and-queues/STAQUEF/problems/STONE_PILE
7 Number of People Linked list https://leetcode.com/problems/number-of-people- Medium
Aware of a Secret aware-of-a-secret/description/
8 Minimum number of Linked list https://leetcode.com/problems/minimum-number- Medium
coins for fruits. of-coins-for-fruits/description/
9 Linked List Cycle Linked List https://leetcode.com/problems/linked-list-cycle/ Easy
10 Palindrome Linked Linked list https://leetcode.com/problems/palindrome-linked- Easy
List list/
11 Swap Nodes In Pairs Linked List https://leetcode.com/problems/swap-nodes-in- Medium
pairs/
12 Maximum Twin Sum Linked List https://leetcode.com/problems/maximum-twin- Medium
Of a linked list sum-of-a-linked-list/

Department of Computer Science and EngineeringPage 1


1.
public class Solution {
public ListNode partition(ListNode head, int x) {
ListNode lessHead = new ListNode(-1);
ListNode moreHead = new ListNode(-1);
ListNode less = lessHead;
ListNode more = moreHead;
ListNode node = head;
while (node != null) {
if (node.val < x) {
less.next = node;
… }// partition
}

2.
public class Solution {
public ListNode insertionSortList(ListNode head) {
ListNode fakeHead = new ListNode(Integer.MIN_VALUE);
while (head != null) {
ListNode p = fakeHead;
while (p != null) {
Department of Computer Science and EngineeringPage 2
if (head.val >= p.val && (p.next == null || head.val <= p.next.val)) {
ListNode next = head.next;
head.next = p.next;
p.next = head;
head = next;
break;
}
p = p.next;
}
}
return fakeHead.next;
}
}

3.
class Solution {
public:
ListNode* reverse(ListNode* head) {
ListNode *curr = head, *prev = nullptr;
while (curr != nullptr) {
ListNode* next_node = curr->next;
Department of Computer Science and EngineeringPage 3
curr->next = prev;
prev = curr;
curr = next_node;
}
… }
if (carry > 0) {
curr->next = new ListNode(carry);
}
return reverse(dummy->next);
}
};

4.

Department of Computer Science and EngineeringPage 4

You might also like