Find distinict elements in an array in $O(n)$ time
For the first task you can use a solution similar to yours.
Let the input array be $A[1, \dots n]$. Create an array $B$ indexed with the integers from $10$ to $10n$ where each entry is a boolean value initially set to false. Then, for each input element $A[i]$, set $B[A[i]]$ to true. At the end of the above loop, return the number of indices $y$ such that $B[y]$ is true. This runs in $O(n)$ worst-case time.
Notice that, depending on how the hashtable is implemented, a hashtable-based solution is not guaranteed to have a worst-case time complexity of $O(n)$. Usually the hash-tables provided by the common programming languages only provide you with expected constant time operations.
Also, if don't have any other information on the values the the input integers, you can't use linear-time sorting algorithms (since their complexity depends on the range of the input values).
Anyway, your solution already works for the general problem in $O(n)$ expected time.
I don't think the general problem can be solved in $O(n)$ worst-case time. According to Wikipedia, there is a lower bound of $\Omega(n \log n)$ on the algebraic decision tree model, and randomness doesn't help.