Server Side Programming Articles

Page 531 of 2109

Python finding programming question in a String

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

When working with strings in Python, we sometimes need to check if we can form a specific subsequence with equal spacing between characters. This problem asks us to find if we can extract the string "programmingquestion" from a given string where each character is picked at regular intervals. The key insight is that we need to find positions of 'p' and 'r' characters, then check if we can form the target string using consistent spacing starting from these positions. Problem Understanding Given a lowercase string, we need to check if we can pick characters at regular intervals ...

Read More

Remove Substrings in One Iteration in python

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

When working with string manipulation, we often need to remove multiple substrings efficiently. Python's replace() method allows us to chain operations to remove different patterns in sequence. Problem Statement Given a string, we need to remove all occurrences of "y" and "xz" substrings. For example, if the input string is "xyxxzyyxxzx", the output should be "xxxx" after removing these patterns. Solution Approach To solve this problem, we will follow these steps − First, remove all "xz" substrings from the original string Then, remove all "y" characters from the resulting string Return the final cleaned ...

Read More

Pattern After Double, Reverse, and Swap in Python

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

The Pattern After Double, Reverse, and Swap problem generates a sequence by applying three operations cyclically: double, reverse, and swap characters. Starting with "xxy", we apply these operations to find the nth pattern in the sequence. Understanding the Pattern The sequence follows this pattern: xxy xxyxxy (doubled) yxxyxx (reversed) xyyxyy (swapped x↔y) xyyxyyxyyxyy (doubled) ... Algorithm Steps To generate the nth pattern, we follow these rules cyclically: Step 0 (mod 3): Double the string (concatenate with itself) Step 1 (mod 3): Reverse the string Step 2 (mod 3): Swap all 'x' ...

Read More

Domino Covering Board in Python

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

Suppose we have two numbers n and m representing a board of size n x m. We also have an unlimited number of 1 x 2 dominos. We have to find the maximum number of dominos that can be placed on the board such that they don't overlap and every domino lies completely within the board. Each domino covers exactly 2 squares, so the maximum number of dominos we can place is limited by the total number of squares divided by 2. Understanding the Problem For a board of size n x m: Total squares ...

Read More

Detect Voter Fraud in Python

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

Voter fraud detection involves identifying cases where a voter has cast multiple votes in an election. In Python, we can detect this by checking if any voter ID appears more than once in our voting records. Each vote is represented as [candidate_id, voter_id], where the candidate_id is who they voted for and voter_id uniquely identifies the voter. Problem Statement Given a list of votes where each vote contains [candidate_id, voter_id], we need to determine if any voter has voted more than once. For example, if the input is [[5, 1], [5, 0], [5, 4], [5, 3], ...

Read More

Counting Number of Dinosaurs in Python

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

Suppose we have a string called animals and another string called dinosaurs. Every letter in animals represents a different type of animal and every unique character in dinosaurs string represents a different dinosaur. We have to find the total number of dinosaurs in animals. So, if the input is like animals = "xyxzxyZ" dinosaurs = "yZ", then the output will be 3, as there are two types of dinosaurs y and Z. In the animal string there are two y type animals and one Z type animal. Algorithm To solve this, we will follow these steps − ...

Read More

Count Elements x and x+1 Present in List in Python

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

Suppose we have a list of numbers called nums, we have to find the number of elements x there are such that x + 1 exists as well. So, if the input is like [2, 3, 3, 4, 8], then the output will be 3 because: 2 has 3 (2+1) in the list 3 has 4 (3+1) in the list (counted twice since 3 appears twice) 4 doesn't have 5 in the list 8 doesn't have 9 in the list Algorithm To solve this, we will follow these steps − Create a ...

Read More

Cell Count After Removing Corner Diagonals in Python

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

Suppose we have a number n representing the length of an n × n board. We need to remove all cells that are diagonal to one of the four corners and count the remaining cells. In this problem, we identify cells that lie on the main diagonal (top-left to bottom-right) or anti-diagonal (top-right to bottom-left) and mark them as removed. The remaining cells represent our answer. Problem Visualization For n = 4, the board looks like this after removing diagonal cells ? XOOX OXXO OXXO XOOX Here, X represents removed diagonal ...

Read More

Connell sequence in Python

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

The Connell sequence is a mathematical sequence that alternates between groups of consecutive odd and even integers, with each group size increasing by one. Understanding this pattern helps us find the nth term efficiently. Understanding the Connell Sequence Pattern The sequence follows this specific pattern ? Take first 1 odd integer: 1 Take next 2 even integers: 2, 4 Take next 3 odd integers: 5, 7, 9 Take next 4 even integers: 10, 12, 14, 16 Continue alternating with increasing group sizes The complete sequence looks like: 1, 2, 4, 5, 7, 9, 10, ...

Read More

Common Words in Two Strings in Python

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

Finding common words between two strings is a frequent programming task. This involves splitting strings into words, handling case-insensitivity, and finding intersections between word sets. For example, if we have s0 = "i love python coding" and s1 = "coding in python is easy", the common words are python and coding, so the count is 2. Algorithm Steps To find common words between two strings, follow these steps: Convert both strings to lowercase for case-insensitive comparison Split each string into a list of words using split() Convert word lists to sets and find their intersection ...

Read More
Showing 5301–5310 of 21,090 articles
« Prev 1 529 530 531 532 533 2109 Next »
Advertisements