Code solution doubt

please check and tell if my code is more efficient than explained of not.

private static int[] allindex(int[] arr, int si, int data, int count) {

	if(si == arr.length)
		return new int[count];

	if(arr[si] == data) {
		count++;
		
	}
	 
	int[] arr2 = allindex(arr, si+1, data, count);
	if(count >=1)
		arr2[count-1] = si;
	return arr2;
}

For this particular queston, the best implementation that can be written is O(n). No other better than this solution can be written for this question and your code seems to hit a linear complexity so i think it’s complexity is just fine .

I hope I’ve cleared your doubt. I ask you to please rate your experience here
Your feedback is very important. It helps us improve our platform and hence provide you
the learning experience you deserve.

On the off chance, you still have some questions or not find the answers satisfactory, you may reopen
the doubt.