FastPrepSplit Text into Fixed-Length Chunks
Problems/Split Text into Fixed-Length Chunks

Split Text into Fixed-Length Chunks

WhatNot logoWhatNot● EasyINTERNPHONE SCREEN

Updated Nov 2026

QuestionFunctionExamplesConstraints

Problem statement

Source note: An internship report describes splitting text into sentences of fixed length. Our version is about 65% the same as the reported question. Length means ASCII characters, spaces are kept, and the last chunk may be shorter. Examples and limits are our assumptions.

Given a string text and a positive integer k, split the string from left to right into consecutive chunks.

  • Every chunk except possibly the last must contain exactly k characters.
  • If fewer than k characters remain, return them as the last chunk without padding.
  • Keep every character exactly once and in order. Spaces and punctuation count toward the length; do not split by words or trim whitespace.
  • Return an empty array when text is empty. Do not add an empty trailing chunk when the length is divisible by k.

Function

splitFixedLength(text: String, k: int) → String[]

Examples

Example 1

text = "abcdefg"k = 3return = ["abc","def","g"]

Two full chunks contain three characters each. The remaining character forms the last chunk.

Example 2

text = "ab cd! "k = 3return = ["ab ","cd!"," "]

Spaces and punctuation count as characters and are preserved, including the trailing space.

Example 3

text = ""k = 4return = []

There are no characters, so the result contains no chunks.

Constraints

  • 0 <= text.length <= 2000.
  • 1 <= k <= 2000.
  • Every character is printable ASCII, with character code from 32 to 126.

More WhatNot Phone Screen questions

  • Merge Sorted Squares of Two ArraysPHONE SCREEN · ONSITE INTERVIEW · Seen Nov 2026
  • Adjacent Pair and Run RemovalPHONE SCREEN · ONSITE INTERVIEW · Seen Nov 2026
  • User Journey PathsPHONE SCREEN · ONSITE INTERVIEW · Seen Nov 2026
  • User Journey Paths from a Log StreamPHONE SCREEN · Seen Nov 2026
  • Reachable Exits in an Obstacle GridPHONE SCREEN · Seen Oct 2026
  • Palindrome with One DeletionPHONE SCREEN · Seen Oct 2026
  • Search a 2D MatrixPHONE SCREEN · ONSITE INTERVIEW · Seen Oct 2026
  • Attraction Route Without Reusing TrailsPHONE SCREEN · Seen Sep 2026
  • Earliest Car for Each PassengerPHONE SCREEN · Seen Sep 2026
  • Minimum Stores for a Shopping ListPHONE SCREEN · Seen Sep 2026

Similar questions at other companies

  • Search and Format ContactsAdyen · PHONE SCREENAdyen interview questions
  • Subtract Two Large Number StringsStackAdapt · PHONE SCREENStackAdapt interview questions
  • Portfolio Valuation, Part 1Stripe · PHONE SCREENStripe interview questions
  • Format a Signed Integer with CommasHudson River Trading · PHONE SCREENHudson River Trading interview questions
  • Fair Coin from a Biased CoinAnthropic · PHONE SCREENAnthropic interview questions
  • Run-Length DecodingApple · PHONE SCREENApple interview questions
  • Trace Pointer Rebinding and Pointee UpdatesArista Networks · PHONE SCREENArista Networks interview questions
  • Match a Variadic Function SignatureConfluent · PHONE SCREENConfluent interview questions
  • Decode and Store StringsAirbnb · PHONE SCREENAirbnb interview questions
  • Delimiter-Parsing String Iteratoramo · PHONE SCREEN

Interview reports that mention this question

  • Whatnot interviews · January 2025

WhatNot interview experiences

  • Whatnot SWE New Grad
  • Whatnot OA · 2024
  • Whatnot OA · November 2023
  • Whatnot interviews · November 2023
  • Whatnot interviews · February 2024
All WhatNot interview questionsSee WhatNot hiring insights
Saved
class Solution {
    public String[] splitFixedLength(String text, int k) {
        // write your code here
    }
}
Checking account…