start, and you want it to show goal. You have a set of step values steps. While the current number x is between 0 and 1000 inclusive, one move picks any step s from steps and replaces x with one of:
- x + s;
- x - s;
- x XOR s (bitwise exclusive OR).
Steps can be reused any number of times in any order. A move that takes the number outside 0..1000 is allowed, but the counter then freezes and no further moves are possible.
Return the fewest moves that turn start into goal, or -1 if it cannot be done.steps=[3, 6], start=1, goal=10 → 2
1 + 3 = 4, then 4 + 6 = 10. No single move reaches 10.
steps=[4], start=0, goal=2 → -1
Every move with step 4 keeps the number a multiple of 4, so 2 is out of reach.
steps=[400], start=300, goal=1100 → 2
300 → 700 → 1100. The value 1100 is outside 0..1000, but it is the goal, so that is fine.
steps=[3, 6], start=1, goal=10
2
Run checks the first 3 tests in your browser. Submit checks all 133 tests on the server, hidden ones included.