1 votes 1 votes Pls Explain how to do this. Algorithms algorithms time-complexity made-easy-test-series + – Arnabi asked Jan 7, 2017 retagged Jul 9, 2022 by Lakshman Bhaiya Arnabi 444 views answer comment Share Follow See 1 comment See all 1 1 comment reply Samujjal Das commented Jan 7, 2017 reply Follow Share A simple for loop will do. for(i=1;i<n;i++) { if(a[i]>j && a[i]<k) { count++; } } Complexity O(n) 2 votes 2 votes Please log in or register to add a comment.
Best answer 1 votes 1 votes Just take a variable initialized to 0 and traverse the array and for each element compare if(A[i]<k &&A[i]>j) then i++ Thats it one time traversing array of size n, hence TC= O(n) Rahul Jain25 answered Jan 7, 2017 selected Jan 7, 2017 by Arnabi Rahul Jain25 comment Share Follow See all 0 reply Please log in or register to add a comment.
1 votes 1 votes All you need to do is iterate through the array and increment a count varaible whenever you find an element between the range j to k. check the code below. int count = 0; for(i=0;i<n;i++){ if(a[i]>=j&&a[i]<=k){ count++; } } Kaushik.P.E answered Jan 7, 2017 Kaushik.P.E comment Share Follow See 1 comment See all 1 1 comment reply Arnabi commented Jan 7, 2017 reply Follow Share Thanx all..:)got it now..i didnt understand the last two lines in the answer given by ME team. pls explain last two lines.. 0 votes 0 votes Please log in or register to add a comment.