FastPrepReverse Nodes in K-Group
Problems/Reverse Nodes in K-Group

Reverse Nodes in K-Group

ByteDance logoByteDance● HardFULLTIMEPHONE SCREEN

Updated Nov 2026

QuestionFunctionExamplesConstraints

Problem statement

Source note: A ByteDance phone-screen report asks you to reverse linked-list nodes in consecutive groups of size k, and to leave a final short group as it is. In our version, the list is a finite integer list with no cycle, and k is positive.

Given the head head of a singly linked list and a positive integer k, reverse the nodes of the list in consecutive groups of exactly k nodes.

If fewer than k nodes remain at the end, leave that final group unchanged. Return the head of the transformed list.

You may change node links, but you must not change node values.

Function

reverseKGroup(head: ListNode, k: int) → ListNode

Examples

Example 1

head = [1,2,3,4,5]k = 2return = [2,1,4,3,5]
head
12345
→
return
21435
Moved or new

The complete groups [1, 2] and [3, 4] are reversed. The final one-node group remains unchanged.

Example 2

head = [1,2,3,4,5]k = 3return = [3,2,1,4,5]
head
12345
→
return
32145
Moved or new

The first three nodes form one complete group and are reversed. Only two nodes remain, so their order is preserved.

Constraints

  • The list contains between 1 and 5000 nodes.
  • -1000 <= node.val <= 1000
  • 1 <= k <= number of nodes
  • The input list is finite and contains no cycle.

More ByteDance Phone Screen questions

  • Count N-Queens PlacementsPHONE SCREEN · Seen Nov 2026
  • Matrix EscapePHONE SCREEN · Seen Nov 2026
  • Largest Number Below N from Reusable DigitsPHONE SCREEN · Seen Nov 2026
  • Log Analyzer: Busiest Service in a Rolling WindowPHONE SCREEN · Seen Nov 2026
  • Majority ElementPHONE SCREEN · Seen Nov 2026
  • Valid ParenthesesPHONE SCREEN · Seen Nov 2026
  • Binary Tree Target-Sum PathsPHONE SCREEN · Seen Nov 2026
  • Longest Increasing SubsequencePHONE SCREEN · Seen Nov 2026
  • Alien DictionaryPHONE SCREEN · ONSITE INTERVIEW · Seen Nov 2026
  • Lexicographically Smallest Topological OrderPHONE SCREEN · ONSITE INTERVIEW · Seen Nov 2026

Similar questions at other companies

  • Merge K Sorted Linked ListsBharatPe · PHONE SCREEN
  • Merge K Sorted ListsBloomberg LP · PHONE SCREEN · ONSITE INTERVIEWBloomberg LP interview questions
  • Convert a Sorted Linked List to a Balanced BSTMeta · PHONE SCREENMeta interview questions
  • Merge Two Sorted ListsLinkedIn · PHONE SCREENLinkedIn interview questions
  • Reverse a Linked ListCisco · PHONE SCREENCisco interview questions
  • Reverse a Linked ListApple · PHONE SCREENApple interview questions
  • Reverse a Singly Linked ListChubb · PHONE SCREENChubb interview questions
  • Reverse a Singly Linked ListAdobe · PHONE SCREENAdobe interview questions
  • Swap Adjacent Linked List NodesNutanix · PHONE SCREENNutanix interview questions
  • Reverse a Singly Linked ListExpedia · PHONE SCREEN · ONSITE INTERVIEWExpedia interview questions

ByteDance interview experiences

  • ByteDance TikTok USDS SWE Intern Interview: 1 Experience
  • ByteDance MLE New Grad Interviews: 1 Experience
  • ByteDance Security SRE Intern Phone Screens: 1 Experience
  • ByteDance USDS New Grad SWE Phone Screen: 1 Experience
  • ByteDance New Grad Data Engineer Video Interviews: 1 Experience
  • ByteDance Trust & Safety Research Scientist Intern: 1 Experience
All ByteDance interview questionsSee ByteDance hiring insights
Saved
/**
 * Definition for singly-linked list.
 * public class ListNode {
 *     int val;
 *     ListNode next;
 *     ListNode() {}
 *     ListNode(int val) { this.val = val; }
 *     ListNode(int val, ListNode next) { this.val = val; this.next = next; }
 * }
 */
class Solution {
    public ListNode reverseKGroup(ListNode head, int k) {
      // write your code here
    }
}
Checking account…