Company: Goldman Sachs_25july

Difficulty: medium

Problem Statement

Distinct Chapters Missed A teacher teaches chapters numbered from 0 to n - 1 , one chapter per day, in order. On day 1 chapter 0 is taught, on day 2 chapter 1 , and so on. After chapter n - 1 is taught, the teacher starts again from chapter 0 and continues cyclically. In general, on day d (days are numbered starting from 1 ) the chapter taught is (d - 1) mod n . A student is absent from day i to day j , both inclusive. Determine the number of distinct chapters the student misses during this absence. Input Format The first line contains a single integer n — the number of distinct chapters. The second line contains two space-separated integers i and j — the first and last day of the absence (inclusive). Output Format Print a single integer: the number of distinct chapters missed during days i through j . Constraints 1 <= n <= 10^5 1 <= i <= j <= 10^9 Example 1 Input: 5 2 4 Output: 3 Explanation: On days 2 , 3 , 4 the chapters taught are 1 , 2 , 3 . All three are distinct,

More Goldman Sachs_25july OA questionsInterview experiences