Sort String Values – First and Last

The program must accept N string values and sort them. Then the program must print the first and the last string values.

Input :

5

lion tiger elephant monkey leopard

Output :

elephant

tiger

Explanation:
Here N = 5.
After sorting the 5 string values, the string values become elephant leopard lion monkey tiger
Here, the first and the last string values are elephant and tiger.
Hence the output is
elephant
tiger

Here are the various methods and logic.

Python :

IMG 20200419 WA0002
#Python code by Agent Hulk
IMG 20200419 WA0000
#Python code by Agent Stark
Capture 3
#Python code by Agent Parker
Capture 5
#Python code by Agent Marvel
Capture 6
#Python code by Agent Cherry

C :

IMG 20200419 WA0001
#C code by Agent falcon

Java :

IMG 20200419 WA0004
#Java code by Agent Steve
Previous Article

Integer - Count of Pairs

Next Article

Sum of Two Integers Equal to K

Write a Comment

Leave a Comment

Your email address will not be published. Required fields are marked *