+ 1

What I Missed in this code coach, 4th test case is not passed. Please help me!!

I have written a code for mathematics code coach in Java. But 4th case is not passed. Please help me out!! https://code.sololearn.com/ckv1zvw0Ubj5/?ref=app

21st Jan 2023, 2:46 PM
Srikanth
Srikanth - avatar
3 Answers
+ 2
See this case : (1+5-4+10+1) is evaluating as (1,5,4,10,1) => (6,4,10,1) now when you search for next + then pos=1 and you are adding 4+10 instead -4+10 So list values becomes (6, 14,1) => (6, 15) , now last 6-15= -9 but the correct answer is 13 +, - have equal precedence. You can go in sequel here...
21st Jan 2023, 6:11 PM
Jayakrishna 🇮🇳
+ 2
Your code cannot deal with expressions with indivisible subset of number, partly because it always deals with division first. Eg, it will fail to find the last expression equals the first input if you add a "3*" before 5 and "/3" after 5 in the last expression of your sample input. Even though the result should be the same if calculated by human. One way to solve it is to change the number types to Double.
21st Jan 2023, 5:43 PM
Lochard
Lochard - avatar
+ 2
Jayakrishna 🇮🇳 Oh, right. + always goes before - also causes a problem. And it is more likely to be the problem since the code coach is meant for Integers.
21st Jan 2023, 6:42 PM
Lochard
Lochard - avatar