Solve two linked list/array tasks
Company: Meta
Role: Machine Learning Engineer
Category: Coding & Algorithms
Difficulty: easy
Interview Round: Technical Screen
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`
Quick Answer: This two-part question evaluates proficiency with fundamental data structures and algorithmic problem-solving—specifically linked list manipulation and array-based reasoning—within the Coding & Algorithms domain and emphasizes practical application skills in implementing efficient algorithms and analyzing time and space complexity.
Remove N-th Node from End
Given a linked list represented by values, remove the n-th node from the end and return the remaining values.
Examples
Input: ([1, 2, 3, 4, 5], 2)
Expected Output: [1, 2, 3, 5]
Explanation: Prompt example.
Input: ([1], 1)
Expected Output: []
Explanation: Remove only node.
Input: ([1, 2], 2)
Expected Output: [2]
Explanation: Remove head.
Hints
- A two-pointer linked-list solution finds the predecessor; this representation removes index len-n.
k-th Missing Positive Number
Return the k-th positive integer missing from a strictly increasing positive array.
Constraints
- arr is strictly increasing positive integers
Examples
Input: ([2, 3, 4, 7, 11], 5)
Expected Output: 9
Explanation: Prompt example.
Input: ([1, 2, 3, 4], 2)
Expected Output: 6
Explanation: Missing after array.
Input: ([5, 6], 1)
Expected Output: 1
Explanation: Missing before first value.
Hints
- Count how many positives are missing before index i: arr[i] - i - 1.