Back to problems

Reverse linked list in fixed-size groups

Algorithm · Microsoft · Medium

Given an array values containing a singly linked list’s values in head-to-tail order, and an integer k with $$k \ge 1$$, reverse every complete consecutive block of k nodes. If a final block contains fewer than k nodes, leave it unchanged. The reversal must be performed in place — do not build a separate copy of the data as the primary technique. Return the transformed list as an array of values. Example 1: Explanation: The full blocks [2, 4, 6] and [8, 10, 12] are reversed,…

Checking your access…