You are given two independent coding tasks.
Task 1: Remove the N-th node from the end of a singly linked list
Given the head of a singly linked list and an integer n, remove the n-th node from the end of the list and return the head of the modified list.
Input
-
head
: head node of a singly linked list (node has fields
val
and
next
)
-
n
: integer
Output
-
The head of the list after removal
Constraints (typical interview assumptions)
-
1 <= n <= length(list)
-
List length can be up to
10^5
Example
-
List:
1 -> 2 -> 3 -> 4 -> 5
,
n = 2
-
Result:
1 -> 2 -> 3 -> 5
Task 2: Find the k-th missing positive number from a strictly increasing array
You are given a strictly increasing array arr of positive integers and an integer k. Consider the infinite sequence of positive integers 1, 2, 3, .... Return the k-th positive integer that is missing from arr.
Input
-
arr
: strictly increasing array of positive integers
-
k
: positive integer
Output
-
The k-th missing positive number
Constraints (typical interview assumptions)
-
1 <= arr.length <= 10^5
-
1 <= arr[i] <= 10^9
-
1 <= k <= 10^9
Example
-
arr = [2, 3, 4, 7, 11]
,
k = 5
-
Missing positives are
[1, 5, 6, 8, 9, 10, ...]
→ answer is
9