PPractick

DSA interview question

Largest Element in an Array

Easy · Algorithms · Topics: array, linear search

The problem

A weather station uploads the day's temperature readings as an array, and the dashboard shows the maximum temperature. It's the simplest array problem there is, which is exactly why it appears in first rounds: the interviewer wants to see a single clean pass, a correct starting value (a real element, not 0, since temperatures can be negative), and the judgement not to sort the whole array just to read one value.

Example: [1, 8, 7, 56, 90] → 90.

Function signature

int largestElement(const vector<int>& a);  // a is non-empty

Test cases

Input aOutputExplanation
[1, 8, 7, 56, 90]90
[5, 5, 5]5All equal
[-3, -1, -7]-1Starting from 0 would wrongly return 0
[10]10Single element
[2147483647, -5]2147483647INT_MAX is handled

(Confirm: the array has at least one element; values can be negative.)

How interviewers phrase it

Clarifying questions to ask

  1. Can the array be empty? What should be returned then?
  2. Can values be negative?
  3. Should I return the value or its index?

Follow-ups to expect

  1. "Why not sort and take the last element?"
  2. "What should max start at?"
  3. "Can you find both max and min in fewer than 2n comparisons?"
  4. "Is there a library function?"
  5. "Complexity?"

Practise questions like this with a real engineer

On Practick another engineer interviews you live for 60 minutes on a question from this bank. They have the full interviewer guide beside the call: the expected answer to every follow-up, hints to give if you stall, and a scoring rubric. You get the model solution once the session settles. It is free: interview someone for an hour and you have earned your own.

Book a free mock interview

Related questions

All 474 dsa interview questions

DSA mock interviews · System design interview questions · Free mock interview practice · Browse interviewers · Sign in