DEV Community

Muthu
Muthu

Posted on

2 2

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

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))
Enter fullscreen mode Exit fullscreen mode

And, the output is

30
10
Enter fullscreen mode Exit fullscreen mode


`

Top comments (1)

Collapse
 
jdforsythe profile image
Jeremy Forsythe

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?

A Workflow Copilot. Tailored to You.

Pieces.app image

Our desktop app, with its intelligent copilot, streamlines coding by generating snippets, extracting code from screenshots, and accelerating problem-solving.

Read the docs

👋 Kindness is contagious

Please leave a ❤️ or a friendly comment on this post if you found it helpful!

Okay