Second Solution Added

Less optimal solution added. The one that runs in O(N*log(N)).