Given an array of length N. It can contain values from ranging from 1 to N^2 (N squared) both inclusive, values are integral. Is it possible to sort this array in O(N) time?
Yes, you can, using radix sort with N buckets and two passes. Basically, you treat the numbers as having 2 digits in base N.