FastPrepReverse First K Characters in Every 2K Block
Problems/Reverse First K Characters in Every 2K Block

Reverse First K Characters in Every 2K Block

Arcesium logoArcesium● EasyINTERNOA

Updated Nov 2026

QuestionFunctionExamples

Problem statement

Source note: Reported in an Arcesium intern online assessment. The report gives the whole transformation and one example, but no numeric limits. We added limits. Our version is about 99% the same as the reported question.

Given a string s and a positive integer k, process s from left to right in consecutive blocks of 2 * k characters.

  • For every complete block of 2 * k characters, reverse its first k characters and leave its next k characters unchanged.
  • If fewer than k characters remain, reverse all remaining characters.
  • If at least k but fewer than 2 * k characters remain, reverse the first k remaining characters and leave the rest unchanged.

Return the transformed string.

Function

reverseFirstKInEvery2KBlock(s: String, k: int) → String

Examples

Example 1

s = "abcdefgh"k = 2return = "bacdfegh"

In abcd, reverse ab to obtain bacd. In efgh, reverse ef to obtain fegh. Combining the blocks gives bacdfegh.

Example 2

s = "abcdefg"k = 3return = "cbadefg"

Reverse abc in the first six-character block, producing cbadef. Only g remains, so reversing the final one-character suffix leaves it unchanged.

More Arcesium Online Assessment questions

  • City Infection NumberOA · Seen Jul 2025
  • Minimum Tunnel Crossing TimeOA · Seen Jul 2025
  • Product of Subset MaximaOA · Seen Jul 2025
  • Reconstruct the Root StreamOA · Seen Jul 2025
  • Add DigitsOA · Seen Aug 2023
  • Binary Tree Maximum Path SumOA · Seen Aug 2023
  • Detect a Cycle in Directed Hate RelationshipsOA · Seen Aug 2023
  • Robo Data Sharing DirectionOA · Seen Jul 2023
  • Capital Gains Tax from TradesOA · Seen Feb 2021
  • K-th Character in an Infinite StringOA · Seen Aug 2020

Similar questions at other companies

  • Rearrange String by Alternating EndsHudson River Trading · OAHudson River Trading interview questions
  • Alternate String EndsCapital One · OACapital One interview questions
  • Concatenate Digit-wise SumsZipRecruiter · OAZipRecruiter interview questions
  • Format TextTikTok · OATikTok interview questions
  • Thresholded Run-Length EncodingBloomberg LP · ONSITE INTERVIEWBloomberg LP interview questions
  • Add Signed Character ArraysByteDance · PHONE SCREENByteDance interview questions
  • Catch Fish with Reusable BaitsSusquehanna International Group (SIG) · OASusquehanna International Group (SIG) interview questions
  • Blood Type Inheritance: Possible Parent GenotypesAbridge · OAAbridge interview questions
  • REST API: Highest International StudentsRippling · OARippling interview questions
  • Filter Isolated Interior Signal BitsSEDEMAC · OA
All Arcesium interview questionsSee Arcesium hiring insights
Saved
class Solution {
    public String reverseFirstKInEvery2KBlock(String s, int k) {
        // Write your code here.
    }
}
Checking account…