PracHub
QuestionsPremiumCoachesLearningGuidesInterview Prep
|Home/Coding & Algorithms/TikTok

Reverse nodes in even-length linked-list groups

Last updated: Mar 29, 2026

Quick Overview

This question evaluates proficiency with singly linked list manipulation, in-place group operations (including conditional group reversal based on group length), pointer handling, and reasoning about linear time and constant extra space constraints.

  • medium
  • TikTok
  • Coding & Algorithms
  • Software Engineer

Reverse nodes in even-length linked-list groups

Company: TikTok

Role: Software Engineer

Category: Coding & Algorithms

Difficulty: medium

Interview Round: Technical Screen

### Problem Given the head of a singly linked list, you will traverse the list in **contiguous groups** of increasing size: the 1st group has size 1, the 2nd group has size 2, the 3rd group has size 3, and so on. For each group: - If the **actual number of nodes** in that group is **even**, reverse the nodes in that group. - If the actual number of nodes in that group is **odd**, leave the group as-is. Note: The final group may contain fewer nodes than its intended size; its **actual length** determines whether it should be reversed. Return the head of the modified linked list. ### Input/Output - **Input:** `head` — head node of a singly linked list. - **Output:** head of the updated list after performing the operations above. ### Example List: `1 -> 2 -> 3 -> 4 -> 5 -> 6 -> 7 -> 8 -> 9` - Group sizes: 1 | 2 | 3 | 4 ... - Groups: `[1]`, `[2,3]`, `[4,5,6]`, `[7,8,9]` (last group has length 3) - Reverse even-length groups only: `[2,3]` is even → becomes `[3,2]`; others unchanged Result: `1 -> 3 -> 2 -> 4 -> 5 -> 6 -> 7 -> 8 -> 9` ### Constraints (typical) - Number of nodes `n`: `1 <= n <= 10^5` - Node values can be any integers (do not affect the logic). - Aim for `O(n)` time and `O(1)` extra space (excluding recursion stack).

Quick Answer: This question evaluates proficiency with singly linked list manipulation, in-place group operations (including conditional group reversal based on group length), pointer handling, and reasoning about linear time and constant extra space constraints.

Related Interview Questions

  • Parse a nested list from a string - TikTok (medium)
  • Implement stacks, streaming median, and upward path sum - TikTok (easy)
  • Maximize sum with no adjacent elements - TikTok (medium)
  • Implement stack variants and path-sum check - TikTok (medium)
  • Find the longest palindromic substring - TikTok (easy)
TikTok logo
TikTok
Dec 11, 2025, 12:00 AM
Software Engineer
Technical Screen
Coding & Algorithms
3
0

Problem

Given the head of a singly linked list, you will traverse the list in contiguous groups of increasing size: the 1st group has size 1, the 2nd group has size 2, the 3rd group has size 3, and so on.

For each group:

  • If the actual number of nodes in that group is even , reverse the nodes in that group.
  • If the actual number of nodes in that group is odd , leave the group as-is.

Note: The final group may contain fewer nodes than its intended size; its actual length determines whether it should be reversed.

Return the head of the modified linked list.

Input/Output

  • Input: head — head node of a singly linked list.
  • Output: head of the updated list after performing the operations above.

Example

List: 1 -> 2 -> 3 -> 4 -> 5 -> 6 -> 7 -> 8 -> 9

  • Group sizes: 1 | 2 | 3 | 4 ...
  • Groups: [1] , [2,3] , [4,5,6] , [7,8,9] (last group has length 3)
  • Reverse even-length groups only: [2,3] is even → becomes [3,2] ; others unchanged Result: 1 -> 3 -> 2 -> 4 -> 5 -> 6 -> 7 -> 8 -> 9

Constraints (typical)

  • Number of nodes n : 1 <= n <= 10^5
  • Node values can be any integers (do not affect the logic).
  • Aim for O(n) time and O(1) extra space (excluding recursion stack).

Submit Your Answer

Sign in to leave a comment

Loading comments...

Browse More Questions

More Coding & Algorithms•More TikTok•More Software Engineer•TikTok Software Engineer•TikTok Coding & Algorithms•Software Engineer Coding & Algorithms
PracHub

Master your tech interviews with 8,500+ real questions from top companies.

Product

  • Questions
  • Learning Tracks
  • Interview Guides
  • Resources
  • Premium
  • For Universities
  • Student Access

Browse

  • By Company
  • By Role
  • By Category
  • Topic Hubs
  • SQL Questions
  • Compare Platforms
  • Discord Community

Support

  • support@prachub.com
  • (916) 541-4762

Legal

  • Privacy Policy
  • Terms of Service
  • About Us

© 2026 PracHub. All rights reserved.