Skip to content

Commit 2f04136

Browse files
committed
Display longest name
1 parent 63eabfa commit 2f04136

File tree

1 file changed

+40
-0
lines changed

1 file changed

+40
-0
lines changed
Lines changed: 40 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,40 @@
1+
"""
2+
Problem Link: https://practice.geeksforgeeks.org/problems/display-longest-name/0
3+
4+
Given a list of names, display the longest name.
5+
6+
Input:
7+
First line of input contains an integer T, the number of test cases. For each test case, there will be two lines.
8+
First line contains integer N i.e. total number of names, and second line contains N space seperated names of different length.
9+
10+
Output:
11+
Longest name in the list of names.
12+
13+
Constraints:
14+
1 <= T <= 10
15+
1 <= N <= 10
16+
1 <= |length of name| <= 1000
17+
18+
Example:
19+
Input:
20+
1
21+
5
22+
Geek
23+
Geeks
24+
Geeksfor
25+
GeeksforGeek
26+
GeeksforGeeks
27+
28+
Output:
29+
GeeksforGeeks
30+
"""
31+
for _ in range(int(input())):
32+
n = int(input())
33+
longest_name = ""
34+
name_length = 0
35+
for i in range(n):
36+
s = input()
37+
if len(s) > name_length:
38+
longest_name = s
39+
name_length = len(s)
40+
print(longest_name)

0 commit comments

Comments
 (0)