## InMobi Interview Question

SDE-2s**Country:**India

#include<bits/stdc++.h>

#include "iostream"

using namespace std;

int maximumStreak(int* arr, int s,int g){

int start = 0 ; // represents the starting index of array

int end = 0; // represents the ending index of array

int ans = INT_MIN;

while(start<=end && end<s){

if(arr[end]-arr[start]+1<=end-start+1+g){

int l = arr[end]-arr[start]+1;

int r = end-start+1;

ans = max(ans,r+g);

end++;

}

else

start++;

}

return ans;

}

int main(){

int s,g;

cin>>s>>g;

int silver[s];

for(int i=0;i<s;i++){

cin>>silver[i];

}

sort(silver,silver+s);

// removing dupicates

int arr[s];

int index = 0;

for(int i=0;i<s-1;i++){

if(silver[i]!=silver[i+1])

arr[index++] = silver[i];

if(i==s-2)

arr[index++] = silver[s-1];

}

cout<<maximumStreak(arr,index,g);

}

```
#include<bits/stdc++.h>
#include "iostream"
using namespace std;
int maximumStreak(int* arr, int s,int g){
int start = 0 ; // represents the starting index of array
int end = 0; // represents the ending index of array
int ans = INT_MIN;
while(start<=end && end<s){
if(arr[end]-arr[start]+1<=end-start+1+g){
int l = arr[end]-arr[start]+1;
int r = end-start+1;
ans = max(ans,r+g);
end++;
}
else
start++;
}
return ans;
}
int main(){
int s,g;
cin>>s>>g;
int silver[s];
for(int i=0;i<s;i++){
cin>>silver[i];
}
sort(silver,silver+s);
// removing dupicates
int arr[s];
int index = 0;
for(int i=0;i<s-1;i++){
if(silver[i]!=silver[i+1])
arr[index++] = silver[i];
if(i==s-2)
arr[index++] = silver[s-1];
}
cout<<maximumStreak(arr,index,g);
}
```

```
#include<bits/stdc++.h>
#include "iostream"
using namespace std;
int maximumStreak(int* arr, int s,int g){
int start = 0 ; // represents the starting index of array
int end = 0; // represents the ending index of array
int ans = INT_MIN;
while(start<=end && end<s){
if(arr[end]-arr[start]+1<=end-start+1+g){
int l = arr[end]-arr[start]+1;
int r = end-start+1;
ans = max(ans,r+g);
end++;
}
else
start++;
}
return ans;
}
int main(){
int s,g;
cin>>s>>g;
int silver[s];
for(int i=0;i<s;i++){
cin>>silver[i];
}
sort(silver,silver+s);
// removing dupicates
int arr[s];
int index = 0;
for(int i=0;i<s-1;i++){
if(silver[i]!=silver[i+1])
arr[index++] = silver[i];
if(i==s-2)
arr[index++] = silver[s-1];
}
cout<<maximumStreak(arr,index,g);
```

}

Can you please explain the question by little solving it.. :)

- sid July 20, 2014