Please look at my code and tell me what I am doing wrong? I guess the main problem is the size of the array. Could you please check?
Recursion Sorted array challenge
Hello @shreyajain,
Your code just has minor mistakes.
- In the recursive call, you have to pass n and not n-1 since you are updating the search element and not the array pointer. If you pass n-1, the last element of the array would be neglected at every call.
- Since in a sorted array there can be two or more equal elements, replace ‘<’ by ‘<=’.
- The base case should be searchelement == n-1 (i.e the last element has been reached).
Hit like if you get it.
1 Like
Thank you for your help!
1 Like
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.