Doubt for question in hackerblocks

question: https://hack.codingblocks.com/app/dcb/473 OR “Count Subarray”

tried code: https://ide.codingblocks.com/s/269122

what i am doing wrong

hello @neelrai906
your solution time complexity is O(N^3)
which will give tle because value of N can be upto 10^7.

try to think of some better algorithm.

aside of complexity why output is wrong

subarray elements should in range left --right.

but u r only checking for maximum .

use two variables ,one to get minimum in subarray and other to get maximum in the subarray .
if min>=left and max <=right then only increment ur count

1 Like