In the video Ma’am mentions that looking for an element from the right side of the array is a naive approach. But even the solution that Ma’am explained traverses the array once (which is the same as looking for an element from the right side in worst case if an element is present at the first position). So what is an efficient solution out of the two, searching an element’s last index from the right side or the solution explained by Ma’am?
Doubt in Last Index Hint video
hello @Ibrahim
see both solutions have time complexity O(n) .but traversing from right to left will be bit efficient becuase the moment we find the required number we will return.
which is not the case with another approach.
but still not much difference in the two given solutions both will take O(n) in worst case.
Sir I am not getting what does this line mean “traversing from right to left will be bit efficient becuase the moment we find the required number we will return.”? Does it mean that return is an inefficient task if the number of steps or number of comparisons is less?
right to left is efficient because we perform less comparision .that is all i want to convey.
Okay Sir, I got your point. Thank you.