Signal Pings

You have an array of n binary signals, where each signal initially has a value of 0. There are n different pings made to these signals, changing their value from 0 to 1. The i ping affects the signal at index ping[i].

After each ping, the processor sorts the array by performing sweeps from left to right, swapping adjacent elements where signal[i] = 1 and signal[i + 1] = 0. The processor stops when no swaps are made in a sweep.

Determine the number of sweeps required after each ping to sort the array.

Note: Each signal is only pinged once.

**Endless thanks to the friend who so generously shared the problem source! **

Example

Unlock to view complete problem details

and practice with sample input/output

Was this article helpful?

View Test Cases & Run Code requires membership

Input Variables
Execution Result: