Distinct Chapters Missed During a Cyclic Absence
Problem statement
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) → intExamples
Example 1
numChapters = 4firstDay = 3lastDay = 5return = 3Days 3, 4, and 5 cover chapters 3, 0, and 1. The student misses three distinct chapters.
Example 2
numChapters = 3firstDay = 2lastDay = 8return = 3The seven-day absence contains at least one complete three-chapter cycle, so every chapter is missed.
Constraints
1 ≤ numChapters ≤ 10^91 ≤ firstDay ≤ lastDay ≤ 10^9
Source note: The gallery contains two independent HackerRank captures of the cyclic chapter-absence task; the newer image preserves the complete visible example and constraints.