Number of Distinct Roll Sequences LeetCode solution in C++

1
class Solution {
2
private:
3
int mod = 1e9 + 7;
4

5
int f(int ind, int prev1, int prev2, int n) {
6
// Base Case
7
if (ind == n) return 1;
8

9
int ans = 0;
10
for (int i = 1; i <= 6; i++) // Exploring all possible values
11
if (prev1 != i && prev2 != i && (prev1 == 0 || __gcd(prev1, i) == 1))
12
ans = (ans + f(ind + 1, i, prev1, n)) % mod;
13

14
return ans;
15
}
16

17
public:
18
int distinctSequences(int n) {
19
return f(0, 0, 0, n);
20
}
21
};

0

WPM •0 •0

100%

ACC •0 •0

0s

TIME •0