Given two strings (of lowercase letters), a pattern and a string. The task is to sort string according to the order defined by pattern and return the reverse of it. It may be assumed that pattern has all characters of the string and all characters in pattern appear only once.
Input : pat = "asbcklfdmegnot", str = "eksge" Output : str = "geeks" (after sorting, str becomes "skeeg" and return its reverse) Input : pat = "mgewqnasibkldjxruohypzcftv", str = "niocgd" Output : str = "coding"
The idea is to first maintain a dictionary according to the index provided in Pattern and then passing the lambda function(which uses utility of dictionary) into the sort function.
Below is the implementation of above idea.
Time Complexity: n*log(n) where n is the length of the string
- Python | Inverse Sorting String
- Python | All Permutations of a string in lexicographical order without using recursion
- Python | Check order of character in string using OrderedDict( )
- Python | Reverse Order Sort in String List
- Python | Check if given string can be formed by concatenating string elements of list
- String slicing in Python to check if a string can become empty by recursive deletion
- Python | Merge Tuple String List values to String
- Python - Remove front K characters from each string in String List
- Python | Delimited String List to String Matrix
- Python - Length of shortest string in string list
- Python | Check if string ends with any string in given list
- String slicing in Python to rotate a string
- Python | Check if a given string is binary string or not
- Python - Remove String from String List
- Python | Sort each String in String list
- Sort an array of string of dates in ascending order
- String Alignment in Python f-string
- String to Int and Int to String in Python
- Python User defined functions
- User-defined Exceptions in Python with Examples