Code RoomReverse nodes k-group
HardPrep Room Coding #1344

Reverse nodes k-group

CodingAlgorithms & data structuresMid–Senior~30 min

A singly linked list is given as a plain list of values in head-to-tail order. Reverse the nodes k at a time and return the resulting list of values. Nodes that don't form a complete group of k at the end are left in their original order. 1 <= k. The list may be empty.

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 30 min
InputExpectedGot
[[1,2,3,4,5],2][2,1,4,3,5]not run yetsample