After printing all the indices where element is found,than in rest of array my code is printing 0

@ishikagoel8218
It is printing 0 for rest of the elements because by default when,array is declared its each index contains 0.
In your code.As when arr2 is initialised at each index its all indexes contains 0.
hence where the value is not found it will print zero.
it can be avoided by placing “-1” as marker,i.e making each element of array as “-1”.
Now we will print only when the array element is not “-1” and rest of your logic and code is correct.
Please refer this code for better understanding:


If it helps please hit a like,else ask your doubts here,we will be happy to help you.