- Trending Categories
- Data Structure
- Networking
- RDBMS
- Operating System
- Java
- iOS
- HTML
- CSS
- Android
- Python
- C Programming
- C++
- C#
- MongoDB
- MySQL
- Javascript
- PHP

- Selected Reading
- UPSC IAS Exams Notes
- Developer's Best Practices
- Questions and Answers
- Effective Resume Writing
- HR Interview Questions
- Computer Glossary
- Who is Who

# Program to check is there any permutation that is lexicographically bigger or not between two strings in Python

Suppose we have two strings s and t of the same size, we have to check whether there is some permutation of s, say s1, and permutation of t, say t1, such that: s1[i] ≤ t1[i] for all 0 ≤ i < n or t1[i] ≤ s1[i] for all 0 ≤ i < n.

So, if the input is like s = "vyx" t = "wzx", then the output will be True, as we can have s1 = "vxy" and t1 = "wxz".

To solve this, we will follow these steps −

- if s and t are empty, then
- return True

- s := sort the string s
- t := sort the string t
- Define a function util() . This will take s1, s2
- for i in range 0 to size of s1, do
- if s1[i] > t1[i], then
- return False

- if s1[i] > t1[i], then
- return True
- From the main method do the following −
- if util(s, t) is true, then
- return True

- swap s and t
- return util(s, t)

Let us see the following implementation to get better understanding −

## Example

class Solution: def solve(self, s, t): if not len(s) or not len(t): return True s = sorted(s) t = sorted(t) def util(s1, t1): for i in range(len(s1)): if s1[i] > t1[i]: return False return True if util(s, t): return True s, t = t, s return util(s, t) ob = Solution() s = "vyx" t = "wzx" print(ob.solve(s, t))

## Input

"vyx", "wzx"

## Output

True

- Related Questions & Answers
- Program to check there is any forward path in circular cyclic list or not in Python
- Program to check there is any common reachable node in a graph or not in Python
- Check if concatenation of two strings is balanced or not in Python
- Program to check same value and frequency element is there or not in Python
- Program to check a number is power of two or not in Python
- Java Program to Compare two strings lexicographically
- C Program to check if two strings are same or not
- Find n-th lexicographically permutation of a strings in Python
- Program to check two strings are 0 or 1 edit distance away or not in Python
- Is there any way to check if there is a null value in an object or array in JavaScript?
- Java Program to check whether two Strings are an anagram or not.
- Is there any Python object inspector?
- Program to check two strings can be equal by swapping characters or not in Python
- Check if edit distance between two strings is one in Python
- Program to check two rectangular overlaps or not in Python

Advertisements