So today’s task was so easy I’m going to do another one because I solved it way too fast. It’s really not that hard if you know some built-in data structures.
Given an n-length Array of numbers between -1,000,000 to 1,000,000, find the number of distinct values in the array.
A = [1,4,2,6,8,2,3,6] returns 6
The idea is to eliminate duplicated numbers from the Array. For this, we use a Set and then get the size of this set which finishes the solution.
I actually spent more time writing this than thinking about the solution😁.