The question was based on DSA – Arrays.
You are given an array of integers, and your task is to find the largest element present in the array.
During the interview, the interviewer first asked me to explain my approach before writing the code. After explaining the approach, I was asked to implement the solution.
Start with the first element as the current maximum. Then traverse the array and compare each element with the current maximum.
If the current element is greater than the maximum, update the maximum.
After traversing the complete array, the maximum value is the answer.
Input:
[10, 5, 25, 8, 15]
Output:
25
Interview tip: Don't immediately start coding. First explain the logic clearly, mention the time and space complexity, and then implement it.