# Intel Coding Questions and Answers

## Intel Coding Questions with Solution

Here, on this page you will find all sample Intel Coding Questions with Solution, which will help you to prepare for Online Assessments and Technical Interviews of Intel for hiring freshers.

### Question 1 : Weird Terminal

#### Problem Statement :

Here is a weird problem in Susan’s terminal. He can not write more than two words each line, if she writes more than two, it takes only 2 words and the rest are not taken. So she needs to use enter and put the rest in a new line. For a given paragraph, how many lines are needed to be written in Susan’s terminal?

Input Format:

A string as the text to input in the terminal

Output Format:

Number of lines written.

Constraints:

Number of words <=10^7

Sample Input:

How long do you have to sit dear ?

Sample Output:

4

Explanation:

The writing will be:

How long

Do you

Have to

Sit dear ?

### Related Banners

Get PrepInsta Prime & get Access to all 200+ courses offered by PrepInsta in One Subscription

Run

```#include<bits/stdc++.h>

using namespace std;

int main() {
string s;
getline(cin, s);
int ans = 0;
istringstream ss(s);
while (ss) {
string word;
int flag = 0;
ss >> word;
if (word == "") break;
for (int i = 0; i < word.length(); i++)
if (!isalpha(word[i])) {
if (i != 0) {
if (i == word.length() - 1) {
if (word[i] == ',' || word[i] == '.' || word[i] == ';' || word[i] == ':' || word[i] == '?' || word[i] == '!') continue;
} else if (word[i] == '.' && word[i + 1] != '.') {
flag++;
break;
} else if (word[i] == '-' && isalpha(word[i + 1])) continue;
else {
flag++;
break;
}
} else {
flag++;
break;
}

}

if (flag == 0) {
ans++;
//cout <<word<<" "<<word.length()<<endl;
}
}
cout << floor((ans - 1) / 2) + 1;
}
```
Run
```s=input()
n=len(s)
s1=''
for i in range(n):
if s[i]=='-':
s1+=''
continue
if s[i]=='.' or s[i]=='!' or s[i]==',' or s[i]=='?':
s1+=' '
continue
else:
s1+=s[i]
a=list(s1.split())
c=0

for i in a:
i1=0
for j in i:
if not ((ord(j)>=65 and ord(j)<=90) or (ord(j)>=97 and ord(j)<=122)):
i1=1
break
if i1==0:
c+=1

print((c-1)//2 +1)

```

### Question 2 : Devil Groups (R->Easy)

Problem Statement  :
There are some groups of devils and they splitted into people to kill them. Devils make People to them left as their group and at last the group with maximum length will be killed. Two types of devils are there namely “@” and “\$”
People is represented as a string “P”

Input Format:
First line with the string for input

Output Format:
Number of groups that can be formed.

Constraints:
2<=Length of string<=10^9

Input string
PPPPPP@PPP@PP\$PP

Output
7

Explanation
4 groups can be formed
PPPPPP@
PPP@
PP\$
PP

Most people in the group lie in group 1 with 7 members.

Run
```#include<bits/stdc++.h>
using namespace std;
int main() {
std::string str;
std::cin >> str;
std::replace(str.begin(), str.end(), '@', ' ');
std::replace(str.begin(), str.end(), '\$', ' ');
std::vector arr;
std::string word;
for (char c : str) {
if (c == ' ') {
if (!word.empty()) {
arr.push_back(word);
word.clear();
}
} else {
word += c;
}
}
if (!word.empty()) {
arr.push_back(word);
}
int max = 0;
for (const std::string& word : arr) {
max = std::max(max, static_cast(word.length()));
}
std::cout << max + 1 << std::endl;
return 0;
}```
Run
```import java.util.*;
class Main
{
public static void main(String[] args)
{
Scanner sc=new Scanner(System.in);
String str=sc.next();
str=str.replace("@"," ");
str=str.replace("\$"," ");
String arr[]=str.split(" ");
int max=0;
for(int i=0;i < arr.length;i++)
max=Math.max(max,arr[i].length());
System.out.println(max+1);

}
}

```
Run
```s=input()
s=s.replace("@"," ").replace("\$"," ")
s=s.split()
ans=[]
for i in s:
ans.append(len(i)+1)
ans[-1]-=1
print(max(ans))
```

