Articles on Trending Technologies

Technical articles with clear explanations and examples

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

Arnab Chakraborty
Arnab Chakraborty
Updated on 25-Mar-2026 971 Views

In geometry, a triangle with positive area must satisfy two conditions: the sum of all angles must equal 180 degrees, and each angle must be positive (greater than 0). Let's explore how to check if three given angles can form a valid triangle. Problem Understanding Given three angles, we need to verify if they can form a triangle with positive area. For a valid triangle: All angles must be positive (greater than 0) Sum of all three angles must equal 180 degrees Each angle must be less than 180 degrees (since other two angles must be ...

Read More

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

Arnab Chakraborty
Arnab Chakraborty
Updated on 25-Mar-2026 583 Views

Sometimes when we type on a keyboard, vowel keys might get long pressed, causing them to repeat one or more times. Given two lowercase strings s (the intended name) and t (the typed name), we need to check whether t could be a result of typing s with some vowels accidentally repeated. So, if the input is like s = "mine" and t = "miiine", then the output will be True because the vowel 'i' is repeated three times while other letters remain unchanged. Algorithm Steps To solve this problem, we will follow these steps − ...

Read More

Check if a string is suffix of another in Python

Arnab Chakraborty
Arnab Chakraborty
Updated on 25-Mar-2026 495 Views

In Python, checking if one string is a suffix of another is a common string manipulation task. A suffix is a substring that appears at the end of a string. For example, "ate" is a suffix of "unfortunate". Python provides multiple approaches to solve this problem efficiently ? Method 1: Using endswith() Method The simplest approach is to use Python's built-in endswith() method ? s = "ate" t = "unfortunate" result = t.endswith(s) print(f"Is '{s}' a suffix of '{t}'? {result}") Is 'ate' a suffix of 'unfortunate'? True Method 2: ...

Read More

Check if a string is Isogram or not in Python

Arnab Chakraborty
Arnab Chakraborty
Updated on 25-Mar-2026 2K+ Views

An isogram is a string where each letter appears exactly once. In Python, we can check if a string is an isogram using various approaches like sets, lists, or built-in functions. For example, "education" is an isogram because each letter (e, d, u, c, a, t, i, o, n) appears only once. Method 1: Using a List to Track Characters We can iterate through each character and maintain a list of seen characters ? def check_isogram_with_list(word): char_list = [] for char in word: ...

Read More

Check if a string is Colindrome in Python

Arnab Chakraborty
Arnab Chakraborty
Updated on 25-Mar-2026 460 Views

A colindrome is a special type of string that consists of concatenated palindromes, each exactly 6 characters long. To check if a string is a colindrome, we need to verify that its length is divisible by 6 and that each 6-character segment is a palindrome. For example, the string "aabbaamnoonm" is a colindrome because it contains two 6-character palindromes: "aabbaa" and "mnoonm". Algorithm To solve this problem, we follow these steps: Check if the string length is divisible by 6 Divide the string into 6-character segments Verify each segment is a palindrome Return True only ...

Read More

Check if a string has m consecutive 1s or 0s in Python

Arnab Chakraborty
Arnab Chakraborty
Updated on 25-Mar-2026 626 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. Algorithm To solve this, we will follow these steps ? str_size := size of s count_0 := 0, count_1 := 0 for i in range 0 to str_size − 1, do ...

Read More

Check if a string has all characters with same frequency with one variation allowed in Python

Arnab Chakraborty
Arnab Chakraborty
Updated on 25-Mar-2026 273 Views

Sometimes we need to check if a string can become "valid" by removing at most one character. A valid string means all unique characters have the same frequency. For example, "aab" is not valid (a appears 2 times, b appears 1 time), but we can remove one 'a' to make it "ab" where both characters appear once. Problem Example Given string s = "xyyzx", we can delete one 'z' to get "xyyx" where both 'x' and 'y' appear twice ? Approach The algorithm counts character frequencies and checks if we can achieve uniform frequency by removing ...

Read More

Check if a string follows a^n b^n pattern or not in Python

Arnab Chakraborty
Arnab Chakraborty
Updated on 25-Mar-2026 285 Views

The a^n b^n pattern refers to a string that contains exactly n consecutive 'a' characters followed by exactly n consecutive 'b' characters. For example, 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^5 b^5 pattern. Algorithm To solve this, we will follow these steps − Get the size of the string Count consecutive 'a' characters from the beginning Check if the number of 'a's multiplied by 2 equals the total string length Verify that all remaining ...

Read More

Check if a string contains a palindromic sub-string of even length in Python

Arnab Chakraborty
Arnab Chakraborty
Updated on 25-Mar-2026 436 Views

A palindrome is a string that reads the same forwards and backwards. In this problem, we need to check if a given string contains any palindromic substring of even length. The key insight is that the shortest even-length palindrome is of length 2, consisting of two identical adjacent characters (like "aa", "bb", etc.). Any longer even-length palindrome must contain at least one pair of adjacent identical characters. Algorithm To solve this problem efficiently, we can use this approach ? Iterate through the string from index 0 to length−2 For each position i, check if string[i] ...

Read More

Check if a string can become empty by recursively deleting a given sub-string in Python

Arnab Chakraborty
Arnab Chakraborty
Updated on 25-Mar-2026 475 Views

Sometimes we need to check if a string can be completely emptied by repeatedly removing occurrences of a substring. This problem involves finding and removing a target substring until either the string becomes empty or no more occurrences exist. 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. Algorithm To solve this, we will follow these steps: while size of ...

Read More
Showing 1–10 of 61,304 articles
« Prev 1 2 3 4 5 6131 Next »
Advertisements