## Morgan Stanley Interview Question for Software Engineer Interns

• 1
of 1 vote

Country: India
Interview Type: Written Test

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

1. Search a tree recursively, returning the minimum and maximum nodes. This should be pretty straight-forward.

2. Turn your problem into a tree. I would basically have the root (for your example) be 1+2*3+4*5, and then brackets get added as you move down the tree; a child of the root, for instance, could be (1+2)*3+4*5.

If you solve both of those problems, you'll have a recursive solution to your original question.

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

Why we need greedy or DP approach for this.
We can sort the numbers in decreasing order and place "+" between large numbers. when all given "+" are used then fill "-" between the numbers.
ex. 10+9+8+7+6-5-3-2-1
This will give us the maximum expression value.

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

No. You are intrepting the question incorrectly. It is given an expression with numbers ,+,- you need maximum output of that expression. For example: 10+9-3+1-2 can be treated as : 19-4-2 or 19-3-1 or 10+6-1 and objective is to get max sum of the given expression 10+9-3+1-2

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

Does this essentially mean parenthesizing the expression in such a way that maximizes its result?

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

This can be solved if we use back tracking to find permutations of the given expression arranging the numbers and the operators in different ways

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

1. Search a tree recursively, returning the minimum and maximum nodes. This should be pretty straight-forward.

2. Turn your problem into a tree. I would basically have the root (for your example) be 1+2*3+4*5, and then brackets get added as you move down the tree; a child of the root, for instance, could be (1+2)*3+4*5.

If you solve both of those problems, you'll have a recursive solution to your original question.

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.

### 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.