#include <iostream>
#include <vector>
using namespace std;
vector<int> occ(int n, vector<int>& a, int t) {
// Base case
if (n == 0) {
return vector<int>();
}
// Get the vector from the recursive call first
vector<int> ans = occ(n - 1, a, t);
// Check the current element and append if it matches
if (a[n - 1] == t) {
ans.push_back(n - 1);
}
return ans;
}
int main() {
int n = 5;
vector<int> a = {1, 3, 5, 6, 5};
int t = 5;
vector<int> ans = occ(n, a, t);
// Output should be: 24 (since 5 is at index 2 and index 4)
for (int i = 0; i < ans.size(); i++) {
cout << ans[i] << " ";
}
return 0;
}
I2luY2x1ZGUgPGlvc3RyZWFtPgojaW5jbHVkZSA8dmVjdG9yPgp1c2luZyBuYW1lc3BhY2Ugc3RkOwoKdmVjdG9yPGludD4gb2NjKGludCBuLCB2ZWN0b3I8aW50PiYgYSwgaW50IHQpIHsKICAgIC8vIEJhc2UgY2FzZQogICAgaWYgKG4gPT0gMCkgewogICAgICAgIHJldHVybiB2ZWN0b3I8aW50PigpOwogICAgfQogICAgCiAgICAvLyBHZXQgdGhlIHZlY3RvciBmcm9tIHRoZSByZWN1cnNpdmUgY2FsbCBmaXJzdAogICAgdmVjdG9yPGludD4gYW5zID0gb2NjKG4gLSAxLCBhLCB0KTsKICAgIAogICAgLy8gQ2hlY2sgdGhlIGN1cnJlbnQgZWxlbWVudCBhbmQgYXBwZW5kIGlmIGl0IG1hdGNoZXMKICAgIGlmIChhW24gLSAxXSA9PSB0KSB7CiAgICAgICAgYW5zLnB1c2hfYmFjayhuIC0gMSk7CiAgICB9CiAgICAKICAgIHJldHVybiBhbnM7Cn0KCmludCBtYWluKCkgewogICAgaW50IG4gPSA1OwogICAgdmVjdG9yPGludD4gYSA9IHsxLCAzLCA1LCA2LCA1fTsKICAgIGludCB0ID0gNTsKICAgIAogICAgdmVjdG9yPGludD4gYW5zID0gb2NjKG4sIGEsIHQpOwogICAgCiAgICAvLyBPdXRwdXQgc2hvdWxkIGJlOiAyNCAoc2luY2UgNSBpcyBhdCBpbmRleCAyIGFuZCBpbmRleCA0KQogICAgZm9yIChpbnQgaSA9IDA7IGkgPCBhbnMuc2l6ZSgpOyBpKyspIHsKICAgICAgICBjb3V0IDw8IGFuc1tpXSA8PCAiICI7CiAgICB9CiAgICAKICAgIHJldHVybiAwOwp9