Grokking 75: Top Coding Interview Questions
Ask Author
Back to course home

0% completed

Reverse Nodes in k-Group (hard)
Table of Contents

Contents are not accessible

Contents are not accessible

Contents are not accessible

Contents are not accessible

Contents are not accessible

Problem Statement

Given the head of a linked list, reverse each k node of the list at a time and return the modified list.

Here, k is a positive integer and is less than or equal to the length of the linked list. If the number of nodes is not a multiple of k, the remaining nodes at the end should stay as they are.

Note: You can only change the nodes themselves, not the values inside them.

Examples

  1. Example 1:
    • Input: head = [1, 2, 3, 4, 5, 6], k = 3
    • Expected Output: [3, 2, 1, 6, 5, 4]
    • Justification: The list is reversed in groups of three

.....

.....

.....

Like the course? Get enrolled and start learning!

Table of Contents

Contents are not accessible

Contents are not accessible

Contents are not accessible

Contents are not accessible

Contents are not accessible