Google Interview Question for Software Engineer / Developers






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

#include "iostream"
#include <conio.h>
#include <string.h>
#include <math.h>
#include <cstdlib>
#include <time.h>
using namespace std;

void shuffle(int A[],int size)
{
int tmp;
for(int i = 0; i<size;i++)
{
srand ( time(NULL) );

int ran = rand()%(size-i);
tmp = A[size - i];
A[size - i] = A[ran];
A[ran] = tmp;
}
}

int main()
{
int A[10] = {1,2,3,4,5,6,7,8,9,10};
shuffle(A,9);

int j = 0;
while(j<9)
{
cout << A[j++] << " ";
}

getch();
return 0;
}

- Pavan February 11, 2011 | Flag Reply
Comment hidden because of low score. Click to expand.
0
of 0 votes

How do you ensure that all K set will be different.
I think you are not using K any where. I do not think only rand() will suffice for this condition.

- Anonymus February 12, 2011 | Flag
Comment hidden because of low score. Click to expand.
0
of 0 vote

one imp parameter missing is number of questions each question has to take, if not known one can probably get [n/k] questions

- Anonymous February 13, 2011 | Flag Reply
Comment hidden because of low score. Click to expand.
0
of 0 vote

use Fisher–Yates_shuffle card shuffling algorithm

- Swapnil February 17, 2011 | 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