retagged by
444 views
1 votes
1 votes

Pls Explain how to do this.

retagged by

2 Answers

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)
selected by
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++;

        }

}

Related questions

4 votes
4 votes
2 answers
1
0 votes
0 votes
0 answers
3