$A$ and $B$ are two arrays with $n$ elements each in the range $1$ to $n^2$.1.How to check if the elements of $A$ are distinct in $O(n)$ time and $O(n)$ space2.How to check if $A$ and $B$ have a common element in $O(n)$ time and $O(n)$ space.Both the algorithms shouldn't use Hash sets or any other advanced data structure. A and B are just simple Arrays.
Algorithm with $O(n)$ time and $O(n)$ space to compare two arrays
algorithms;arrays