### Question 3 : Airport Authority

Problem Statement -:

In an airport, the Airport authority decides to charge a minimum amount to the passengers who are carrying luggage with them. They set a threshold weight value, say, T, if the luggage exceeds the weight threshold you should pay double the base amount. If it is less than or equal to threshold then you have to pay \$1.

Function Description:

Complete the weightMachine function in the editor below. It has the following parameter(s):

Parameters:

 Name Type Description N Integer number of luggage T Integer weight of each luggage weights[ ] Integer array threshold weight

Returns: The function must return an INTEGER denoting the required amount to be paid.

Constraints:

• 1 <= N <= 10^5
• 1 <= weights[i] <= 10^5
• 1 <= T <= 10^5

Input Format for Custom Testing:

• The first line contains an integer, N, denoting the number of luggage.
• Each line i of the N subsequent lines (where 0 <= i <n) contains an integer describing the weight of ith luggage.
• The next line contains an integer, T, denoting the threshold weight of the boundary wall.

Sample Cases:

• Sample Input 1
4
1
2
3
4
3
• Sample Output 1
5
• Explanation:
Here all weights are less than threshold weight except the luggage with weight 4 (at index 3) so all pays base fare and it pays double fare.
Run
```#include<stdio.h>
long int weightMachine(long int N,long int weights[],long int T)
{
long int amount=0,i;
for(i=0;i<N;i++) { amount++; if(weights[i]>T)
{
amount++;
}
}
return amount;
}
int main()
{
long int N,i,T;
scanf("%ld",&N);
long int weights[N];
for(i=0;i<N;i++)
{        scanf("%ld",&weights[i]);
}
scanf("%ld",&T);
printf("%ld",weightMachine(N,weights,T));
return 0;
}```
Run
```#include <bits/stdc++.h>
using namespace std;
long int weightMachine(long int N,long int weights[],long int T)
{
long int amount=0,i;
for(i=0;i<N;i++) { amount++; if(weights[i]>T)
{
amount++;
}
}
return amount;
}
int main()
{
long int N,i,T;
cin>>N;
long int weights[N];
for(i=0;i<N;i++) { cin>>weights[i];
}
cin>>T;  cout<<weightMachine(N,weights,T);
return 0;
}```
Run
```import java.util.*;
class Main
{
static int weightMachine (int N, int weights[],int T)
{
int amount = 0, i;
for (i = 0; i < N; i++) { amount++; if (weights[i] > T)
{
amount++;
}
}
return amount;
}

public static void main (String[]args)
{
Scanner sc = new Scanner (System.in);
int n = sc.nextInt ();
int weights[]= new int[n];
for(int i=0; i<n; i++)
weights[i] = sc.nextInt();
int t = sc.nextInt ();
System.out.println (weightMachine(n, weights, t));
}
}```
Run
```def weightMachine(N,weights,T):
amount=0
for i in weights:
amount+=1
if(i>T):
amount+=1
return amount
N=int(input())
weights=[]
for i in range(N):
weights.append(int(input()))
T=int(input())
print(weightMachine(N,weights,T))```

### Question 4 : Simple problem

Problem Statement :

Mr X is a teacher of maths. He came across a very simple problem. In the problem you have to arrange the numbers in an ascending order and calculate the total number of swaps required. The number of swaps must be minimum. But Mr X is busy with some other tasks and you being his favourite student , so he asks you to solve this problem.

Constraints:

1<=T<=100
1<=N<=100
1<=A[ ] <=1000
Examples

Input :
4
4 3 1 2
Output:
2
Explanation: Swap index 0 with 3 and 1 with 2 to form the sorted array {1, 2, 3, 4}.

Input :
5
1 5 4 3 2
Output :
2

