Recently I had been trying to solve a question :
I have come up with the following approach :
#include "bits/stdc++.h"
using namespace std;
const int MOD = 1000000007;
vector<int> getValidRep(const vector<int>& arr, int i, int m) {
vector<int> vec;
if (i == 0) {
for (int i = 1; i <= m; i++) {
if (i != arr[i + 1])
vec.push_back(i);
}
}
else if (i == arr.size() - 1) {
for (int i = 1; i <= m; i++) {
if (i != arr[i - 1])
vec.push_back(i);
}
}
else {
for (int i = 1; i <= m; i++) {
if (i != arr[i - 1] && i != arr[i + 1])
vec.push_back(i);
}
}
return vec;
}
int f(const vector<int>& arr, int n, int m) {
int totWays = 1;
for (int i = 0; i < n; i++) {
if (arr[i] == -1) {
vector<int> vec = getValidRep(arr, i, m);
totWays = (static_cast<long long>(totWays) * vec.size()) % MOD;
}
}
return totWays;
}
int main() {
int n = 5;
vector<int> v(n);
for(auto &it : v) cin>>it;
int m = 5;
cout << f(v, n, m) << endl; // Output: 4
return 0;
}
The thing is that , I cannot submit to test for the test cases as it was part of an OA and I can't find it on any online judge and I am not able to think of anythinf better. All kinds of inputs will be appreciated... Thanks