We use cookies to ensure you have the best browsing experience on our website. Please read our cookie policy for more information about how we use cookies.
Make sure to consider all of the different parenthesis cases.
when m=1, there is only one case: a
when m=2, there is only one case: a b
when m=3, there are 2 cases: (a b) c ,
a (b c)
when m=4, there are 5 cases: ((a b) c) d ,
(a b) (c d) ,
(a (b c)) d ,
a ((b c) d) ,
a (b (c d))
when m=5, I found that there are 14 distinct cases.
At first, I only considered different numbers (m! cases) and operators (4^(m-1) cases), failing test cases #11, 12, 13, 16, 17, 18 and 22. Then I realized that different parantheses can make different results and then passed all the test cases.
Cookie support is required to access HackerRank
Seems like cookies are disabled on this browser, please enable them to open this website
Project Euler #93: Arithmetic expressions
You are viewing a single comment's thread. Return to all comments →
Make sure to consider all of the different parenthesis cases.
At first, I only considered different numbers (m! cases) and operators (4^(m-1) cases), failing test cases #11, 12, 13, 16, 17, 18 and 22. Then I realized that different parantheses can make different results and then passed all the test cases.