Split a Crawl Log Into Most Chunks Keeping Each Host Together

Last updated: November 29, 2026

Quick Overview

A string lists the host letter of each page fetched by a crawler. Split it into as many contiguous chunks as possible so that every host letter appears in only one chunk, and return the chunk sizes.

Google
Coding & Algorithms
Software Engineer
Google
November 29, 2026
Software Engineer
Technical Screen
Coding & Algorithms
Medium

0

0

0 solved


A string lists the host letter of each page fetched by a crawler. Split it into as many contiguous chunks as possible so that every host letter appears in only one chunk, and return the chunk sizes.

Framed around sharding a web crawl log so each host's pages land in one worker's chunk, this is a greedy two-pointer question in the style of Google technical screens. The interviewer checks the last-occurrence precomputation and the moving chunk end.

What the Interviewer Expects
  • Precomputes the last index of each character
  • Extends the current chunk end to the max last index seen
  • Closes the chunk when the scan reaches its end
  • Explains why greedy cutting gives the most chunks
  • States O(n) time and O(alphabet) space
Key Topics to Cover
Two Pointers
Greedy
Last Occurrence
Partitioning
How to Approach This
  1. Clarify input constraints and edge cases before writing code.
  2. Walk through your approach verbally and confirm with the interviewer before coding.
  3. Start with a brute force solution, then optimize. Mention time and space complexity.
  4. Test your solution with examples, including edge cases like empty input or duplicates.
  5. Consider common patterns: sliding window, two pointers, hash map, BFS/DFS, dynamic programming.
Possible Follow-up Questions
  • What if each host is a full string instead of a letter?
  • What if chunks also have a maximum size?
  • How would you parallelize computing last occurrences on a very large log?
Sharpen Your Skills on Codemia

Practice similar problems with our interactive workspace, get AI feedback, and track your progress.

Practice DSA Problems
Sample Answer
Requirements
  • Input: string log of lowercase letters.
  • Output: list of chunk lengths, left to right, maximizing the number of chunks such that no letter appears in two chunks....
High-Level Design

First record last[ch], the final index where each letter appears. Then scan with start at the current chunk's beginning and end as the furthest last index of any letter seen so far in the chunk....


Submit Your Answer
Markdown supported