Given two strings s1 and s2, write a function to return true if s2 contains the permutation of s1. In other words, one of the first string’s permutations is the substring of the second string.
Input: s1 = "ab" s2 = "eidbaooo"
Output:True
Explanation: s2 contains one permutation of s1 ("ba").
Input: s1= "ab" s2 = "eidboaoo"
Output: False
from itertools import permutations s1=input('Enter string s1 : ') s2=input('Enter string s2 : ') Slist=list(s1) permi=permutations(Slist) temp=[] for i in list(permi): temp.append(''.join(i)) flag=0 for i in temp: if i in s2: flag=1 break print(False) if flag==0 else print(True)
Input_1:
Enter string s1 : tweet
Enter string s2 : sweet
Output:
False
Input_2:
Enter string s1 : weed
Enter string s2 : dewe
Output:
True
Input_3:
Enter string s1 : fcuk
Enter string s2 : fuckthecode
Output:
True
Input_4:
Enter string s1 : ab
Enter string s2 : eidbaooo
Output:
True
Input_5:
Enter string s1 : ab
Enter string s2 : eidboaoo
Output:
False
Illustration of the Output
More Q
- Find the majority element appearing more than n/2 times
- Return an array of the squares of each number.
- Highest factor in addition.
- Find the empty packets(0) of chocolate and push it to the end of the conveyor belt(array).
- Every element in array appears twice.Find that single one.
- Find the duplicate letters in string. Same to do in dictionary way.
- Find minimum number of edits (operations) required to convert ‘str1’ into ‘str2’.
- Return the maximum number you can get by changing at most one digit.
- Sed Commands – Ranges of lines.
- Find the kth smallest element in the given 2D array.
- Find all elements that appear more than [n/3] times.
- Write a function to return true if s2 contains the permutation of s1.
- Sort the array into a wave like array.
- Re-order array, such that
nums[0] < nums[1] > nums[2] < nums[3]...
. - Given the coordinates, return true if the four points construct a square.
- Minimum Distance Between Words of a String.
- Return the shortest distance between these two words.
- Write a program to find the n-th ugly number.
- Check if array could become Non – Decreasing array.
- Find the minimum area of a rectangle that can be formed from given points.