Programming Articles - Page 1523 of 3363

Check if all elements of the array are palindrome or not in Python

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

2K+ Views

Suppose we have a list of numbers nums. We have to check whether the list is palindrome or not.So, if the input is like nums = [10, 12, 15, 12, 10], then the output will be True.To solve this, we will follow these steps −n := size of numsreset is_palindromei := 0while i

Check if all digits of a number divide it in Python

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

725 Views

Suppose we have a number n. We have to check whether all digits of it can divide n or not.So, if the input is like n = 135, then the output will be True, because (135 / 1 = 135), (135 / 3 = 45) and (135 / 5 = 27).To solve this, we will follow these steps −val := nwhile val > 0, dod := val mod 10if n is not divisible by d, thenreturn Falseval := quotient of (val / 10)return TrueLet us see the following implementation to get better understanding −Example Live Demodef is_divisible(n, d) :    return ... Read More

Check if all bits of a number are set in Python

Yaswanth Varma
Updated on 30-Jul-2025 15:14:27

518 Views

In computers, data is stored in the binary form, which uses the two digits 0 and 1. Each digit in this format is known as a bit. In this article, we are going to check if all bits of a number are set in Python. A bit is said to be set if the binary representation of every bit is 1. Let's look at some scenarios to understand this better: Scenario 1 Input: 3 Binary: 111 Output: True Explanation: All bits are 1. Scenario 2 Input: 6 Binary: 110 Output: False Explanation: Not all bits are 1. ... Read More

Check if a two-character string can be made using given words in Python

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

197 Views

Suppose we have a string s of length 2, and also have a list of words w where all words are of length 2. We have to check whether we can concatenate words from w and that concatenated string contains s as substring or not.So, if the input is like s = "no", w = ["ol", "on", "ni", "to"], then the output will be True as we can concatenate strings like "onol", that contains "no"To solve this, we will follow these steps −n := the number of words in wchar_0 := False, char_1 := Falsefor i in range 0 to ... Read More

Check if a triangle of positive area is possible with the given angles in Python

Arnab Chakraborty
Updated on 29-Dec-2020 13:28:56

946 Views

Suppose we have three angles. We have to check whether it is possible to create a triangle of positive area with these angles or not.So, if the input is like a = 40 b = 120 c = 20, then the output will be True as the sum of 40 + 120 + 20 = 180.To solve this, we will follow these steps −if a, b and c are not 0 and (a + b + c) is same as 180, thenif (a + b) >= c or (b + c) >= a or (a + c) >= b, thenreturn ... Read More

Check if a string is the typed name of the given name in Python

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

563 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

471 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

10K+ 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

444 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

Advertisements