Guruji Interview Question for Software Engineer / Developers






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

is {1, 3, 10} and {10, 1, 3} equivalent? Should both be print out?

- vodangkhoa April 22, 2007 | Flag Reply
Comment hidden because of low score. Click to expand.
0
of 0 vote

Here is the code.
Given: "1234" and N = 2
It would print out "13", "14", "24"

all other strings ("43","41"..) are just permutation of the above result.
Working code. Just copy and paste it to your favorite IDE then compile away.

#include <iostream>
#include <string>
void printComb(const char ar[], bool used[], int SIZE){
string str = "";
for (int i = 0; i < SIZE; ++i){
if (used[i]){
str += ar[i];
}
}
cout << str << endl;
}

//variable u keeps track of the number of
//characters in our result

void comb(const char ar[], bool used[], int index, int u, int N, int SIZE){
if (u == N){
printComb(ar, used, SIZE);
} else if (index >= SIZE){
return;
} else {
used[index] = true;
++u;
comb(ar, used, index + 2, u, N, SIZE);
used[index] = false;
--u;
comb(ar, used, index + 1, u, N, SIZE);
}
}

int main(){
int N = 2;
string str = "1234";
bool used[str.length()];
for (int i = 0; i < str.length(); ++i){
used[i] = false;
}
comb(str.c_str(), used, 0, 0, N, str.length());
}

- vodangkhoa April 22, 2007 | Flag Reply
Comment hidden because of low score. Click to expand.
0
of 0 vote

khoa's solutions looks ok!

- desiNerd April 23, 2008 | 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