Reported September 2026
Visamath

Distinct Chapters Missed During a Cyclic Absence

Reported by candidates from Visa's online assessment. Pattern, common pitfall, and the honest play if you blank under the timer.

Get StealthCoderRuns invisibly during the live Visa OA. Under 2s to a working solution.
Founder's read

Visa reported this OA in September 2026, and it looks like a simulation problem until you read the constraints. A teacher walks through chapters in a cycle, a student misses a stretch of days, and you count distinct chapters missed. Both numbers go up to 10^9, so looping over days is dead on arrival. What it really reduces to is one length check and one modulo comparison. If you've got an invite in your inbox, this is a five-minute problem once you see it. StealthCoder is the safety net if your head goes blank mid-assessment, but the trick below should be enough.

The problem

A chemistry teacher teaches exactly one chapter per day, moving through a book in order. The book contains numChapters chapters numbered from 0 through numChapters - 1. On day i, where days are zero-indexed, the teacher covers chapter i % numChapters.
A student is absent on every day from firstDay through lastDay, inclusive. Return the number of distinct chapters taught during that absence.

Function
countDistinctChaptersMissed(numChapters: int, firstDay: int, lastDay: int) → int

Examples
Example 1
numChapters = 4
firstDay = 3
lastDay = 5
return = 3
Days 3, 4, and 5 cover chapters 3, 0, and 1. The student misses three distinct chapters.
Example 2
numChapters = 3
firstDay = 2
lastDay = 8
return = 3
The seven-day absence contains at least one complete three-chapter cycle, so every chapter is missed.

Constraints
1 ≤ numChapters ≤ 10^9
1 ≤ firstDay ≤ lastDay ≤ 10^9

Reported by candidates. Source: FastPrep

Pattern and pitfall

Count the days absent: len = lastDay - firstDay + 1. If len >= numChapters, every chapter appears at least once, so return numChapters. Otherwise the window is shorter than one cycle, so no chapter repeats and the answer is just len. That's it. You don't even need the wraparound logic, because a window shorter than a cycle can't hit the same chapter twice. The common pitfall is simulating day by day or building a set, which times out at 10^9. Another trap is off-by-one on the inclusive range, so check Example 1: days 3 to 5 is length 3, with numChapters 4, answer 3. Example 2: length 7 against 3 chapters returns 3. Return min(len, numChapters). If you freeze on the live OA, StealthCoder can hand you this reduction while you type, but write it yourself if you can. It's one line.

Memorize the pattern. If you can't, run StealthCoder. The proctor sees the IDE. They don't see what's behind it.

If this hits your live OA

You can drill Distinct Chapters Missed During a Cyclic Absence 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 by an engineer who treats the OA as theater. If yours is tonight, you don't have time to grind. You have time to hedge.

Get StealthCoder

Related leaked OAs

⏵ The honest play

You've seen the question. Make sure you actually pass Visa's OA.

Visa reuses patterns across OAs. Made by an engineer who treats the OA as theater. If yours is tonight, you don't have time to grind. You have time to hedge. Works on HackerRank, CodeSignal, CoderPad, and Karat.

Distinct Chapters Missed During a Cyclic Absence FAQ

How hard is the Visa distinct chapters OA really?+

Easy once you spot the reduction. The hard part is resisting the urge to simulate. With values up to 10^9, the only viable answer is arithmetic. If you reach min(length, numChapters), you're done in a few lines.

What's the trick for countDistinctChaptersMissed?+

Compute the absence length as lastDay - firstDay + 1. A window of that many consecutive days in a cycle of numChapters covers min(length, numChapters) distinct chapters. Shorter than a cycle means no repeats. Longer or equal means everything is covered.

Do I need modulo math for the wraparound?+

No. Wraparound doesn't change the distinct count. Consecutive days always map to consecutive chapters mod numChapters, so a window shorter than one cycle gives all different chapters even if it wraps past the end of the book.

What edge cases should I test?+

Test numChapters = 1 (answer is always 1), firstDay equal to lastDay (answer is 1), length exactly equal to numChapters, and maximum values near 10^9. Also confirm the inclusive range by checking that Example 1 gives 3, not 2.

How do I prepare for this in 48 hours?+

Practice recognizing when huge constraints rule out simulation and a closed-form answer exists. Do a handful of cyclic index and range-length problems, and always check small examples by hand. This one needs no data structures, just careful counting.

Problem reported by candidates from a real Online Assessment. Sourced from a publicly-available candidate-aggregated repository. Not affiliated with Visa.

OA at Visa?
Invisible during screen share
Get it