Python Basics簡単

Find Largest element in an array

Detailed guide and Python implementation for the 'Find Largest element in an array' problem.

問題提起

簡単

Write a function find_largest(arr) that takes a list of integers arr and returns the largest element. Iterate through the array and track the maximum value seen so far.

制約
  • 1 <= len(arr) <= 10^5
  • -10^9 <= arr[i] <= 10^9

Example 1
Input
arr = [3, 7, 2, 8, 1]
Output
8
Explanation

Comparing all elements: 3, 7, 2, 8, 1. The maximum is 8.

Example 2
Input
arr = [-5, -2, -8, -1]
Output
-1
Explanation

Among negative numbers, -1 is the largest.

Example 3
Input
arr = [100]
Output
100
Explanation

Only one element, so it is the largest.

Need a Hint?
Consider using Arrays-specific data structures like sets or heaps.
Edge Cases to Watch
  • Empty input structures
  • Single element inputs
  • Large numerical bounds

解決する準備はできましたか?

Open the problem in PyRun's browser-based Python editor. Your code runs fully offline — no server required.

エディタで開く
Found this breakdown helpful?

PyRun is built and maintained by an independent solo developer. If this helped your interview prep, consider buying a coffee!

Buy me a coffee

推奨される Python リソース

関連するインタラクティブなチュートリアル、チートシート、コード比較で知識を深めてください。