SRM 720, D2, 250-Pointer (DistinctGridEasy)
James S. Plank
Sat Sep 30 18:04:55 EDT 2017
Given a collection of n values, how do you determine how many of them are distinct?
Use a set: Insert each value into the set. Then the size of the set is the number
of distinct elements.
Armed with that knowledge, you should have two doubly-nested for loops. Here is the first:
- For every row of grid:
- Clear the set.
- Insert each element in the row into the set.
- Check the set's size. If it doesn't equal k return "Bad."
The second set of loops does the same thing, but with columns instead of rows.
If you complete both sets of loops, then the answer is "Good".