showing wrong answer for test case1
Found at last question
@ayush15goel hey ayush your code is not working for this case
5
6 9 3 9 0
9
your output is 1
but expected output is 3
sir I am not getting the idea how to get the expected output.Can you pl help
Hello @ayush15goel,
What your code is printing is the first occurrence of M.
Now, you can follow two approach.
-
instead of returning i, use a variable to store the index at which M is occurring and initialized it with -1.
Print the value of that variable when the base condition satisfies. -
instead of checking from the first index of sequence, start from the last index.
In this case, you have no need to take any extra variable.
Hope, this would help.
Give a like, if you are satisfied.
sir now wrong answer for test case 3
There are two errors and both are similar.
-
You are passing t. what is the maximum index of the array? Think.
-
Is it not possible that there is only one occurrence of M and that is at 0th index. Does your code check for the 0th index of array? Think.
Hope, this would help.
thanks sir.Got the mistake.Passing all test cases now
you can give a like, i wont mind.