Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • Home
  • SEARCH
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 8844529
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 14, 20262026-06-14T11:30:37+00:00 2026-06-14T11:30:37+00:00

You are given three things 1) An array of ‘n’ positive and negative integers.

  • 0

You are given three things

1) An array of ‘n’ positive and negative integers.
2) A number ‘x’.
3) Operators : ‘+’, ‘-‘, ‘%’, ‘/’

Form an expression with the array such that when you evaluate it, the result becomes ‘x’.

For example, consider the array [5,3,-1,6,2,3] and x=2, one possible solution would be

5 / 3 + (-1) + 6 / 2 – 1

Assume the result of 5 / 3 is 1(Always the integer division).

I have one more complex variant of this.

In the complex variant of this problem, assume that BODMASS rule don’t apply. So, at any point of time you traversed through elements ‘m’ and you have the intermediate result ‘y’. You can apply any of the operators to the ‘y’ and a[m + 1].

For example, in the variant 1,

5 + 3 – 2 / 2 = 7 ( 2 / 2 evaluated first, so 5 + 3 – 1)

in the variant 2,

5 + 3 – 2 / 2 = 3 (5 + 3 = 8. The array reduced to 8 – 2 / 2. Now, 8 -2 = 6. And array reduced to 6 / 2 which evaluate to 3).

Algo/Math/DS experts?

Is this a NP hard?

  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-06-14T11:30:39+00:00Added an answer on June 14, 2026 at 11:30 am

    There are 4 operators, so you have 4^(n-1) possible values for a set of n terms. You can construct a graph of the search space where each path represents a set of operator values and the end point is the result of the calculation.

    Of all those end points, only those which give the correct answer will end at the correct end point.

    Note, however, that if you start with the end point, you can traverse backward; only if you have a valid set of operators will you end on the first value.

    So traverse it from both ends, and the two calculations will meet in the middle. This is a much smaller space, of 4^(n/2) = 2^n from each direction. To match the two sets of answers you will need to sort the lists you get in the middle, although you may prefer to do this at every step to permit you to prevent duplicate paths being followed. At this point it looks much like a maze traversal.

    One known NP-complete problem is that of Boolean satisfiability, which is “the problem of determining if the variables of a given Boolean formula can be assigned in such a way as to make the formula evaluate to TRUE”. I suspect that since the search space is demonstrably larger than that of a the boolean satisfiability problem, and that since a solution would also determine that a formula was satisfiable (and is thus at least as hard as solving the satisfiability), then the problem should be NP-complete.

    In the maze sense, partial solutions whose values diverge from zero would be less likely to be the correct solution, and given an initial sweep of the parameters it should be clear what limits there are to size (i.e. all multiplies), which is not the case in the boolean problem.

    Edit: To clarify the tree I mentioned at the beginning. Suppose our list is

     1 ? 2 ? 5 = X
    

    Then the graph is something like this:

     r1 -->  r2  ---> r3 (X)
    
     1  +2    3  +5    8
                 -5   -2
                 *5   15
                 /5    0
    
        -2   -1  +5    4
                 -5   -6
                 *5   -5
                 /5    0
    
        *2    2  +5    7
                 -5   -3
                 *5   10
                 /5    0
    
        /2    0  +5    5
                 -5   -5
                 *5    0
                 /5    0
    

    As you can see, if X is -5, then it could be 1 -2 *5 or 1 /2 -5. Working backwards, from -5:

    -5 +5    0
       -5  -10
       *5  -25
       /5   -1
    

    So if we had stepped from each end, we’d be at the middle column and the only common values would be -1 and 0, yielding the two paths with 8 calculations rather than the 16 going in one direction only.

    A point that this raises, which I had missed, is that the integer division is not a 1:1 mapping, so stepping backward is ambiguous; -4/5 -> 0, -3/5 -> 0 etc up to 4/5 -> 0. 0 is the worst case because it is approached from either side of 0, but even 20/10 to 29/10 all map to the same value, 2. This is quite a hurdle; it raises the number of possible nodes when stepping backwards by the size of the number being divided, so for a 5, there are 3+5 = 8 possible states rather than 4.

    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I have an optimization problem as follows. Given an array of positive integers, e.g.
I'm simplifying a larger complex problem with the following... Given three arrays of integers,
Given the following array: var things = ['sandwich', 17, 'fake@sample.com', 3, 'horse', 'octothorpe', 'anotheremail@sample.com',
I know that there is an algorithm that permits, given a combination of number
I'm given three binary random variables: X, Y, and Z. I'm also given the
Given the following strings 7;#User One 7;#User Two;#9;#User Two 7;#User Two;#9;#User Two;#123;#User Three I
Given that: There seems to be no easy way to get a list of
Original Problem: I have 3 boxes each containing 200 coins, given that there is
I've created two UserControls, a ValidationManager and a ValidationOutput. On a given form there
Given the following data structure var things = [{ name: thing1, sex: male}, {

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.