How do you find the largest and smallest number in an unsorted integer array?

twitter logo github logo ・1 min read

interview (3 Part Series)

1) How do you find the duplicate number on a given integer array? 2) How do you find the largest and smallest number in an unsorted integer array? 3) How do you find all pairs of an integer array whose sum is equal to a given number?

Python is very simple language to do these kind of operations. Thats why its using in Machine Learning processes

input = [10,20,30,11,10]

print(max(input))
print(min(input))

And, the output is

30
10


`

twitter logo DISCUSS (1)
markdown guide
 

I'm not a python guy, but wouldn't this scan the entire array twice? For a large array that would be wasteful. It's probably better to design a single loop and track the min and max values, right?

Classic DEV Post from Jun 23

What Advice Would You Give Your 20-year-old Self?

If you could go back in time, what advice would you give your 20-year-old self?

muTheTechie profile image
Loving #opensource #AWS #python
Join dev.to

Be a better developer. Free forever.