FastPrepReverse Each Group of K List Nodes
Problems/Reverse Each Group of K List Nodes

Reverse Each Group of K List Nodes

Capital One logoCapital One● HardINTERNONSITE INTERVIEW

Updated Nov 2026

QuestionFunctionExamplesConstraints

Problem statement

Source note: The only coding question in a 2023 report on a Capital One software engineering internship loop is the k-group linked-list reversal.

The report does not say what happens to a last group shorter than k, and it gives no limits or examples. Here, a short last group keeps its order, as in the common version. The limits are our choices.

Our version is about 85% the same as the reported question.

Give the n list nodes the positions 0 to n - 1, with position 0 at head, and group them by the block size k:

  • Block i covers positions i * k through i * k + k - 1, for i = 0, 1, 2, .... Only the last block may come up short of k nodes.
  • A block holding k nodes keeps the same positions, but its nodes fill them in reverse order.
  • A short last block is not changed.

Return the node at position 0 after the change.

Function

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

Examples

Example 1

head = [4,-1,7,2,9,6,3,8,5,0]k = 4return = [2,7,-1,4,8,3,6,9,5,0]
head
4-172963850
→
return
27-14836950
Moved or new
  • Blocks of 4: [4, -1, 7, 2] | [9, 6, 3, 8] | [5, 0]
  • Full blocks reversed: [2, 7, -1, 4] | [8, 3, 6, 9] | [5, 0] (the last block holds only 2 of 4 nodes, so it is unchanged)
  • Joined: [2, 7, -1, 4, 8, 3, 6, 9, 5, 0]

Example 2

head = [11,-3,0,8,-6,14]k = 2return = [-3,11,8,0,14,-6]
head
11-308-614
→
return
-3118014-6
Moved or new
  • Blocks of 2: [11, -3] | [0, 8] | [-6, 14]
  • Full blocks reversed: [-3, 11] | [8, 0] | [14, -6]
  • Joined: [-3, 11, 8, 0, 14, -6]

Example 3

head = [-5,-12,-1,-9,-3,-7,-20]k = 3return = [-1,-12,-5,-7,-3,-9,-20]
head
-5-12-1-9-3-7-20
→
return
-1-12-5-7-3-9-20
Moved or new
  • Blocks of 3: [-5, -12, -1] | [-9, -3, -7] | [-20]
  • Full blocks reversed: [-1, -12, -5] | [-7, -3, -9] | [-20] (the last block has 1 node, so it is unchanged)
  • Joined: [-1, -12, -5, -7, -3, -9, -20]

Constraints

  • The number of nodes n is between 1 and 1000.
  • -1000 <= node.val <= 1000
  • 1 <= k <= n

More Capital One Onsite Interview questions

  • Digit-Coded Card ValidationONSITE INTERVIEW · Seen Nov 2026
  • Sort ColorsONSITE INTERVIEW · Seen Oct 2026
  • Virtual Card Transaction ValidatorONSITE INTERVIEW · Seen Oct 2026
  • Banking System with Top ActivityONSITE INTERVIEW · Seen Sep 2026
  • Transaction Event StoreONSITE INTERVIEW · Seen Jul 2026
  • Shortest Path in an Unweighted GraphONSITE INTERVIEW · Seen Jul 2026
  • Duplicate Transactions Within 60 SecondsONSITE INTERVIEW · Seen May 2026
  • LRU CachePHONE SCREEN · ONSITE INTERVIEW · Seen May 2026
  • Cashback TrackerONSITE INTERVIEW · Seen Nov 2025
  • Reverse a StringOA · ONSITE INTERVIEW · Seen Oct 2025

Similar questions at other companies

  • LFU CacheAmazon · ONSITE INTERVIEW
  • LFU CacheJP Morgan Chase · ONSITE INTERVIEWJP Morgan Chase interview questions
  • LFU CacheSnowflake · OA · ONSITE INTERVIEWSnowflake interview questions
  • LRU Cache with TTLAutodesk · ONSITE INTERVIEWAutodesk interview questions
  • Recover a Function-Call LRU Cache with a Write-Ahead LogAnthropic · ONSITE INTERVIEWAnthropic interview questions
  • Merge k Sorted ListsZS · ONSITE INTERVIEWZS interview questions
  • LFU CacheSalesforce · ONSITE INTERVIEWSalesforce interview questions
  • Max StackLinkedIn · ONSITE INTERVIEWLinkedIn interview questions
  • LFU CacheBlinkit · ONSITE INTERVIEWBlinkit interview questions
  • Fair Multi-Tenant CacheOkta · ONSITE INTERVIEWOkta interview questions

Capital One interview experiences

  • Capital One Coding OA Questions: 3 Experiences
  • Capital One Experienced Engineer Power Day and OA: 6 Experiences
  • Capital One New Grad OA Questions: 14 Experiences (Part 2 of 2)
  • Capital One TDP Agentic Round (AI Coding): 7 Experiences
  • Capital One SWE Power Day, Level Not Reported: 6 Experiences
  • Capital One TIP Intern OA and Power Day: 13 Experiences
All Capital One interview questionsSee Capital One 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 reverseInGroups(ListNode head, int k) {
        // Write your code here.
    }
}
Checking account…