This is a verified interview question from Visa. Candidates reporting seeing this problem in recent Online Assessments (OAs) and onsite rounds. Mastering "Distinct Chapters Missed - Visa Online Assessment IIT BHU" covers key patterns like Arrays.
"A course consists of `numChapters` distinct chapters numbered from `0` to `numChapters - 1`. The chapters are taught **sequentially**, one chapter per day. After the last chapter is taught, the course starts again from chapter `0`. Given that a student was absent from **day `firstDay` to day `lastDay`**, both inclusive, determine the **number of distinct chapters** the student missed. ### Input * `numChapters` — number of distinct chapters. * `firstDay` — first day the student was absent. * `lastDay` — last day the student was absent. The chapter taught on day `d` is: ```text (d % numChapters) ``` ### Output Return the number of **distinct chapters** taught between `firstDay` and `lastDay`, inclusive. ### Example 1 ```text Input: numChapters = 4 firstDay = 3 lastDay = 5 ``` Chapters taught: ```text Day: 0 1 2 3 4 5 6 7 Chapter: 0 1 2 3 0 1 2 3 ``` The student missed: ```text Day 3 → Chapter 3 Day 4 → Chapter 0 Day 5 → Chapter 1 ``` Distinct chapters missed: ```text {0, 1, 3} ``` Therefore: ```text Answer = 3 ``` ### Example 2 ```text Input: numChapters = 4 firstDay = 1 lastDay = 6 ``` Chapters: ```text 1, 2, 3, 0, 1, 2 ``` Distinct chapters: ```text {0, 1, 2, 3} ``` ```text Answer = 4 ``` ### Constraints ```text 1 ≤ numChapters ≤ 10^9 0 ≤ firstDay ≤ lastDay ≤ 10^18 ``` **Goal:** Find an efficient solution without iterating through every day."
Join thousands of developers practicing for Visa.