Feasibility of Printing Within Given Days
Reported by candidates from Agoda's online assessment. Pattern, common pitfall, and the honest play if you blank under the timer.
The mistake that sinks a first attempt on this Agoda OA, reported in July 2026, is overthinking it. Candidates reach for binary search or DP because the wording sounds like a classic partition problem. But the daily limit is fixed, so there's nothing to search. It's a single greedy pass over the chapters in order. If you've seen "split array" style questions, your brain will pattern-match wrong. Slow down for ten seconds and read what's actually given. If you blank anyway, StealthCoder runs invisibly during the live assessment and hands you the pass as a safety net.
The problem
You are given an array pages, where pages[i] is the number of pages in chapter i, a fixed daily printing limit dailyLimit, and an integer days. Chapters must be printed in order, and a chapter cannot be split across days. Return true if all chapters can be printed within days days; otherwise return false. Function canPrintWithinDays(pages: int[], dailyLimit: int, days: int) → boolean Examples Example 1 pages = [100,200,300,400] dailyLimit = 500 days = 3 return = true One valid schedule is [100,200], [300], and [400], all within the daily limit of 500.
Reported by candidates. Source: FastPrep
Pattern and pitfall
The trick is greedy packing. Walk the chapters in order, keep a running total for the current day, and add each chapter while it fits under dailyLimit. When the next chapter would overflow, start a new day and reset the total to that chapter. Count days used and return whether it's at most days. The pitfall is the edge case: if any single chapter is bigger than dailyLimit, it can never be printed, so return false right away. Another trap is starting the day counter at 0 and forgetting the last open day, so start at 1. Don't split chapters and don't reorder them. It's O(n) time and O(1) space. Greedy is optimal here because filling each day as much as possible never hurts later days. StealthCoder is the hedge if you freeze on the edge cases while the clock runs.
The honest play: practice the pattern, and have StealthCoder ready for the one you didn't see coming.
You can drill Feasibility of Printing Within Given Days 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. Built for the candidate who saw this exact problem leak two days before his OA and wondered if anyone had a play.
Get StealthCoderRelated leaked OAs
You've seen the question.
Make sure you actually pass Agoda's OA.
Agoda reuses patterns across OAs. Built for the candidate who saw this exact problem leak two days before his OA and wondered if anyone had a play. Works on HackerRank, CodeSignal, CoderPad, and Karat.
Feasibility of Printing Within Given Days FAQ
What's the trick to this Agoda printing problem?+
Greedy packing. Fill each day with consecutive chapters until the next one would exceed dailyLimit, then open a new day. Count the days and compare to days. No binary search is needed because the limit is already given, not something you minimize.
How hard is it really?+
Easy. It's a linear scan with a counter and a running sum. The difficulty is mostly in not confusing it with the split-array minimize-the-largest-sum problem, which does need binary search. Here the capacity is fixed.
What edge cases should I test?+
A chapter larger than dailyLimit should return false immediately. Also test an empty array, a single chapter that exactly equals the limit, and days equal to 1. Make sure your day counter starts at 1 so the final open day is counted.
Do I need dynamic programming here?+
No. Chapters must go in order and can't be split, and filling each day as much as possible is always optimal. Greedy gives the right answer in O(n). DP would work but wastes time you'd rather spend on edge cases.
How do I prepare in 48 hours for an OA like this?+
Practice writing the greedy loop from memory in your language, then do a few capacity-style problems like shipping packages or splitting arrays so you can tell fixed-capacity from minimize-capacity. Know when binary search on the answer applies and when it doesn't.