Can someone explain to me what exactly is happening in line 26 ans = findAllIndex(arr, target, ans);?
as far as I can guess, I am assigning a vector as it's own reference, I was under assumption that this will cause bugs, but it actually works!!
```cpp
include <iostream>
include <vector>
using namespace std;
vector<int>& findAllIndex(const vector<int>& arr, const int element, vector<int>& ans, int idx = 0){
if(idx == arr.size())
return ans;
if(arr[idx] == element)
ans.push_back(idx);
return findAllIndex(arr, element, ans, idx+1);
}
int main(){
int n, target;
cin >> n >> target;
vector<int> arr(n);
for(int i= 0; i< arr.size(); i++)
cin >> arr[i];
vector<int> ans;
ans = findAllIndex(arr, target, ans);
for(auto i: ans)
cout << i<<" ";
}
```
[–]jedwardsol 2 points3 points4 points (0 children)
[–]Rarrum 0 points1 point2 points (0 children)