AILearn
Problems

2. Find Maximum Element

Easy

Write a function find_max(arr) that finds the maximum element in an array without using built-in max() or np.max().

Example:

Input: arr = [3, 7, 2, 9, 1, 5]

Output: 9

Constraints:

  • Array length: 1 <= len(arr) <= 1000
  • Array values: -10000 <= arr[i] <= 10000
  • Test Cases

    Test Case 1
    Input: [3, 7, 2, 9, 1, 5]
    Expected: 9
    Test Case 2
    Input: [1, 2, 3, 4, 5]
    Expected: 5
    Test Case 3
    Input: [-5, -2, -10, -1]
    Expected: -1
    + 2 hidden test cases
    Python 3
    Loading editor...
    Console Output
    Click "Run" to test your code or "Submit" to submit your solution.