Company: Nk Securities_27oct
Difficulty: medium
Bridge Crossing Problem Problem Description There is a small one-way bridge that can carry a maximum weight of U units at a time. There is also a line of N cars waiting to cross the bridge. The weights of the cars are given as an array weight of N integers. The weight of the k -th car in the line is weight[k] (for K within the range [0, N-1] ). The car that will enter second weights weight[1] and so on. At most two cars can be on the bridge at the same time. To design, the first car will enter the bridge. The second car will enter the bridge as soon as the first car leaves the bridge, the fourth car will leave, and the third car will enter, and so on. Their cars leave the bridge in the same order they entered it. However, this may lead to a situation where cars exceed the bridge's weight limit. To prevent such a situation, some drivers have to turn back. When a driver turns back, all drivers behind them in line move one position closer to the bridge. The driver who turns back is remove