Get the expected number


  • 2
    W

    a. Input:

    i. Set of integers [A, B, C, ..., D], the size of the set will be from 2 to 5 integers. For example [5, 5, 5, 1]

    ii. Target number: one integer, for example 24

    b. Output: arithmetical expression, that can use four arithmetic operands '+', '-', '*', '/' , any number of nested parenthesis and uses each integer from the input set exactly once. The result of the expression should be equal to the target number. If no such expression exists, then output will be 'none'

    c. Samples of inputs and outputs:

    i. [1, 2, 3, 4], target = 3, output: (2 + 4) * 1 – 3 = 3

    ii. [3, 3, 2, 8], target = 2, output: (3 – 3) * 8 + 2 = 2

    iii. [2, 1, 7], target = 12, output: 2 * (7 – 1) = 12

    iv. [3, 5, 5, 3], target = 1, output: (5 - (5 – 3)) / 3 = 1


  • 1
    A

    The answer is given in c# in one of the website online. The website is codinghelmet.com. please refer to the website.


  • 0
    A
    This post is deleted!

Log in to reply
 

Looks like your connection to LeetCode Discuss was lost, please wait while we try to reconnect.