Dataford
Interview QuestionsInterview GuidesExperiencesMock InterviewsPricing
Get started
Largest Element in Unsorted Array
00:00
5 left

Largest Element in Unsorted Array

EasyPython

Problem

Find largest element in an unsorted array

Implement find_largest(nums) to return the largest integer in a non-empty array. Scan the array without sorting it.

Input: nums, a non-empty list of integers. Output: the largest integer.

Examples: find_largest([3, 1, 7, 2]) returns 7; find_largest([-5, -2, -9]) returns -2.

Constraints: 1 <= len(nums) <= 10^4; values range from -10^9 to 10^9.

Constraints

  • 1 <= len(nums) <= 10^4
  • -10^9 <= nums[i] <= 10^9
  • The input array is non-empty
  • Do not sort the array

Function Signature

def find_largest(nums):
Interviewer

Your question is Largest Element in Unsorted Array. Start with the requirements in the Question tab.

Run and submit as often as you like. When you're ready, talk me through your approach or go straight to the code.

You need to log in / sign up to run or submit.
CodePython 3
You need to log in / sign up to run or submit.Ln 2
Run your code to see test output here.