Given the `head` of a singly linked list and two integers, `X` and `Y`. Implement a function `transformList` that recursively modifies the `val` of each node in the list. For each node, if its `val` is strictly less than `Y`, increment `val` by `X`. Otherwise, decrement `val` by `X`. The function should return the `head` of the modified linked list.
Explanation: Nodes with value < 6 are incremented by 3, others are decremented by 3. (1+3=4), (5+3=8), (8-3=5), (2+3=5).
Explanation: Since all node values (10, 20, 30) are >= 0, each is decremented by 5. (10-5=5), (20-5=15), (30-5=25).
Analyze constraints and compute optimal solutions step-by-step.
No dry run loaded.
🚀 Practice this problem
Run code, get AI hints & track streak