Reverse nodes in k-groups
Given a singly linked list encoded as a Python list of integers and an integer k, reverse the nodes of the list k at a time and return the resulting sequence as a Python list. Nodes in a final group with fewer than k elements are left as-is (not reversed). k is between 1 and the length of the list; the list has up to 5000 nodes.
Implement
reverse_k_group(values: list[int], k: int) → list[int]Examples
in
[[1,2,3,4,5],2]out[2,1,4,3,5]What a strong answer looks like
State your approach and its time/space complexity out loud before you optimize. Handle the edge cases (empty input, duplicates, overflow), and say why you chose this over the brute force. Green tests are the floor, not the grade.
0:00 of about 35 min
solution.py
InputExpectedGot
[[1,2,3,4,5],2][2,1,4,3,5]not run yetsample