2782. Number of Unique Categories
You are given an integer
n
and an objectcategoryHandler
of classCategoryHandler
.There are
n
elements, numbered from0
ton - 1
. Each element has a category, and your task is to find the number of unique categories.The class
CategoryHandler
contains the following function, which may help you:
boolean haveSameCategory(integer a, integer b)
: Returnstrue
ifa
andb
are in the same category andfalse
otherwise. Also, if eithera
orb
is not a valid number (i.e. it’s greater than or equal ton
or less than0
), it returnsfalse
.Return the number of unique categories.
1 | /** |