Suppose we have a string s. We have to check whether the given string is isogram or not. The isogram is a string where the occurrence of each letter is exactly one.So, if the input is like s = "education", then the output will be True because all characters in "education" occurs exactly once.To solve this, we will follow these steps −char_list := a new listfor each char in word, doif char is non numeric, thenif char is in char_list, thenreturn Falseinsert char at the end of char_listreturn TrueLet us see the following implementation to get better understanding −Example Live Demodef ... Read More
Suppose we have a string s. We have to check whether the given string is colindrome or not. The colindrome is a concatenated string of 6 length palindromes.So, if the input is like s = "aabbaamnoonm", then the output will be True as this contains palindromes like "aabbaa" and "mnoonm", both are of length 6.To solve this, we will follow these steps −if size of s is not multiple of 6, thenreturn Falsefor i in range 0 to size of s - 1, increase by 6, doif s[from index i to i+5] is not palindrome, thenreturn Falsereturn TrueLet us see ... Read More
Suppose we have a binary string s and another value m, we have to check whether the string has m consecutive 1’s or m consecutive 0’s.So, if the input is like s = "1110111000111", m = 3, then the output will be True as there are three consecutive 0s and 1s.To solve this, we will follow these steps −str_size := size of scount_0 := 0, count_1 := 0for i in range 0 to str_size - 2, doif s[i] is same as '0', thencount_1 := 0count_0 := count_0 + 1otherwise, count_0 := 0count_1 := count_1 + 1if count_0 is same as ... Read More
Suppose we have a lowercase string s, we have to check whether we can convert s into a valid string by deleting at most 1 character. Here a valid string means a string str such that for all unique characters in str each character’s frequency is same.So, if the input is like s = "xyyzx", then the output will be True as we can delete z then string will be "xyyx" where occurrences of x and y are same.To solve this, we will follow these steps −size := 26occurrence := an array of size 26. This is storing frequencies of ... Read More
Suppose we have a string s we have to check whether the string is following the pattern a^nb^n or not. This is actually a string when n = 3, the string will be "aaabbb".So, if the input is like s = "aaaaabbbbb", then the output will be True as this follows a^5b^5.To solve this, we will follow these steps −size := size of sfor i in range 0 to size - 1, doif s[i] is not same as 'a', thencome out from loopif i * 2 is not same as size, thenreturn Falsefor j in range i to size - ... Read More
Suppose we have a string s. We have to check whether this string contains some even length palindrome or not.So, if the input is like s = "afternoon", then the output will be True as "afternoon" has even length palindrome "noon".To solve this, we will follow these steps:for i in range 0 to size of string - 1, doif string[i] is same as string[i + 1], thenreturn Truereturn FalseLet us see the following implementation to get better understanding −Example Live Demodef solve(string): for i in range (0, len(string)): if (string[i] == string[i + 1]): ... Read More
Suppose we have two strings s and t. We can delete t from s any number of times. And t appears only once at a time. We have to check whether s can become empty by removing t as many times as required.So, if the input is like s = "pipipinnn" t = "pin", then the output will be True as we can remove "pin" from "pipipinnn", then we will get "pipinn", again remove "pin" to get string "pin", then remove it to make it empty.To solve this, we will follow these steps −while size of s > 0, doposition ... Read More
Suppose we have two strings s and t, we have to find how many times the string s can be concatenated to generate t. If we cannot generate t using s, then return -1.So, if the input is like s = "tom" t = "tomtomtom", then the output will be 3 as we can concatenate "tom" 3 times to get "tomtomtom".To solve this, we will follow these steps −if size of t is not divisible by size of s, thenreturn -1cnt := quotient of (size of t / size of s)s := concatenate s cnt number of timesif s is ... Read More
Suppose we have two strings s and t. We have to check whether we can get s by rotating t two place at any direction left or right.So, if the input is like s = "kolkata" t = "takolka", then the output will be True as we can rotate "takolka" to the left side two times to get "kolkata".To solve this, we will follow these steps −if size of s is not same as size of t, thenreturn Falseright_rot := blank stringleft_rot := blank stringl := size of tleft_rot := left_rot concatenate t[from index l - 2 to end] concatenate ... Read More
Suppose we have two strings lowercase strings s and t. We have to check whether t can be generated from s using following constraints or not −Characters of t is there in s for example if there are two 'a' in t, then s should also have two 'a's.When any character in t is not in s, check whether the previous two characters (previous two ASCII values) are there in s or not. For example, if 'f' is in t but not in s, then 'd' and 'e' can be used from s to make 'f'.So, if the input is ... Read More