Found 26504 Articles for Server Side Programming

Check if a string is suffix of another in Python

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

441 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

393 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

569 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

211 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 or not in Python

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

227 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 if a string contains a palindromic sub-string of even length in Python

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

396 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 sub-string in Python

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

427 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

Check if a string can be repeated to make another string in Python

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

463 Views

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

Advertisements