Run
```#include <bits/stdc++.h>

using namespace std;

int main() {
int n;
cin >> n;
vector < int > arr(n);
for (int i = 0; i < n; i++) cin >> arr[i];
vector < pair < int, int >> ap(n);
for (int i = 0; i < n; i++) {
ap[i].first = arr[i];
ap[i].second = i;
}
sort(ap.begin(), ap.end());
vector < bool > v(n, false);
int ans = 0;

for (int i = 0; i < n; i++) { if (v[i] || ap[i].second == 1) continue; int cs = 0, j = i; while (!v[j]) { v[j] = 1; j = ap[j].second; cs++; } if (cs > 0) ans += cs - 1;
}
cout << ans;
}
```
Run
```import java.util.Scanner;
public class Main {
static int minimumSwaps(int[] arr) {
int count = 0;
int i = 0;
while (i < arr.length) {
if (arr[i] != i + 1) {
while (arr[i] != i + 1) {
int temp = 0;
temp = arr[arr[i] - 1];
arr[arr[i] - 1] = arr[i];
arr[i] = temp;
count++;
}
}
i++;
}
return count;
}
public static void main(String[] args) {
Scanner ss = new Scanner(System.in);
int n = ss.nextInt();
int[] arr = new int[n];
for (int i = 0; i < n; i++) {
arr[i] = ss.nextInt();
}

System.out.println(minimumSwaps(arr));
}
}
```
Run
```n = int(input())
ar = list(map(int, input().split()))
arrpos = list(enumerate(ar))
arrpos.sort(key=lambda it: it[1])
vis = {k: False for k in range(n)}
ans = 0
for i in range(n):
if vis[i] or arrpos[i][0] == i:
continue
j = i
cycles = 0
while vis[j] == False:
vis[j] = True
cycles += 1
j = arrpos[j][0]
if cycles > 0:
ans += cycles - 1
print(ans)

```

### Question 5 : Set Bit

Problem Statement  :

You are given an integer, N. You have to turn it into the binary representation of it, and find out how many set bits are there in the binary representation.

Input Format:
The first line contains the integer.

Output Format:
One line containing an integer denoting the number of setbits.

Constraints:
1<=N<=10^9

Sample Input:
8
Output:
1

Output Description:
8 in binary is 1000.

Run
```#include <bits/stdc++.h>

using namespace std;

int main() {
int n, ans = 0;
cin >> n;
while (n) {
n &= (n - 1);
ans++;
}
cout << ans;
}```
Run
```import java.util.*;
public class Main {
public static void main(String[] args) {
Scanner sc = new Scanner(System.in);
int n = sc.nextInt();
int count = 0;
while (n != 0) {
if ((n & 1) == 1)
count++;
n = n >> 1;
}
System.out.println(count);
}
}
```
Run
```n = int(input())
ans = 0
while n:
n &= n - 1
ans += 1
print(ans)
```

### Question 6:

Problem Statement –  Abhijeet is one of those students who tries to get his own money by part time jobs in various places to fill up the expenses for buying books. He is not placed in one place, so what he does, he tries to allocate how much the book he needs will cost, and then work to earn that much money only. He works and then buys the book respectively. Sometimes he gets more money than he needs so the money is saved for the next book. Sometimes he doesn’t. In that time, if he has stored money from previous books, he can afford it, otherwise he needs money from his parents.

Now His parents go to work and he can’t contact them amid a day. You are his friend, and you have to find how much money minimum he can borrow from his parents so that he can buy all the books.

He can Buy the book in any order.

Function Description:

Complete the function with the following parameters:

 Name Type Description N Integer How many Books he has to buy that day. EarnArray[ ] Integer array Array of his earnings for the ith book CostArray[ ] Integer array Array of the actual cost of the ith book.

Constraints:

• 1 <= N <= 10^3
• 1 <= EarnArray[i] <= 10^3
• 1 <=  CostArray[i] <= 10^3

Input Format:

• First line contains N.
• Second N lines contain The ith earning for the ith book.
• After that N lines contain The cost of the ith book.

Output Format: The minimum money he needs to cover the total expense.

Sample Input 1:

3

[3 4 2]

[5 3 4]

Sample Output 1:

3

Explanation:

At first he buys the 2nd book, which costs 3 rupees, so he saves 1 rupee. Then he buys the 1st book, that takes 2 rupees more. So he spends his stored 1 rupee and hence he needs 1 rupee more. Then he buys the last book.

