Cse220 Quiz 2

Download as docx, pdf, or txt
Download as docx, pdf, or txt
You are on page 1of 1

23-Summer-CSE220 Quiz 01 Marks: 20 Time: 40 mins

Name: ID:
Section:
1. Given a set of sorted intervals, find all non-overlapping intervals after merging the
overlapping intervals using stack. Assume that you already have a stack
implemented that allows you to push and pop a tuple. You have to write a function
that takes the sorted intervals as input and returns merged intervals.

For example,

Input: [(1, 5), (2, 3), (4, 6), (7, 8), (8, 10), (12, 15)]

Output: Intervals after merging overlapping intervals are [(1, 6), (7, 10), (12, 15)]

Explanation:

(1, 5), (2, 3), (4, 6) are overlapping intervals. After merging we get (1,6)
(7, 8), (8, 10) are overlapping intervals. After merging we get (7,10)

2. You are given a linked list, and an integer k.


Return the head of the linked list after swapping the kth node from the beginning
and the kth node from the end (the list is 1-indexed). You have to swap the whole node, not just
the value/ element of the node. You’re free to use any of the helper functions you’ve learnt,
but you need to implement the helper functions separately.

Example:

Input:
a = 1 → 2 → 3 → 4 → 5 → None
k=2

Output: 1 → 4 → 3 → 2 → 5 → None

Input:
a = 1 → 7 → 4 → 5 → None
k=2
Output: 1 → 4 → 7 → 5 → None
[CO1, 10 marks each]

You might also like