
You are given two independent coding tasks.
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
Constraints (typical interview assumptions)
1 <= n <= length(list)
10^5
Example
1 -> 2 -> 3 -> 4 -> 5
,
n = 2
1 -> 2 -> 3 -> 5
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
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
[1, 5, 6, 8, 9, 10, ...]
→ answer is
9