This problem is based on checking call history. You have a list of call durations, and you want to know which call lasted the longest.
The answer is simply the largest number in the list. You do not need to sort the whole list. You only need to keep track of the biggest duration you have seen so far.
For example, if the durations are [4, 12, 7, 9], the answer is 12. That is the longest call in the list.
If the list is empty, return -1 because there is no call duration to report.
Example Input & Output
With one call, that duration is automatically the longest.
12 is the longest call duration in the list.
An empty call list has no valid duration to return.
Algorithm Flow

Solution Approach
A good way to solve this is to keep one variable for the current longest duration.
First, handle the empty-list case. If there are no calls, return -1.
If the list has values, store the first call duration in a variable like longest. That gives you a starting answer.
Then move through the remaining durations and compare each one with longest.
The update rule is:
Whenever you find a bigger duration, replace the old value.
After the loop ends, longest is the largest duration in the list, so that is the answer you print.
Best Answers
Solutions Coming Soon
Verified best solutions for this Challenge are still being analyzed and will be available soon.
Comments (0)
Join the Discussion
Share your thoughts, ask questions, or help others with this Challenge.
