CodePark/ problems / Largest Number
START PRACTICINGPRACTICE
Coding problem · Data structures and algorithms › Foundations

Largest Number

easyabout 8 minutes in an interview

Write largestNumber(nums) that returns the largest number in the array nums.

  • If nums is empty, return null.
  • Numbers can be negative, and the same value can appear more than once.
  • Don't use Math.max or .sort. Look at the numbers yourself.
Input: nums = [3, 9, 2, 7] Output: 9
Input: nums = [-5, -2, -8] Output: -2All negative: the answer is the one closest to zero.
Input: nums = [] Output: null