Qumulo Interview Question for Member Technical Staffs


Country: United States
Interview Type: In-Person




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

Google for this question and you will get many links. Below is just simple plain implementation.

# your code goes here

def get_result(operator, operand1, operand2):
	operand1 = int(operand1)
	operand2 = int(operand2)
	
	if operator == str("*"):
		return operand1*operand2;
	if operator == str("+"):
		return operand1+operand2;
	if operator == str("-"):
		return operand1-operand2;	
	if operator == str("/"):
		return operand1/operand2;
	if operator == str("="):
		return operand1 == operand2;		
		
def evaluate(expr):
	stack = []
	operand_cound = 0
	operators = ['*', '+', '-', '/', '=']
	for i in expr[::-1]:
		print i
		operand1 = None
		operator = None
		if i not in operators:
			stack.append(i)
		elif i in operators:
			operand1 = stack.pop()
			operand2 = stack.pop()
			stack.append(get_result(i, operand1, operand2))
	return stack.pop()

print evaluate("-*+4325")

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

I'm curious how your code will perform agains the expresssion in question i.e. * - 6 5 7 = 7?
Strting from the left, your stack will contain one 7 before = expression is encountered, when you try to remove
2 operands from the stack, you only have 1 operand -> err
Instead I would suggest also pushing in the = operator into the stack

- puneet.sohi November 11, 2015 | Flag
Comment hidden because of low score. Click to expand.
0
of 0 vote

Both prefix and postfix can be implemented using a simple strategy using a stack(LIFO). We assume the
current prefix/postfix expression is present in a queue(FIFO)
A general algo is:

Till queue empty
  Dequeue one element from queue
    if element is a number/operand or an = expression
      push it into the stack
    else //element is an operand like + - * etc
      pop top two elements from stack
      perform the operation using the operand
      push result onto stack

      if(stack becomes empty before two elements can be popped)
	error! 

At this point, your queue will contain one element i.e. the answer

- puneet.sohi November 11, 2015 | Flag Reply
Comment hidden because of low score. Click to expand.
0
of 0 vote

public static boolean isInteger(String token) {
        if (token == null)
            return false;
        try {
            Integer.parseInt(token);
        } catch (NumberFormatException e) {
            return false;
        }

        return true;
    }

    public static void main(String[] args) {
        Deque<Character> stack = new ArrayDeque<>();

        Scanner scanner = new Scanner(System.in);

        Integer num1 = null, num2 = null;
        String token;
        while (scanner.hasNext()) {
            token = scanner.next();

            if (!isInteger(token)) {
                stack.addFirst(token.charAt(0));
            }
            else {
                if (num1 == null) {
                    num1 = new Integer(Integer.parseInt(token));
                }
                else {
                    num2 = new Integer(Integer.parseInt(token));

                    switch (stack.removeFirst()) {
                        case '+':
                            num1 = num1 + num2;
                            break;
                        case '-':
                            num1 = num1 - num2;
                            break;
                        case '*':
                            num1 = num1 * num2;
                            break;
                        case '/':
                            num1 = num1 / num2;
                            break;
                        default:
                            System.out.println("Unsupported operation");
                            return;
                    }
                }
            }
        }

        System.out.println("Answer: " + num1);
    }

- aman.wardak December 28, 2015 | 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