1 min to read
ginortS - HackerRank Solution Python
ginortS is a medium-level problem of python on Hackerrank that requires knowledge of sort
in python. In this post, you will learn how to solve Hackerrank’s ginortS problem and its solution in Python.
Problem Statement and Explanation
Sort the string using the ginortS
logic based on the following rules:
- 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
- Single line containing a string
S
. -
ginortS HackerRank Solution python
Explanation of Solution
The code you provided is a Python function called ginortS(), which takes a string as input and returns a new string with the characters sorted in the following order:
- Lowercase letters
- Uppercase letters
- Odd numbers
- Even numbers
The function works by first creating four empty strings: small
, capital
, odd
, and even
. It then iterates over the input string and adds each character to the appropriate string depending on its type.
Once the function has finished iterating over the input string, it sorts each of the four strings and then concatenates them together to form the output string.