Time Complexity:
The above approach has a time complexity of O(n)
, where n
represents the number of array elements. We only need to traverse the complete array once to identify the unique element. Additionally, the space complexity of the preceding method is O(1)
, as no additional space is required to eliminate duplicates from the sorted array.
Now its time to try and play around with the final solution!