Show problems as
Classic problem #1207EasyArrayHash Table

Unique Number of Occurrences

Real-world version: Distinct Tallies In A Core Log
Tracked in this browser only
Read Unique Number of Occurrences on LeetCode(opens in a new tab)

The 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.

Python
def all_tallies_differ(offsets: list[int]) -> bool:
Java
public boolean allTalliesDiffer(int[] offsets)