Run
```#include<bits/stdc++.h>
using namespace std;

int main() {
int n, ans = 0, sum = 0;
cin >> n;

vector< int > arr1(n), arr2(n);
for (int i = 0; i < n; i++) { cin >> arr2[i];
}
for (int i = 0; i < n; i++) { cin >> arr1[i];
}
for (int i = 0; i < n; i++) {
arr2[i] -= arr1[i];
}
sort(arr2.begin(), arr2.end(), greater< int >());
for (int i = 0; i < n; i++) {
sum += arr2[i];
if (sum < 0) {
ans += abs(sum);
sum = 0;
}
}
cout << ans << endl;

return 0;
}
```
Run
```n = int(input())
ans = 0
su = 0

arr2 = list(map(int, input().split()))
arr1 = list(map(int, input().split()))

for i in range(n):
arr2[i] -= arr1[i]

arr2.sort(reverse=True)

for i in range(n):
su += arr2[i]
if su < 0:
ans += abs(su)
su = 0

print(ans)
```
Run
```import java.util.*;
class Main
{
public static void main(String args[])
{
Scanner sc = new Scanner (System.in);
int n=sc.nextInt();
int arr1[]= new int[n];
int arr2[]= new int[n];
for(int i=0; i<n; i++)
arr2[i]=sc.nextInt();
for(int i=0; i<n; i++)
arr1[i]=sc.nextInt();
for(int i=0; i<n; i++) arr2[i] -= arr1[i]; Arrays.sort(arr2); int sum=0, ans=0; for(int i=n-1; i>=0; i--)
{
sum+=arr2[i];
if(sum<0)
{
sum = -sum;
ans= ans +sum ;
sum=0;
}
}
System.out.println(ans);
}
}```

### Question 7:

You have a positive integer m and a non-negative integer s. Your task is to find the smallest and the largest of the numbers that have length m and sum of digits s. The required numbers should be non-negative integers written in the decimal base without leading zeroes.

Input

• The single line of the input contains a pair of integers m, s (1 ≤ m ≤ 100, 0 ≤ s ≤ 900) — the length and the sum of the digits of the required numbers.

Output

• In the output print the pair of the required non-negative integer numbers — first the minimum possible number, then — the maximum possible number. If no numbers satisfying conditions required exist, print the pair of numbers “-1 -1” (without the quotes).

Examples

• Input 1
2 15
• Output 1
69 96
• Input 2
3 0
• Output 2
-1 -1
Run
```n,s=map(int,input().split())
if(n>1 and s==0):
print(-1 , -1)

elif(n==1 and s==0):
print(0, 0)

else:
br=[0]*n
i=0
brk=0
while(s>0):
if(i<n):
br[i]=min(9,s)
s=s-br[i]
i=i+1
else:
print(-1, -1)
brk=1
break

if(brk==0):
maxm=0
i=10
j=0
while(j<n): maxm=maxm*i + br[j] j+=1 #print(maxm) minm=0 j=n-1 i=10 f=0 while(j>=0):
if(j==n-1 and br[j]==0):
minm=minm+1

f=1
else:
if(br[j]>0 and f==1):
minm=minm*i + br[j]-1
f=0

else:
minm=minm*i + br[j]
#print('h')

j=j-1

print(minm,maxm)
```
Run
```import java.util.*;
class Solution
{
public static void solve(int m,int s)
{
int sum=s-1;
if(m!=-1&&s==0 || s>9*m)
{
System.out.println("-1 -1");
return;
}
String res1="",res2="";
for(int i=0;i< m;i++)
{
res1+=Math.min(s,9);
s=s-Math.min(9,s);
}

for(int i=0;i< m-1;i++)
{
res2+=Math.min(sum,9)+res2;
sum=sum-Math.min(9,sum);
}
res2=(sum+1)+res2;
System.out.println(res2+ " "+res1);
}
public static void main(String[] args)
{
Scanner sc=new Scanner(System.in);
int m=sc.nextInt();
int s=sc.nextInt();
solve(m,s);
}
}
```
Run
```#include<bits/stdc++.h>
using namespace std;

void number (int m, int s)
{

int sum = s;

string mini = "", maxi = "";

if ((m != -1 and s == 0) or s > 9 * m)
{
cout << "-1 -1";
return;
}

for (int i = 0; i < m; i++)
{
int x = min (9, s);
maxi += to_string (x);

s = s - x;
}

for (int i = 0; i < m - 1; i++)
{
int x = min (9, sum);
mini += to_string (x);

sum -= x;
}

mini = to_string (sum) + mini;

cout << mini << " " << maxi; return; } int main () { int m, s; cin >> m >> s;

number (m, s);

return 0;
}
```

