2782. Number of Unique Categories
You are given an integer
nand an objectcategoryHandlerof classCategoryHandler.There are
nelements, numbered from0ton - 1. Each element has a category, and your task is to find the number of unique categories.The class
CategoryHandlercontains the following function, which may help you:
boolean haveSameCategory(integer a, integer b): Returnstrueifaandbare in the same category andfalseotherwise. Also, if eitheraorbis not a valid number (i.e. it’s greater than or equal tonor less than0), it returnsfalse.Return the number of unique categories.
1 | /** |