Amazon Interview Question for Software Engineer / Developers


Country: India
Interview Type: In-Person




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

Just plain bogus..

The overhead of setting up threads to do this in parallel will be too much. If you string is so big that it actually improves performance that you are probably doing something wrong.

- Anonymous October 20, 2011 | Flag Reply
Comment hidden because of low score. Click to expand.
0
of 0 votes

We both agreed on your point. But he just wanted to see if I can come up with a divide and conquer type algorithm to do this. We did this with an assumption of having unlimited number of processors and the parenthesis check might be replaces with a more processor intensive code block that will defeat the overhead of thread setup.

- msramachandran October 20, 2011 | Flag
Comment hidden because of low score. Click to expand.
0
of 0 votes

@msramachandran: which location you given interview in amazon and for what position exactly?

- Anonymous October 20, 2011 | Flag
Comment hidden because of low score. Click to expand.
0
of 0 votes

@Chennai for SDE 2

- msramachandran October 20, 2011 | Flag
Comment hidden because of low score. Click to expand.
0
of 0 votes

@msramachandran: i can thought of O(n) and O(n/2) as the best speed, by parsing from one end or both the ends of string. Is there any better solution then that and what is the Divide and conquer way to solve this ... I could not think of any sub problem for this one .

- Gaurav November 01, 2011 | Flag
Comment hidden because of low score. Click to expand.
0
of 0 vote

@msramachandran: Did you solve all the questions?

- Anonymous October 20, 2011 | Flag Reply
Comment hidden because of low score. Click to expand.
0
of 0 votes

yeah i did. :)

- msramachandran October 20, 2011 | Flag
Comment hidden because of low score. Click to expand.
0
of 0 votes

@msramachandran: one more question, you said you told the interviewer that you knew the question beforehand. What was the response from the interviewer? Should we tell them that I know the question already?

- Anonymous October 20, 2011 | Flag
Comment hidden because of low score. Click to expand.
0
of 0 votes

Well. I take interviews all the time. I can figure out if the candidate already knew the question and tries to fake it. And I am a little extra honest always :). So I don't telling him that I knew the solution already. It also cuts the crap and may be I will get a new question that I can break my head on.

He reacted saying "ok. but can you tell me the answer". For the second question, I told him that i knew the question and answer before he explained 25% of the question. Save a lot of time for both of us and it gave him a good opinion of myself.

- msramachandran October 20, 2011 | Flag
Comment hidden because of low score. Click to expand.
0
of 0 votes

Did u use careercup only for preparing for all the questions? from where all did u collect the questions? i am also preparing and planning to apply after a couple of months. are 2/3 months of preparation enof?
thanks.

- yyy December 06, 2011 | Flag
Comment hidden because of low score. Click to expand.
0
of 0 vote

int isValidParenthesis(char *str, int len) {
int count = 0, i;
for(i = 0; i < len; i++) {
if (str[i] == '[') {
count++;
}
else if (str[i] == ']') {
count--;
}
if (count < 0) {
return FALSE;
}
}
if (count > 0) {
return FALSE;
}
return TRUE;
}

- nagaraju October 23, 2011 | Flag Reply
Comment hidden because of low score. Click to expand.
0
of 0 votes

This is incorrect
example []][

Use stack .

- Anonymous March 01, 2012 | Flag
Comment hidden because of low score. Click to expand.
0
of 0 vote

// Function returns a pointer to end of string if its balanced
// Otherwise, string is imbalanced at next to the return pointer
char* check_balance( char *p )
{
	if( *p == '\0' || *p == ')' )
		return p;

	else if( *p == '(' )
	{
		p = check_balance(p+1);
		if( *p != ')' )
			return --p;
	}
	return check_balance(p+1);
}

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

// Function returns a pointer to end of string if its balanced
// Otherwise, string is imbalanced at next to the return pointer
char* check_balance( char *p )
{
	if( *p == '\0' || *p == ')' )
		return p;

	else if( *p == '(' )
	{
		p = check_balance(p+1);
		if( *p != ')' )
			return --p;
	}
	return check_balance(p+1);
}

- Sani October 28, 2011 | Flag Reply
Comment hidden because of low score. Click to expand.
0
of 0 vote

bool isBalanced(const char *str)
{
   assert(str);

   int oc = 0; // open paren count
   int len = strlen(str);

   for (int i = 0; i < len; ++i) {
      if (str[i] == '(')
         ++oc;
      else if (--oc < 0)
         return false;
   }

   return oc == 0;
}

- Anonymous September 28, 2016 | 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