### Question 8: Queries for Count

The task is to determine the number of elements within a specified range in an unsorted array. Given an array of size n, the goal is to count the elements that fall between two given values, i and j, inclusively.
Examples:

Input:
Array: [1, 3, 3, 9, 10, 4]
Range 1: i = 1, j = 4
Range 2: i = 9, j = 12

Output:
For Range 1: 4
For Range 2: 2

Explanation:
In the first query, the numbers within the range 1 to 4 are 1, 3, 3, and 4.
In the second query, the numbers within the range 9 to 12 are 9 and 10.

Run
```#include<bits/stdc++.h>
using namespace std;

int findLowerIndex(int arr[], int n, int x) {
int low = 0, high = n - 1;
while (low <= high) { int mid = (low + high) / 2; if (arr[mid] >= x)
high = mid - 1;
else
low = mid + 1;
}
return low;
}

int findUpperIndex(int arr[], int n, int y) {
int low = 0, high = n - 1;
while (low <= high) {
int mid = (low + high) / 2;
if (arr[mid] <= y)
low = mid + 1;
else
high = mid - 1;
}
return high;
}

int countElementsInRange(int arr[], int n, int x, int y) {
int count = 0;
count = findUpperIndex(arr, n, y) - findLowerIndex(arr, n, x) + 1;
return count;
}

int main() {
int arr[] = {1, 4, 4, 9, 10, 3};
int n = sizeof(arr) / sizeof(arr[0]);

sort(arr, arr + n);

int lowerRange = 1, upperRange = 4;
cout << countElementsInRange(arr, n, lowerRange, upperRange) << endl;

lowerRange = 9;
upperRange = 12;
cout << countElementsInRange(arr, n, lowerRange, upperRange) << endl;

return 0;
}

```
Run
```def find_lower_index(arr, x):
low, high = 0, len(arr) - 1
while low <= high: mid = (low + high) // 2 if arr[mid] >= x:
high = mid - 1
else:
low = mid + 1
return low

def find_upper_index(arr, y):
low, high = 0, len(arr) - 1
while low <= high:
mid = (low + high) // 2
if arr[mid] <= y:
low = mid + 1
else:
high = mid - 1
return high

def count_elements_in_range(arr, x, y):
arr.sort()
lower_index = find_lower_index(arr, x)
upper_index = find_upper_index(arr, y)
count = upper_index - lower_index + 1
return count

arr = [1, 4, 4, 9, 10, 3]
lower_range = 1
upper_range = 4
print(count_elements_in_range(arr, lower_range, upper_range))

lower_range = 9
upper_range = 12
print(count_elements_in_range(arr, lower_range, upper_range))

```
Run
```import java.util.Arrays;

class Main {
static int findLowerIndex(int[] arr, int n, int x) {
int low = 0, high = n - 1;
while (low <= high) { int mid = (low + high) / 2; if (arr[mid] >= x)
high = mid - 1;
else
low = mid + 1;
}
return low;
}

static int findUpperIndex(int[] arr, int n, int y) {
int low = 0, high = n - 1;
while (low <= high) {
int mid = (low + high) / 2;
if (arr[mid] <= y)
low = mid + 1;
else
high = mid - 1;
}
return high;
}

static int countElementsInRange(int[] arr, int n, int x, int y) {
int count = 0;
count = findUpperIndex(arr, n, y) - findLowerIndex(arr, n, x) + 1;
return count;
}

public static void main(String[] args) {
int[] arr = {1, 4, 4, 9, 10, 3};
int n = arr.length;

Arrays.sort(arr);

int lowerRange = 1, upperRange = 4;
System.out.println(countElementsInRange(arr, n, lowerRange, upperRange));

lowerRange = 9;
upperRange = 12;
System.out.println(countElementsInRange(arr, n, lowerRange, upperRange));
}
}

```

### Question 9: Find the homeless

