Given an array of length N and an integer X, you need to find all the indexes where X is present in the input array. Save all the indexes in an array (in increasing order).
Do this recursively. Indexing in the array starts from 0.
Input Format:
Line 1: An Integer N i.e. size of array
Line 2: N integers which are elements of the array, separated by spaces
Line 3: Integer x
Output Format:
indexes where x is present in the array (separated by space)
Constraints:
1 <= N <= 10^3
Example:
Input:
5
9 8 10 8 8
8
Output:
1 3 4
Algorithm:
To find the elements using recursion, we call upon a recursive function maintaining an output array, its size and a variable currIndex for traversal of the input array. The base case of this function will be if currIndex is equal to the size of Input array. i.e we have finished traversing the array. On every recursive call, the input element at currIndex is compared with ‘x’, and if it matches is then stored within the output array (and hence incrementing the output array size by 1). Next recursive call is made by incrementing the currIndex.
Source Code/Functions:
Output