1.

What will be the worst case time complexity of finding the sum of elements in a given range of (l,r) in an array of size n?(a) O(n)(b) O(l+r)(c) O(l-r)(d) O(r-l)This question was addressed to me during a job interview.I need to ask this question from Miscellaneous in division Miscellaneous of Data Structures & Algorithms II

Answer»

Correct answer is (a) O(n)

For explanation: For a GIVEN array of size n we have to TRAVERSE all n elements in the WORST CASE. In such a case l=0, r=n-1 so the time complexity will be O(n).



Discussion

No Comment Found

Related InterviewSolutions