Problem Statement -:  There are N Homeless people in the community and N houses in the community. It will be given in the array (people), the height of the person, and in the array house capacity of the house is given.

The government decided to give homes to people on the basis of the following conditions:

• Priority is given to the people from left to right of the array
• Each person is allotted to a house if and only if the capacity of the house is greater than or equal to the person’s height
• Nearby empty Houses are allotted to the person( starting from the extreme left)

You need to find the number of homeless people who have not been allotted any home if the government follows the above conditions. So that government will have an idea of how many people they need to allot homes for next time.

Constraints:

• 1 <= N <= 10^3
• 1 <= people[i] <= 10^5
• 1 <= house[i] <= 10^5

Input Format for Custom Testing:

• The first line contains an integer, N, denoting the number of  people and number of houses.
• Each line i of the N subsequent lines (where 0 <= i <= N) contains an integer describing peoplei.
• Each line i of the N subsequent lines (where 0 <= i <= N) contains an integer describing housei.

Sample Test Cases

• Sample Input 1
3
4
2
7
3
5
10
• Sample Output 1
0
• Explanation
people=[4,2,7]
house=[3,5,10]
People[0] has more priority , from left to right order in houses 5 is the nearest one which fits for people[0]
people[1]=2 will fit in 3 which is nearer from left
people[2]=7 will fit in remaining house of capacity of 10
So no homeless people left so return 0
• Sample Input 2
3
3
8
5
1
9
4
• Sample Output 2
2
• Explanation
people=[3,8,5]
house=[1,9,4]
people[0]=3 can fit in 9 which is nearest from left in array house
people[1]=8  cannot fit in any home which is left (i.e, 1 and 4)
people[2]=5 cannot fit in any home which is left (i.e, 1 and 4)
So return 2,which is number of homeless people
Run
```#include<bits/stdc++.h>
using namespace std;
int main(){
int n;
cin>>n;
int people[n], house[n];
for(int i=0; i<n; i++) cin>>people[i];
for(int i=0; i<n; i++) cin>>house[i];
int count = 0;
for(int i=0; i<n; i++){
for(int j=0; j<n; j++){
if(people[i]<house[j]){
count+=1 ;
house[j]=-1;
break ;
}
}
}
cout<<n-count;
}
```
Run
```import java.util.*;
class Main
{
public static void main(String args[])
{
Scanner sc = new Scanner (System.in);
int n=sc.nextInt();
int people[]= new int[n];
int house[]= new int[n];
for(int i=0; i<n; i++)
people[i]=sc.nextInt();
for(int i=0; i<n; i++)
house[i]=sc.nextInt();
int count = 0;
for(int i=0; i<n; i++){
for(int j=0; j<n; j++){
if(people[i]<house[j]){
count+=1 ;
house[j]=-1;
break ;
}
}
}
System.out.println(n-count);
}
}
```
Run
```N=int(input())
people=[]
house=[]
#to read data of people and house arrays
for i in range(N): people.append(int(input()))
for i in range(N): house.append(int(input()))
count=0
for i in range(N):
for j in range(N):
if(people[i] < house[j]):
count+=1
house[j]=-1
break
print(N-count)
```

### Question 10:

Fountains are installed at every position along a one-dimensional garden of length n. Array locations[] represents the coverage limit of these fountains. The ith fountain (where 1sisn) has a coverage limit of locations[i] that can range from the position max((i – locations[i]), 1) to min((i + locations[i]), n ). In other words, the h fountains do not reach outside the boundaries of the garden. In the beginning,all the fountains are switched off. Determine the minimum number of fountains that need to be activated to cover the n length garden by water.

Example

• n = 3
• locations[] = {0, 2, 13, then
• For position 1: locations[1] = 0, max((1 – 0),
• 1) to mini (1+0), 3) gives range = 1 to 1
• For position 2: locations[2] = 2, max((2-2),
• 1) to min( (2+2), 3) gives range = 1 to 3
• For position 3: locations[3] = 1, max( (3-1),
• 1) to min( (3+1), 3) gives range = 2 to 3

For the entire length of this garden to be covered, only the fountain at position 2 needs to be activated.

Function Description

Complete the function fountainActivation in the editor below.

fountainActivation has the following Parameter:

