Counting the number of duplicates in a list

What is the quickest way to count the maximum number of duplicates in a list? For example, the maximum number of duplicates in {1,1,1,3} is 3, in {1,1,2,2} is 2 and in {1,1,1,2,2,2,3,3} is 3. I've unsuccessfully tried combinations of Commonest, Count and CountDistinct. Other questions have dealt with identifying or deleting duplicates rather than counting them.

• Look up Tally. For example, MaximalBy[Tally[lst], Last]. – Henrik Schumacher Jun 1 '19 at 12:03

lst = {1, 1, 1, 2, 2, 2, 3, 3};

ClearAll[f]
f = Max[Counts @ #] /. 1 -> 0 &;

f @ lst


3

f @ {1,2,3,4}


0

• The problem is that e.g. {1,2,3} returns 1, but it contains no duplicates (defined as two or more ocurrences). – spaced Jun 1 '19 at 12:33
• @spaced, good catch. Updated to get 0 when there are no duplicates. – kglr Jun 1 '19 at 12:43