FastPrepOrdered Acknowledgement API

Ordered Acknowledgement API

Bloomberg LP logoBloomberg LP● MediumNEW GRADONSITE INTERVIEW
Learn

Problem statement

Positive message IDs arrive out of order in acknowledgements. After each arrival, return the largest ID x such that every ID from 1 through x has arrived. Return -1 while ID 1 is still missing.

Duplicate acknowledgements do not change state.

Function

latestAfterAcknowledgements(acknowledgements: int[]) → int[]

Examples

Example 1

acknowledgements = [2,1,5,4,3]return = [-1,2,2,2,5]

The contiguous prefix advances only when every gap is filled.

Constraints

  • At most 2 * 10^5 acknowledgements.
  • IDs are positive signed 32-bit integers.

More Bloomberg LP problems

See Bloomberg LP hiring insights
public int[] latestAfterAcknowledgements(int[] acknowledgements) {
  // Write your code here.
}
acknowledgements[2,1,5,4,3]
expected[-1,2,2,2,5]
Checking account…