🌞 I Keep Losing My Focus — Until I Guard One Window at a Time
A story of drifting focus and stolen afternoons — where a moving sunbeam in a temple courtyard becomes our first lesson in the Sliding Window pattern.
Characters: Arjun, Guru Bodhi · Arc: Beginner · Pattern: Sliding Window (Fixed & Variable Size)
📜 Sutra of Fading Light — Too Many Rituals, Not Enough Sun
The Shifting Sunbeam Court lay high in the Gurukul, its stone floor warmed by a single band of morning light. Every day the beam slid slowly across the courtyard, then vanished over the far wall.
Arjun had been given a simple task: perform a sequence of offerings — incense, lamps, water, flowers — only inside the light. Outside the sunbeam, the ritual “did not count”.
This would have been easy, except for one problem: there were too many rituals and only a small moving patch of time and space where they would be “valid”.
Arjun tried to scatter his focus. A lamp here, a chant there, a rushed bow in between. By the time he finished one corner, the light had already moved on.
📜 Sutra of Distraction — The Real-World Version
If this feels uncomfortably familiar, good. Arjun’s courtyard is just your calendar with nicer lighting.
You have a fixed block of energy — maybe 90 minutes of real focus in the morning, another 60 in the evening. Inside those “light windows” your work matters far more than outside.
But you try to cram everything in: email, messages, docs, research, code reviews, deep work. The result?
- Nothing gets enough attention to actually finish.
- You feel “busy all day”, but the important work doesn’t move.
- You end the day like Arjun: tired, annoyed, and behind.
📜 Sutra of the Moving Window — Guard What the Light Touches
As Arjun panted across the courtyard, the soft thud of a staff echoed against stone.
Guru Bodhi stood at the edge of the light, watching the sun crawl along the floor.
Stand still… and guard a window of it.”
He pointed at a rectangular patch of light currently touching four tiles.
“Place your rituals in a row,” he continued, “and wherever the window rests, complete only what lies within. When the sun moves a little, your window moves with it — dropping what fell behind, picking up what just entered.”
This, in algorithm-speak, is the Sliding Window pattern: a moving frame over a sequence, always looking at only a small active subset at a time.
🧠 The Beam of Maximum Light — Algorithm Scroll (Fixed Window)
Turn Arjun’s problem into a classic coding puzzle:
[2, 1, 5, 1, 3, 2]The sunbeam always covers exactly
k consecutive tiles
(say, k = 3). Find the
maximum total brightness inside the window at any
position.
Naïve Approach
Sum every group of k tiles from scratch. For each
starting tile i, add up
brightness[i : i + k]. Time complexity:
O(n · k). Slow if the courtyard is huge.
Sliding Window Insight
When the window moves one step to the right:
- We drop the value that left the window.
- We add the new value that just entered.
That means we can update the sum in O(1) time and scan
the entire row in O(n).
from typing import List
def max_light_in_window(brightness: List[int], k: int) -> int:
"""
Return the maximum total brightness inside any contiguous
window of size k.
"""
if k <= 0 or k > len(brightness):
raise ValueError("k must be between 1 and len(brightness)")
window_sum = sum(brightness[:k])
max_sum = window_sum
# Slide the window one step at a time.
for right in range(k, len(brightness)):
left = right - k
window_sum += brightness[right] # add entering lamp
window_sum -= brightness[left] # remove leaving lamp
max_sum = max(max_sum, window_sum)
return max_sum
Complexity
-
Time:
O(n)— we touch each lamp at most twice. -
Space:
O(1)— we keep only the current window sum and best answer.
Guru: “Do not recount all the lamps each time you move. Remember what you already know, and update only what changed.”
🧭 Real-World Scroll — Your Day as Sliding Windows
The same pattern shows up in your calendar and habits:
- Protect a 90-minute deep-work window each morning — only one high-impact task lives there.
- Use a 30-minute window for messages: clear all inboxes, then let them wait until the window slides back again.
- For learning, keep a fixed daily study window, sliding it across topics over weeks instead of trying to learn five things at once.
- On a longer timescale, treat weeks like windows too: each week has a narrow band of attention — guard which projects stand in that light.
The key is this: at any moment, only a small slice of your life can be in true focus. Sliding Window is the discipline of choosing that slice on purpose.
📜 Sutra of Action — How Arjun Keeps the Light
The next morning, Arjun arranged his offerings in a single row across the courtyard tiles. He chose a window of four tiles — no more, no less.
Wherever the sunbeam fell, he completed only the rituals in that band. When the light moved forward one tile, he let the back tile go and picked up the new one that entered the frame.
By the time the sun climbed over the far wall, every offering had been completed, calmly, inside the light.
Guru: “That is the way of the sliding window. Guard the frame. Let the rest wait their turn.”