Quiet Sensor Codes
Preview mode. Log in to edit, run, submit, and save progress.
Quiet Sensor Codes
A warehouse audit records integer sensor codes. A code is considered quiet only if it appears exactly once in the full audit and neither of its neighboring values appears anywhere in the audit. For a code x, the neighboring values are x - 1 and x + 1. The output should contain every quiet code in increasing order. If no code satisfies the quiet rule, the result should contain no elements. Input Format: You are given an integer array codes. Output Format: Return an array containing all quiet codes in sorted increasing order.
Examples
codes = [10, 6, 5, 8]
8 10
Explanation: Code(s) [8, 10] appear once and have no neighboring value present. They are returned in sorted order.
Approach hint
The frequency table can also answer whether a neighboring value exists.
Common mistake
Skipping assumptions, edge cases, or trade-offs can make an otherwise good answer feel incomplete.