• int locations[n]: the fountain locations

Returns

• int: the minimum number of fountains that must be activated

Constraints

• 1<_n<_ 10^5
•  O<_locations[i] <_ mini (n,100) (where 1 <_1<_10^5)

► Input Format For Custom Testing

Sample Case 0

Sample Input For Custom Testing

• 3 ->locations[] size n = 3
• 1 ->locations[] [1, 1, 1
• 1 ->Sample Output

Sample Output

• 1

Explanation

Here, locations = {1, 1, 13

• For position 1: locations[1] = 1, maxi (1 -1), 1) to min((1+1), 3) gives range = 1 to 2
• For position 2: locations[2] = 1, max( (2 -1), 1) to min( (2+1), 3) gives range = 1 to 3
• For position 3: locations[3] = 1, max((3 -1), 1) to min((3+1), 3) gyes range = 2 to 3

If the 2nd fountain is active, the range from position 7 to 3 will be covered. The total number of fountains needed is 1.

Run
```#include<bits/stdc++.h>

#define ll long long

using namespace std;

bool compare(pair < int, int > A, pair < int, int > B)

{

if (A.first = B.first)

return A.second < B.second;

return A.first < B.first;

}

int solve(int location[], int n)

{

pair < int, int > range[n];

for (int i = 0; i < n; i++)

{

int id = i + 1;

range[i].first = max(1, id - location[i]);

range[i].second = min(n, id + location[i]);

}

sort(range, range + n, compare);

int i = 0;

int ans = 0;

while (i < n)

{

pair < int, int > p = range[i];

ans++;

while (i + 1 < n && range[i].first == range[i + 1].first)

{

p.second = max(p.second, range[i + 1].second);

i++;

}

//cout<<p.second<<" "<<i<<endl;

while (i < n && range[i].second <= p.second)

i++;

//cout<<p.second<<" "<<i<<endl; } return ans; } int main() { int n; cin >> n;

int location[n];

for (int i = 0; i < n; i++) cin >> location[i];

cout << solve(location, n) << endl;

return 0;

}
```
Run
```import java.util.*;

class Main {

static int minCntFoun(int a[], int N) {

int[] dp = new int[N + 1];
Arrays.fill(dp, -1);

// Mark the reachable indices for each fountain
for (int i = 0; i < N; i++) {
int left = Math.max(i - a[i], 0);
int right = Math.min(i + a[i]+1, N);
dp[left] = Math.max(dp[left], right);
}

int cntfount = 1;
int idxRight = dp[0];
int idxNext = 0;

// Traverse the reachable indices and activate fountains
for (int i = 0; i < N; i++) {

idxNext=Math.max(idxNext,dp[i]);
if(i==idxRight){
cntfount++;
idxRight = idxNext;
}

}

return cntfount;
}

// Driver Code
public static void main(String[] args) {
Scanner scan=new Scanner(System.in);
int n = scan.nextInt();
int[] location=new int[n];
for(int i=0;i < n;i++){
location[i]=scan.nextInt();

}

System.out.print(minCntFoun(location, n));
}
}
```

## FAQs on Intel Coding Questions

##### Question 1: Is it hard to crack Interview Interview Process?

Candidates who have appeared for Intel Interview process claimed that Technical Interview of Intel is bit Hard because they generally ask questions based on DSA, DBMS, OOPs concept, along with Questions based on Computer Science Fundamentals and Computer System Architecture. etc with other core subjects related to Hardware Component of Computer.

##### Question 2: What are steps involved in Intel Recruitment process?

Intel Recruitment Process mainly consists of 3 steps:

1. Online Aptitude Test
2. Online Coding Assessment.
3. Technical Interview
4. HR Interview
##### Question 3: Does Intel includes of Group Discussion as the part of Interview ?

Yes, Sometimes Intel also conduct Group Discussion after Both Online Assessments followed by Technical Interview and HR Interview. It totally depends on the No. of Application they receive for Hiring.

## Get over 200+ course One Subscription

Courses like AI/ML, Cloud Computing, Ethical Hacking, C, C++, Java, Python, DSA (All Languages), Competitive Coding (All Languages), TCS, Infosys, Wipro, Amazon, DBMS, SQL and others