Signal Pings
Updated
Problem statement
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.
Function
getRequiredSweeps(ping: int[]) → int[]Examples
Example 1
ping = [1, 2, 4, 3]return = [2, 3, 3, 1]
More Fortinet interview questions
Similar questions at other companies
- Deployment Window SchedulerStripe · OAStripe interview questions
- Power Cell BankOptiver · OAOptiver interview questions
- Credit Accounts with Scheduled TransfersAirbnb · OAAirbnb interview questions
- Four-Level Banking System with Scheduled PaymentsZipRecruiter · OAZipRecruiter interview questions
- IPO Share AllocationTwo Sigma · OATwo Sigma interview questions
- Task Management SystemCoinbase · OACoinbase interview questions
- Four-Player Trick-Taking Card Game SimulationScale AI · OA · PHONE SCREENScale AI interview questions
- Task Management SystemAnthropic · OAAnthropic interview questions
- Progressive Parcel Tracking OperationsKlaviyo · OAKlaviyo interview questions
- Initial Public OfferingPoint72 · OAPoint72 interview questions