1. Tallest Building

EasyArray
RPby Rohit Parihar1 submission

A surveyor walks along a street and writes down the height of every building she passes, in metres. Given these heights in the order she recorded them, return the height of the tallest building.

Write a method findMax that takes the array nums of heights and returns the largest value in it.

The array always contains at least one building.

Example 1

Input:
nums = [3,9,4]
Output:
9
Explanation:

The tallest building is 9 metres.

Example 2

Input:
nums = [-7,-2,-15]
Output:
-2
Explanation:

Heights can be negative (for example basements below street level); the largest here is -2.

Constraints

1 ≤ nums.length ≤ 104

-109 ≤ nums[i] ≤ 109

How this problem is judged

Answers
Your answer must match exactly. Numbers compare by value, so 2 and 2.0 are equal.

Expected complexity

Time
O(n)
Space
O(1)

What the author was aiming for. Your own solution is not measured against it.

Asked in an interview

Were you asked this in an interview? Say where, anonymously.

Code
Loading the editor…