Problem · Queue

Camera Log API Sequence

Learn this problem
MediumVerkada logoVerkadaFULLTIMEPHONE SCREEN

Problem statement

A camera service maintains two independent FIFO queues for every camera: a command queue and a log queue. Process a finite sequence of API operations and return one response for each operation in input order.

The initial command and log rows correspond by index to cameraIds. Apply each operation to the camera named by the parallel operationCameraIds entry:

  • POLL_COMMAND: remove and return the oldest command for that camera, or "NONE" when its command queue is empty.
  • GET_LOG: remove and return the oldest log for that camera, or "NONE" when its log queue is empty.
  • SEND_LOG: append the parallel operationPayloads value to that camera's log queue and return "ACK".

Command and log queues are isolated from one another and from every other camera. The payload entry is ignored for POLL_COMMAND and GET_LOG.

Function

cameraLogApiSequence(cameraIds: String[], initialCommands: String[][], initialLogs: String[][], operationTypes: String[], operationCameraIds: String[], operationPayloads: String[]) → String[]

Examples

Example 1

cameraIds = ["cam-a","cam-b"]initialCommands = [["reboot","upgrade"],[]]initialLogs = [["boot-ok"],["motion"]]operationTypes = ["POLL_COMMAND","POLL_COMMAND","GET_LOG","SEND_LOG","GET_LOG","POLL_COMMAND","GET_LOG"]operationCameraIds = ["cam-a","cam-a","cam-b","cam-b","cam-b","cam-a","cam-a"]operationPayloads = ["","","","uploaded","","",""]return = ["reboot","upgrade","motion","ACK","uploaded","NONE","boot-ok"]

The first two command polls consume cam-a's commands in FIFO order. The first log read consumes cam-b's initial log; the send then appends uploaded, which the next read returns. The third command poll is empty, while cam-a's log queue is unaffected.

Example 2

cameraIds = ["x","y"]initialCommands = [[],["y-cmd"]]initialLogs = [[],[]]operationTypes = ["SEND_LOG","GET_LOG","GET_LOG","POLL_COMMAND","POLL_COMMAND"]operationCameraIds = ["x","y","x","x","y"]operationPayloads = ["x-log","","","",""]return = ["ACK","NONE","x-log","NONE","y-cmd"]

Sending a log to x does not change y. Reading y's empty log queue returns NONE, and the subsequent read from x returns the newly submitted log.

Constraints

  • cameraIds.length == initialCommands.length == initialLogs.length.
  • operationTypes.length == operationCameraIds.length == operationPayloads.length.
  • Camera IDs are unique non-empty strings, and every operation camera ID appears in cameraIds.
  • Every operation type is POLL_COMMAND, GET_LOG, or SEND_LOG.
  • Queued values and SEND_LOG payloads are non-empty strings other than the reserved value NONE.

More Verkada problems

drafts saved locally
public String[] cameraLogApiSequence(String[] cameraIds, String[][] initialCommands, String[][] initialLogs, String[] operationTypes, String[] operationCameraIds, String[] operationPayloads) {
    // write your code here
}
cameraIds["cam-a","cam-b"]
initialCommands[["reboot","upgrade"],[]]
initialLogs[["boot-ok"],["motion"]]
operationTypes["POLL_COMMAND","POLL_COMMAND","GET_LOG","SEND_LOG","GET_LOG","POLL_COMMAND","GET_LOG"]
operationCameraIds["cam-a","cam-a","cam-b","cam-b","cam-b","cam-a","cam-a"]
operationPayloads["","","","uploaded","","",""]
expected["reboot", "upgrade", "motion", "ACK", "uploaded", "NONE", "boot-ok"]
checking account