Sort Number By Unit and Tenth Digits
Coding Problem Keys
Sort Number By Unit and Tenth Digits
Problem Statement
Given N positive integers, the program must sort the numbers based on their unit digits (Smaller to larger). If the unit digits are same, then consider tenth digit to sorts. Assume no two numbers will have both unit and tenth digits equal.
Input Format
The first line contains N.
The second line contains N integers separated by a space.
Output Format
The first line contains the sorted integers separated by a space.
Boundary Conditions
1 <= N <= 100
Example Input/Output 1
Input
9
12 223 10 4345 189 9 455 61 82
Output
10 61 12 82 223 4345 455 9 189
Note: Max Execution Time Limit: 5000 millisecs
Solution:
Programming Language: Python 3 Language
n=int(input()) l=input().split() k=sorted([i[::-1] for i in l]) print(*[i[::-1] for i in k])
# Published By PKJCODERSProgramming Language: Python 3 Language
l=input() l=sorted(list(map(int,input().split())),key=lambda i:(i/10)%10) l=sorted(l,key=lambda i:i%10) print(*l)
# Published By PKJCODERS(Note: Incase If the code doesn't Pass the output kindly comment us with your feedback to help us improvise.)
Comments