Header Ads Widget

Number of elements -- TCS nqt solution

 Problem:-

Given an array with N non-negative integers and lower and upper limits R1 and R2, respectively. Find the number of elements x in the array such R1≤x≤R2.

Input:

5- Value of N

4- 1st element of arr

9- 2nd element of arr

10- 3rd element of arr 

30- 4th element of arr

20- 5th element of arr

1- Value of R1

25- Value of R2

Output:-

4

Code(C++):-

#include <iostream>
using namespace std;

int main()
{
int n;
cin>>n;
int a[n];
for(int i=0;i<n;i++)
cin>>a[i];
int r1,r2;
cin>>r1>>r2;
int ans=0;
for(int i=0;i<n;i++)
{
if(a[i]>=r1 && a[i]<=r2)
ans++;
}
cout<<ans;
return 0;
}

Recommended Post :-

HCL Coding Questions:-

Capgemini Coding Questions:-

Companies interview:-

Full C course:-    

Key points:-

Cracking the coding interview:-

 Array and string:-

Tree and graph:-

Hackerearth Problems:-

Hackerrank Problems:-

Data structure:-

 MCQs:-