Tap here to switch tabs
Problem
Submissions

Problem: First Day Where You Have Been in All the Rooms

med
30 min
Try to solve the First Day Where You Have Been in All the Rooms problem.

Statement

There are n rooms labeled from 00 to n −1- 1. Starting on day 00, you begin in room 00 and visit one room each day.

You are given a 00 indexed integer array nextVisit of length n. When you are in room i on any day:

  • If you have visited room i an odd number of times (including the current visit), the next room you visit will be nextVisit[i].

  • If you have visited room i an even number of times (including the current visit), the next room you visit will be (i + 1) % n.

Return the first day on which you have visited every room at least once. Since the answer may be very large, return it modulo 109+710^9 + 7.

Constraints:

  • n == nextVisit.length

  • 2≤2 \leq n ≤105\leq 10^5

  • 0≤0 \leq nextVisit[i] ≤\leq i

⋮
Tap here to switch tabs
Problem
Submissions

Problem: First Day Where You Have Been in All the Rooms

med
30 min
Try to solve the First Day Where You Have Been in All the Rooms problem.

Statement

There are n rooms labeled from 00 to n −1- 1. Starting on day 00, you begin in room 00 and visit one room each day.

You are given a 00 indexed integer array nextVisit of length n. When you are in room i on any day:

  • If you have visited room i an odd number of times (including the current visit), the next room you visit will be nextVisit[i].

  • If you have visited room i an even number of times (including the current visit), the next room you visit will be (i + 1) % n.

Return the first day on which you have visited every room at least once. Since the answer may be very large, return it modulo 109+710^9 + 7.

Constraints:

  • n == nextVisit.length

  • 2≤2 \leq n ≤105\leq 10^5

  • 0≤0 \leq nextVisit[i] ≤\leq i