Skip to content
the poor coder

Hackerrank - ginortS Solution

Poor Man
Published
Updated
Reading time
1 min read

You are given a string S.
S contains alphanumeric characters only.

Your task is to sort the string  in the following manner:

  • All sorted lowercase letters are ahead of uppercase letters.
  • All sorted uppercase letters are ahead of digits.
  • All sorted odd digits are ahead of sorted even digits.

Input Format

A single line of input contains the string .

Constraints

Output Format

Output the sorted string .

Sample Input

Text
Sorting1234

Sample Output

Text
ginortS1324

Solution in Python#

Using regex

Python
import re
S= input()
series="[a-z]","[A-Z]","[13579]","[02468]"
print("".join(map(lambda x: "".join(sorted(re.findall(x, S))),series)))

Without regex

Python
l,u,o,e=[],[],[],[]
for i in sorted(input()):
    if i.isalpha():
        x = u if i.isupper() else l
    else:
        x = o if int(i)%2 else e
    x.append(i)
print("".join(l+u+o+e))

Keep going

ESC