Originally published byDev.to
One way is to traverse the array and keep updating the min and max elements .
- initialize min = arr[0] max = arr[o]
traverse the array from index 1
For each element:
If element < min β update min
If element > max β update max
4.return max and min array
5.Time Complexity: O(n)
We traverse the array once
Space Complexity: O(1)
πΊπΈ
More news from United StatesUnited States
NORTH AMERICA
Related News
Jeff Bezos Seeking $100 Billion to Buy Manufacturing Companies, 'Transform' Them With AI
4h ago
Officer Leaks Location of French Aircraft Carrier With Strava Run
4h ago
Microsoft Says It Is Fixing Windows 11
4h ago
50% of Consumers Prefer Brands That Avoid GenAI Content
4h ago
White House Unveils National AI Policy Framework To Limit State Power
4h ago