given a expresion 2*3+5-3......
Microsoft Interview Questions and Answers
(Continued from previous question...)
33. given a expresion 2*3+5-3......
Question:
given a expresion
2*3+5-3 it consisitof 3 opertors(+,-,*),but they can occur more than time.
we have to maximise the vlaue of expression by adding parathesis
like 2*3+5-3=8 no paranthesis
2*(3+5)-3=13
2*(3+5-3)=10
and so on maximise it with differnt possible parathesis
maybe an answer1:
a suggest using recursion and maintaining a set bit with each value of dp.
set bit would be initially 0 for all
then would be set to 1 for dp[i,i]
now if set bit is 0 then dp[] has to be computed and bit should be set to 1 otherwise it can be directly picked up from the table dp
maybe an answer2:
V(a, op, b)
if(op == '+')
return(a+b)
if(op == '-')
return(a-b)
if(op == '*')
return(a*b)
if(op == '/')
return(a/b)
MVE(i, j)
return max{V(MVE(i, j-2), a[j-1], a[j]), V(MVE(i+2, j), a[i+1], a[i])}
if(i == j)
return a[i]
(Continued on next question...)
Other Interview Questions
|