Arnab Chakraborty

Arnab Chakraborty

3,768 Articles Published

Articles by Arnab Chakraborty

Page 75 of 377

Check if all occurrences of a character appear together in Python

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

Sometimes we need to check if all occurrences of a specific character appear consecutively in a string. This means the character should form a single continuous block without being scattered throughout the string. For example, in the string "bbbbaaaaaaaccddd", all occurrences of 'a' appear together as one block, so the result is True. However, in "bbbaaacccaaaddd", the character 'a' appears in two separate groups, so the result would be False. Algorithm Approach We can solve this using a flag-based approach ? Use a flag to track if we've already seen a block of the target ...

Read More

Check if all enemies are killed with bombs placed in a matrix in Python

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

In this problem, we need to determine if all enemies in a matrix can be eliminated by bombs. The matrix contains three types of cells: 0 for empty area 1 for bomb 2 for enemies Bombs can blast horizontally and vertically across the entire row and column, destroying all enemies in their path (but not other bombs). Problem Example Consider this matrix: 0020 0100 0200 0010 The bomb at position [1, 1] can eliminate the enemy at [2, 1], and the bomb at [3, 2] can eliminate the enemy at ...

Read More

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

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

A palindrome array is an array that reads the same forwards and backwards. In Python, we can check if an array is a palindrome by comparing elements from both ends moving towards the center. So, if the input is like nums = [10, 12, 15, 12, 10], then the output will be True because the array reads the same from left to right and right to left. Algorithm To solve this, we will follow these steps ? Get the size of the array Use a flag variable ...

Read More

Check if all digits of a number divide it in Python

Arnab Chakraborty
Arnab Chakraborty
Updated on 25-Mar-2026 762 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). Algorithm To solve this, we will follow these steps − val := n while val > 0, do ...

Read More

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

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

Given a two-character string s and a list of two-character words w, we need to check whether we can concatenate words from w to create a string that contains s as a substring. For example, if s = "no" and w = ["ol", "on", "ni", "to"], we can concatenate "on" + "ol" to get "onol", which contains "no" as a substring. Algorithm To solve this problem, we need to check three possible scenarios ? The target string s exists directly in the word list We can form s by taking the second character of one ...

Read More

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 586 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 497 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 461 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
Showing 741–750 of 3,768 articles
« Prev 1 73 74 75 76 77 377 Next »
Advertisements