FastPrepMarkdown Header Chunks
Problems/Markdown Header Chunks

Markdown Header Chunks

Sierra logoSierra● MediumFULLTIMEPHONE SCREEN

Updated Sep 2026

QuestionFunctionExamplesConstraints

Problem statement

Split a Markdown document into chunks whose text length does not exceed maxChunkSize whenever possible. Lines must remain intact.

When a new chunk starts inside a Markdown header section, prepend the active header path to that chunk. For example, if the current content is under # A and ## B, the new chunk should start with those header lines before adding the next content lines.

Return each chunk as a display string where the lines inside that chunk are joined by | .

Function

chunkMarkdown(markdown: String, maxChunkSize: int) → String[]

Examples

Example 1

markdown = "# A\nshort\nlonger line\n## B\nx\ny"maxChunkSize = 20return = ["# A | short","# A | longer line","# A | ## B | x | y"]

The second chunk repeats the active # A header before continuing content under that section.

Example 2

markdown = "# Guide\nalpha\nbeta"maxChunkSize = 30return = ["# Guide | alpha | beta"]

The whole document fits within one chunk.

Constraints

  • Header lines are lines whose first non-space character is #. If a single non-header line plus its active headers is longer than maxChunkSize, keep that line in its own chunk with the active headers.

More Sierra interview questions

  • Compact Conversation History by Token BudgetPHONE SCREEN · Seen Nov 2026
  • Paginate Retained Conversation HistoryPHONE SCREEN · Seen Nov 2026
  • Compact Conversations by Unique ListingsPHONE SCREEN · Seen Oct 2026
  • Maximum Array ValueOA · Seen Oct 2026

Similar questions at other companies

  • Business Account KYC Verification — Parts 1–5Stripe · PHONE SCREENStripe interview questions
  • Read Across Sound TracksAirbnb · PHONE SCREENAirbnb interview questions
  • Stateful Log Transform and SearchRippling · PHONE SCREEN · ONSITE INTERVIEWRippling interview questions
  • In-Memory Filesystem CommandsPerplexity AI · PHONE SCREEN · ONSITE INTERVIEWPerplexity AI interview questions
  • K-Step Bit Flip with RetentionCisco · PHONE SCREENCisco interview questions
  • Elevator Scheduling SimulationOpenAI · PHONE SCREENOpenAI interview questions
  • File Storage ServiceCresta · PHONE SCREENCresta interview questions
  • String Interpolation with a Missing-Value ModeMongoDB · PHONE SCREENMongoDB interview questions
  • Dasher Pay with Store Waits and Peak HoursDoorDash · PHONE SCREENDoorDash interview questions
  • Return Every Matching DecryptionDuolingo · PHONE SCREENDuolingo interview questions
All Sierra interview questionsSee Sierra hiring insights
Saved
class Solution {
    public String[] chunkMarkdown(String markdown, int maxChunkSize) {
        // write your code here
    }

}
Checking account…