What will be the worst case time complexity of code to find sum in given query range (l,r) in an array of size n with q number of such queries?
What will be the worst case time complexity of code to find sum in given query range (l,r) in an array of size n with q number of such queries? Correct Answer O(n*q)
For finding the result of one query the worst case time complexity will be n. So for q queries the time complexity will be O(q*n). This can be reduced by using square root optimization.
মোঃ আরিফুল ইসলাম
Feb 20, 2025