I created two variables min and max, comparing them with the elements as I traversed the array. It is a single traversal so the time complexity is O(n).
The space complexity is also O(1) because the size of the array remains contants and only two variables are created.