Amazon Interview Question for Software Engineer in Tests






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

public static boolean isWellFormed(String input)
	{
		if(input==null) return true;
		if(input.length()==0) return true;
		
		Stack<Character> stack = new Stack<Character>();
		for(int i=0; i<input.length(); ++i)
		{
			char temp = input.charAt(i);
						
			if(temp =='[' || temp =='{' || temp =='(' ) 
				stack.push(temp);
			
			if(temp ==']' || temp == '}' || temp == ')') 
			{
				if(stack.isEmpty()) return false;
				if(temp != stack.pop()) return false;
			}
		}
		if(!stack.isEmpty()) return false;
		return true;
	}

- R May 02, 2011 | Flag Reply
Comment hidden because of low score. Click to expand.
0
of 0 vote

what is string id [}{)(]

- ravi May 06, 2011 | Flag Reply
Comment hidden because of low score. Click to expand.
0
of 0 vote

Using the above code with stack fails for the input [}{)(]

I have tried the classic way. Let me know, if you see any bugs.

public static bool isWellFormed(String input)
{
if (input == null) return true;
if (input.Length == 0) return true;

int count = 0;
for (int i = 0; i < input.Length; i++)
{
char iChar=input[i];
if (iChar == '(' || iChar == '{' || iChar == '[')
count++;

if (input[i] == ')' || iChar == '}' || iChar == ']')
count--;
}
return ((count==0)?true:false);
}

- kumar June 15, 2011 | Flag Reply
Comment hidden because of low score. Click to expand.
0
of 0 vote

@kumar
The question is to check for wellformed and not to count whether the number of opening and closing brackets match. You code does not do even the basic.

- coolvin June 25, 2011 | Flag Reply
Comment hidden because of low score. Click to expand.
0
of 0 vote

<pre lang="" line="1" title="CodeMonkey59664" class="run-this">import java.util.HashMap;
import java.util.Map;
import java.util.Stack;


public class WellFormedString {
static Map<Character, Character> map = new HashMap<Character, Character>();

static {
map.put(']', '[');
map.put('}', '{');
map.put(')', '(');
}

public static void main(String[] args) {
System.out.println(isWellFormed("(}"));
}

public static boolean isWellFormed(String input) {

if (input == null)
return true;

if (input.length() == 0)
return true;

Stack<Character> stack = new Stack<Character>();

for (int i = 0; i < input.length(); ++i) {
char temp = input.charAt(i);

if ((temp == '[') || (temp == '{') || (temp == '('))
stack.push(temp);

if ((temp == ']') || (temp == '}') || (temp == ')')) {

if (stack.isEmpty())
return false;

if (map.get(temp) != stack.pop())
return false;
}
}

if (!stack.isEmpty())
return false;

return true;
}
}

</pre><pre title="CodeMonkey59664" input="yes">
</pre>

- srav44 June 25, 2011 | Flag Reply
Comment hidden because of low score. Click to expand.
0
of 0 vote

import java.util.*;
public class wellFormed
{
public static void main(String []args)
{
String str="[[{]{(())}}]]";
if(isBalanced(str))
        System.out.println("balanced");
else
        System.out.println("not balanced");
}

public static boolean isBalanced(String str)
{
Stack<Character> s=new Stack<Character>();
for(int i=0;i<str.length();++i)
{
        if(str.charAt(i)=='{' || str.charAt(i)=='(' || str.charAt(i)=='[')
                s.push(str.charAt(i));
        if(str.charAt(i)=='}' || str.charAt(i)==')' || str.charAt(i)==']')
                if(!matchParenthesis(s.pop(),str.charAt(i)))
                        return false;
}
if(!s.isEmpty())
        return false;
return true;
}
public static boolean matchParenthesis(char a,char b)
{
        if((a=='{' && b=='}') || (a=='(' && b==')') || (a=='[' && b==']'))
                return true;
        else
                return false;
}
}

- nagarajmailing August 28, 2012 | Flag Reply
Comment hidden because of low score. Click to expand.
0
of 0 vote

(()(()))

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

public bool iswellformed(string str)
    {
        Stack<char> s = new Stack<char>();
        if (str.Length == 0)
            return false;
        for (int i = 0; i < str.Length; i++)
        {

                if ((str[i]=='{') || (str[i]=='[') || (str[i]=='('))
            {
                s.Push(str[i]); 
            }
                else if ((str[i] == '}') || (str[i] == ']') || (str[i] == ')'))
            {
                if (s.Count == 0)
                    return false;
                char pop = s.Pop();
                if ((str[i] != '}' && pop=='{') || ((str[i] != ']') && pop =='[') || ((str[i] != ')')&& pop=='('))
                    return false;
            }
        }
        if (s.Count != 0)
            return false;

        return true;
    }

- Royal October 13, 2013 | Flag Reply
Comment hidden because of low score. Click to expand.
0
of 0 vote

Hi Bru,


Such vivid info on the
Amazon Interview Question for Software Engineer in Tests ! Flabbergasted! Thank you for making the read a smooth sail!




The Make Public function in S3 is perfectly working these past few months and years I should say.
Just last week, we are experiencing failure in the "Make Public" function. Once I successfully upload a folder with multiple files) then Make Public the uploaded files, the notification below shows Failure

Anyways great write up, your efforts are much appreciated.


MuchasGracias,
Morgan

- Anonymous June 01, 2018 | 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