Check If a String is the Typed Name in Python

Arnab Chakraborty
Updated on 29-Dec-2020 13:27:45

531 Views

Suppose we have two lowercase strings s and t. Sometimes, when we type a vowel, the key might get long pressed, and the vowel will be repeated 1 or more times. We have to check whether it is possible that t is typed that indicates s or not.So, if the input is like s = "mine" t = "miiine", then the output will be True as vowel 'i' is repeated three times, other letters are fine.To solve this, we will follow these steps −s_len := size of st_len := size of tj := 0for i in range 0 to s_len ... Read More

Check If a String Is Suffix of Another in Python

Arnab Chakraborty
Updated on 29-Dec-2020 13:26:12

447 Views

Suppose we have two strings s and t. We have to check whether s is suffix of t or not.So, if the input is like s = "ate" t = "unfortunate", then the output will be True.To solve this, we will follow these steps −s_len := size of st_len := size of tif s_len > t_len, thenreturn Falsefor i in range 0 to s_len, doif s[s_len - i - 1] is not same as t[t_len - i - 1], thenreturn Falsereturn TrueLet us see the following implementation to get better understanding −Example Live Demodef solve(s, t):    s_len = len(s)   ... Read More

Check If a String Is Palindrome in C Using Pointers

Arnab Chakraborty
Updated on 29-Dec-2020 13:24:43

9K+ Views

Suppose we have a string s. We have to check whether the given string is a palindrome or not. We have to solve this problem using pointers in C.So, if the input is like s = "racecar", then the output will be True.To solve this, we will follow these steps −length := size of stringforward := pointing to the first character of stringreverse := pointing to the last character of stringwhile position of reverse >= position of forward, doif character pointed by reverse is same as character pointed by forward, thenincrease forward and decrease reverse by 1otherwisecome out from loopif ... Read More

Check If a String Is Isogram or Not in Python

Arnab Chakraborty
Updated on 29-Dec-2020 13:22:20

2K+ Views

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

Check If a String is Colindrome in Python

Arnab Chakraborty
Updated on 29-Dec-2020 13:20:38

402 Views

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

Check if a String Has m Consecutive 1s or 0s in Python

Arnab Chakraborty
Updated on 29-Dec-2020 13:17:33

579 Views

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

Check If a String Has All Characters with Same Frequency with One Variation Allowed in Python

Arnab Chakraborty
Updated on 29-Dec-2020 13:16:11

220 Views

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

Check If a String Follows A N B N Pattern in Python

Arnab Chakraborty
Updated on 29-Dec-2020 13:14:02

236 Views

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

Check for Palindromic Substring of Even Length in Python

Arnab Chakraborty
Updated on 29-Dec-2020 13:12:42

402 Views

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

Check If a String Can Become Empty by Recursively Deleting a Given Substring in Python

Arnab Chakraborty
Updated on 29-Dec-2020 13:11:47

434 Views

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

Advertisements