Algorithm · ByteDance · Hard
A bug on a number line starts at position 0 and wants to reach position x. On each move it can either: jump forward by a positions, or jump backward by b positions. The bug must follow these rules: It cannot land on a negative position. It cannot land on any position in the forbidden list. It cannot make two consecutive backward jumps. Return the minimum number of jumps needed to reach x. If it is impossible, return -1. Function Signature Parameters forbidden: list of…
Checking your access…