Interview Question for SDE1s


Country: India




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

the error is in line:

if (str[j] == temp[i])

It should be:

if (str[j] == temp[0])

- zr.roman November 18, 2015 | Flag Reply
Comment hidden because of low score. Click to expand.
0
of 0 vote

need to initialize MAXLEN
final int MAXLEN = str.length();

- Prem Kumar November 18, 2015 | Flag Reply
Comment hidden because of low score. Click to expand.
0
of 0 votes

no, it is obvious that MAXLEN is a global variable and initialized in proper place.
You see, the code is just a separate function.

- zr.roman November 18, 2015 | Flag
Comment hidden because of low score. Click to expand.
0
of 0 vote

for(i=j=0, temp[i]=str[j]; j < MAXLEN && i < MAXLEN; j++)

- Sahil Kapoor November 18, 2015 | Flag Reply
Comment hidden because of low score. Click to expand.
1
of 1 vote

for(i=j=0, temp[i]=str[j]; j < MAXLEN; j++)

should work too.

- Sahil Kapoor November 18, 2015 | Flag
Comment hidden because of low score. Click to expand.
0
of 0 vote

str[j+1] == temp [i]

- Anil November 19, 2015 | Flag Reply
Comment hidden because of low score. Click to expand.
0
of 0 vote

i maybe negative, and the array will be out of boud.

- sakar2003 December 25, 2015 | Flag Reply
Comment hidden because of low score. Click to expand.
-1
of 1 vote

void checkBalance(string str)
{
	char temp[MAXLEN];
	int i, j;
	for (i = j = 0; temp[i] = str[j]; j++)
	{
		if (str[j+1] == temp[i]) // accessing more than last element of str
			i++;
	}
	if (i == 0)
		printf("Balanced\n");
	else
		printf("Not Balanced\n");
}

- Anonymous November 19, 2015 | Flag Reply
Comment hidden because of low score. Click to expand.
0
of 0 votes

what is condition to exit for loop?

- NewGuy November 25, 2015 | Flag


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