Sliding-Window Text Chunking
Reported by candidates from SAP Labs's online assessment. Pattern, common pitfall, and the honest play if you blank under the timer.
The SAP Labs OA reported in July 2025 looks like a sliding-window problem, but it's really a loop with a step size. Split an array of words into chunks of chunkSize, where each chunk starts chunkSize minus overlap words after the last one. Keep the short final chunk. Return nothing for an empty array. If you've got an invite for this one, the whole job is getting the index math right and not overthinking it. And if your head goes blank mid-assessment, StealthCoder runs invisibly on screen and gives you the solution in real time as a safety net.
The problem
You are given an array of words words, a positive integer chunkSize, and an integer overlap satisfying 0 <= overlap < chunkSize. Starting at index 0, create a chunk containing up to chunkSize consecutive words. Then advance the start index by chunkSize - overlap and repeat while the start index is within the array. Return all chunks in source order. Keep the final non-empty chunk even if it contains fewer than chunkSize words. If words is empty, return an empty array. Function chunkText(words: String[], chunkSize: int, overlap: int) → String[][] Examples Example 1 words = ["a","b","c","d","e"] chunkSize = 3 overlap = 1 return = [["a","b","c"],["c","d","e"],["e"]] The window starts at indices 0, 2, and 4. Consecutive chunks overlap by one word. Example 2 words = ["one","two","three","four"] chunkSize = 2 overlap = 0 return = [["one","two"],["three","four"]] With zero overlap, each window begins immediately after the previous one. Example 3 words = [] chunkSize = 4 overlap = 1 return = [] There are no words, so no chunks are emitted. Constraints 0 <= words.length <= 10^5 1 <= chunkSize <= 10^5 0 <= overlap < chunkSize Each word is a non-null string.
Reported by candidates. Source: FastPrep
Pattern and pitfall
The trick is that there's no real window to maintain. Compute step = chunkSize - overlap. Since overlap is strictly less than chunkSize, step is at least 1, so the loop always advances and never hangs. Then loop start from 0 while start < n, and slice from start to min(start + chunkSize, n). Push each slice. That's O(n * chunkSize / step) output size, which is expected since overlapping words get copied. The common pitfall is the stop condition. Don't stop when a chunk reaches the end of the array, because Example 1 expects the trailing ["e"] chunk starting at index 4. Another pitfall is forgetting the empty input case, though the while loop handles it for free. Watch for off-by-one on the slice end, and don't use end-exclusive logic in one language and end-inclusive in another. If you blank during the live OA, StealthCoder is the hedge that gets you the loop skeleton fast.
Drill it cold or hedge it with StealthCoder. Either way, don't walk into the OA hoping you remember the trick.
You can drill Sliding-Window Text Chunking cold, or you can hedge it. StealthCoder runs invisibly during screen share and surfaces a working solution in under 2 seconds. The proctor sees the IDE. They don't see what's behind it. Made for the candidate who got the OA invite this morning and has 72 hours, not six months.
Get StealthCoderRelated leaked OAs
You've seen the question.
Make sure you actually pass SAP Labs's OA.
SAP Labs reuses patterns across OAs. Made for the candidate who got the OA invite this morning and has 72 hours, not six months. Works on HackerRank, CodeSignal, CoderPad, and Karat.
Sliding-Window Text Chunking FAQ
What's the trick in the SAP Labs text chunking problem?+
Treat it as a stepped loop. Compute step as chunkSize minus overlap, start at 0, and take a slice of up to chunkSize words each time. Advance start by step while start is less than the array length. No deque or counters needed.
How hard is this one really?+
Easy. It's mostly index arithmetic and edge cases. The constraint overlap < chunkSize guarantees step is at least 1, so there's no infinite loop. If you can write a for loop with a slice, you can solve it in a few minutes.
Why does Example 1 include a chunk with just one word?+
The rule says to repeat while the start index is within the array. Starts are 0, 2, and 4. Index 4 is valid, and only one word remains, so you keep the short chunk ["e"]. Don't drop partial final chunks.
What edge cases should I test before submitting?+
Test an empty array, which should return an empty array. Test overlap of 0, chunkSize larger than the array length, and chunkSize 1. Also test a case where the last chunk is short, like Example 1. Those cover nearly every bug.
How should I prepare in 48 hours for this kind of OA?+
Practice slicing and stepping through arrays, then write this one from scratch twice. Focus on loop bounds and min(start + chunkSize, n). Spend the rest of your time on other sliding-window and array problems so the pattern feels automatic under a timer.