InMobi Interview Question for SDE-2s


Country: India




Comment hidden because of low score. Click to expand.
0
of 0 vote

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

- sid July 20, 2014 | Flag Reply
Comment hidden because of low score. Click to expand.
0
of 0 vote

#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);
}

- Chintan October 07, 2015 | Flag Reply
Comment hidden because of low score. Click to expand.
0
of 0 vote

#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);
}

- Vivek October 07, 2015 | Flag Reply
Comment hidden because of low score. Click to expand.
0
of 0 vote

#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);

}

- Vivek October 07, 2015 | Flag Reply


Add a Comment
Name:

Writing Code? Surround your code with {{{ and }}} to preserve whitespace.

Books

is a comprehensive book on getting a job at a top tech company, while focuses on dev interviews and does this for PMs.

Learn More

Videos

CareerCup's interview videos give you a real-life look at technical interviews. In these unscripted videos, watch how other candidates handle tough questions and how the interviewer thinks about their performance.

Learn More

Resume Review

Most engineers make critical mistakes on their resumes -- we can fix your resume with our custom resume review service. And, we use fellow engineers as our resume reviewers, so you can be sure that we "get" what you're saying.

Learn More

Mock Interviews

Our Mock Interviews will be conducted "in character" just like a real interview, and can focus on whatever topics you want. All our interviewers have worked for Microsoft, Google or Amazon, you know you'll get a true-to-life experience.

Learn More