Unique Number of Occurrences
Real-world version: Distinct Tallies In A Core LogThe statement here is our own: the same inputs, outputs and technique.
A drilling crew tags every core sample it lifts with the signed offset of the level it came from, in decimetres above the survey datum. Levels below the datum carry a negative offset, and offsets lists one tag per sample in the order the samples were lifted.
The crew calls a log well spread when no two different offsets were sampled the same number of times. An offset that appears once and another that also appears once spoils that, while an offset sampled once alongside one sampled four times does not.
Return true if the log is well spread and false otherwise. Note that -40 and 40 are different offsets.
Examples
Example 1
- Input
- offsets = [-40, 7, -40, 7, 65]
- Output
- false
Offset -40 was sampled twice, offset 7 was sampled twice as well, so two different offsets share a tally.
Example 2
- Input
- offsets = [-5, -5, -5, 62, 91, 62, 14]
- Output
- false
The tallies are three samples at -5, two at 62 and one each at 91 and 14, and the two singles clash.
Example 3
- Input
- offsets = [-1000, -1000, -1000, -1000]
- Output
- true
Only one offset appears in the log, so there is no second tally for it to clash with.
Constraints
- 1 <= offsets.length <= 1000
- -1000 <= offsets[i] <= 1000
The signature
The editor starts with this. It matches the parent problem's shape, so a solution that works here works on a standard judge unchanged.
def all_tallies_differ(offsets: list[int]) -> bool:public boolean allTalliesDiffer(int[] offsets)Checking your plan…
How this problem was checked
- Passed: Reference solution run against 12 test cases: 12 passed
- Passed: 3 worked examples confirmed by running the code
- Passed: 0 eight-word sequences shared with the parent problem's text
- Passed: Agrees with an independent brute-force solution on random inputs
- Passed: Test set shown to catch deliberately broken solutions
- Passed: Reviewed by a separate quality pass
- Passed: Function arity matches the parent problem's