Company: ARCESIUM

Difficulty: easy

Problem Statement

A distributed gateway receives payloads that were sent in a fixed order, but the network may deliver them out of order. Every payload carries a sequenceNumber , and payloads must be released to the downstream consumer in increasing sequence order starting from sequence number 1 . Whenever a payload arrives, the gateway must immediately release the longest run of contiguous payloads starting at the next expected sequence number. A payload that arrives out of order is buffered until every preceding payload has been received. Each payload is released exactly once . If an arrival carries a sequence number that has already been released, or one that is already sitting in the buffer, the arrival is ignored completely (nothing is released for it and the stored payload is not overwritten). You are given the arrivals in the order they occur. For every arrival, report what the gateway releases at that moment. Input Format The first line contains an integer q — the number of arrivals. Each

More ARCESIUM OA questionsInterview experiences