call(back)
Algorithms & Data StructureseasySign in to star problems

Drone Zone Sensor

A drone senses objects in zones and reports that data to an external system. Build a DroneZoneSensor class:

DroneZoneSensor(transport)     transport is anything with a send(payload) method
sense(zone, objectId, attrs)   record a detection; detecting the same object in
                               the zone again replaces the earlier record
retrieve(zone)                 every detection in the zone, each {id, ...attrs};
                               an unknown zone is empty
send(zone?)                    send every zone changed since the last send — or
                               just zone when given — as transport.send({zone, objects});
                               return the number of zones sent

A zone that hasn't changed since it was last sent isn't sent again.

Hints

Hint 1

A hashmap of hashmaps — zone → object id → latest detection — makes re-detections upserts instead of duplicates. That single choice answers half the follow-ups.

Hint 2

Take the transport as a constructor argument (anything with a send method) and track which zones changed since the last send — injected dependency and incremental sends are the two senior signals in a five-minute class.

Asked at