Please read the new rule regarding the restriction on the use of AI tools. ×

013's blog

By 013, history, 8 years ago, In English

Given an expression E and another integer 'k' , you are required to find out whether it is possible to parenthesize E such that it evaluates to 'k'. If the answer is YES, print the corresponding parenthesized expression. Assume the max and min value of E will be within -N and +N where N ≤ 10000 and the value of  - N ≤ k ≤ N.

Sample Input and output:

Input: E = 2 + 3 * ( - 1) + 4 + ( - 7), k = 8

Output: Yes. E = (2 + 3) * (( - 1) + 4) + ( - 7) = 8

Can this problem be solved in O(n2N)? If yes then how? If no then what is the best complexity to solve it?

  • Vote: I like it
  • +15
  • Vote: I do not like it