Display Longest Name
Practice this coding question on Coding Gurukul.
Problem statement
A visitor centre prints the longest registered name on a sample badge to check whether the badge layout is wide enough. Registrations arrive in a fixed order. Your task Find the longest name in the list. If several names have the same maximum length, return the one that appears first. Important details Each name is a nonempty sequence of English letters without spaces. Count characters, including uppercase letters, without changing the spelling or capitalization. The comparison is by length rather than alphabetical order. Keep the earliest candidate when lengths tie. Print the name itself, not its length or its index. One scan of the registrations is sufficient. Worked example For Mira, Alexander, and Josephine, the last two names both have nine letters. Alexander appears first, so that is the output.
Input format
The first line contains n. The next n lines each contain one name.
Output format
Print the earliest name having maximum length.
Constraints
1 <= n <= 1000; each name contains 1 to 100 English letters.
Sample input
3 Mira Alexander Josephine
Sample output
Alexander
Sign in to run or submit a solution in C++, Java or Python.