Check if a string can be converted to another string by replacing vowels and consonants in Python

Arnab Chakraborty
Updated on 25-Mar-2026 14:08:26

474 Views

Sometimes we need to check if one string can be transformed into another by replacing characters with specific rules. In this problem, we can only replace vowels with other vowels and consonants with other consonants. The transformation rules are: A vowel (a, e, i, o, u) can only be replaced with another vowel A consonant can only be replaced with another consonant Both strings must have the same length Example If we have s = "udpmva" and t = "itmmve", we can transform: u (vowel) → i (vowel) ✓ d (consonant) → t (consonant) ... Read More

Check if a sorted array can be divided in pairs whose sum is k in Python

Arnab Chakraborty
Updated on 25-Mar-2026 14:08:08

222 Views

Suppose we have a sorted array of numbers and another number k. We need to check whether the given array can be divided into pairs such that the sum of every pair equals k. So, if the input is like arr = [1, 2, 3, 4, 5, 6] and k = 7, then the output will be True as we can form pairs like (1, 6), (2, 5) and (3, 4). Algorithm To solve this, we will follow these steps − Get the size of the array If the array size is odd, return False ... Read More

Check if a queue can be sorted into another queue using a stack in Python

Arnab Chakraborty
Updated on 25-Mar-2026 14:07:51

418 Views

Sometimes we need to check if elements in a queue can be rearranged into sorted order using an auxiliary stack. This problem involves three data structures: an input queue, a stack for temporary storage, and an output queue for the final sorted sequence. Problem Understanding Given a queue with the first n natural numbers in unsorted order, we need to determine if we can sort them into non-decreasing sequence using these operations: Push or pop elements from stack Delete element from input queue Insert element into output queue For example, with queue [6, 1, ... Read More

Check if a Queen can attack a given cell on chessboard in Python

Arnab Chakraborty
Updated on 25-Mar-2026 14:07:25

814 Views

In chess, a queen is the most powerful piece that can move horizontally, vertically, and diagonally any number of squares. Given two coordinates on a chessboard representing a queen's position and a target cell, we need to determine if the queen can attack that position. So, if the input is like Q = (1, 1) and O = (4, 4), then the output will be True as the queen can reach (4, 4) diagonally. ... Read More

Check if a prime number can be expressed as sum of two Prime Numbers in Python

Arnab Chakraborty
Updated on 25-Mar-2026 14:07:00

1K+ Views

Given a prime number n, we need to check whether it can be expressed as the sum of two prime numbers (x + y where both x and y are prime). This is related to Goldbach's conjecture, which states that every even integer greater than 2 can be expressed as the sum of two primes. For example, if n = 19, we can express it as 19 = 17 + 2, where both 17 and 2 are prime numbers. Approach We'll use a simple approach by checking if both n and (n - 2) are prime numbers. ... Read More

Check if a point lies on or inside a rectangle in Python

Arnab Chakraborty
Updated on 25-Mar-2026 14:06:37

6K+ Views

When working with geometric problems in Python, checking if a point lies inside a rectangle is a fundamental task. Given a rectangle defined by its bottom-left and top-right corner points, we can determine if any point (x, y) falls within its boundaries. Problem Statement Given a rectangle represented by two points: bottom-left corner (x1, y1) and top-right corner (x2, y2), we need to check whether a given point (x, y) lies inside or on the rectangle. For example, if bottom_left = (1, 1), top_right = (8, 5), and point = (5, 4), the output should be True ... Read More

Running Selenium Webdriver with a proxy in Python.

Debomita Bhattacharjee
Updated on 25-Mar-2026 14:06:08

4K+ Views

We can run a proxy with Selenium webdriver in Python. A proxy is an essential component to do localization testing. We can take an e-commerce application and check if the language and currency visible is as per the user location. With the help of proxy within tests, we can verify if the website user interface matches with the location. We have to set a proxy with below steps − Import webdriver from Selenium package. Define proxy server address. Create an object of ChromeOptions class Communication of proxy with ChromeOptions. Summing options to Chrome() object. Basic ... Read More

Program to Find Out the Smallest Substring Containing a Specific String in Python

Arnab Chakraborty
Updated on 25-Mar-2026 14:05:47

2K+ Views

Finding the smallest substring that contains a specific string as a subsequence is a challenging problem. Given two strings s and t, we need to find the shortest substring in s where t appears as a subsequence. If multiple substrings exist with the same minimum length, we return the leftmost one. For example, if s = "abcbfbghfb" and t = "fg", the output will be "fbg" because it's the smallest substring containing "f" and "g" in sequence. Algorithm Overview We use dynamic programming to solve this problem efficiently ? Create a DP array where dp[i] ... Read More

Program to Reverse a Substring Enclosed Within Brackets in Python

Arnab Chakraborty
Updated on 25-Mar-2026 14:05:20

592 Views

When working with strings containing parentheses, we often need to reverse the content within brackets. This problem requires us to reverse every substring enclosed within parentheses in a recursive manner. For example, if the input string is "back(aps)ce", we need to reverse "aps" to get "spa", resulting in "backspace". Algorithm Approach We'll use a two-phase approach ? Phase 1: Create a mapping of matching parentheses using a stack Phase 2: Traverse the string and reverse content within brackets recursively Step-by-Step Solution Phase 1: Map Matching Brackets First, we identify which opening ... Read More

Program to Find Out the Number of Moves to Reach the Finish Line in Python

Arnab Chakraborty
Updated on 25-Mar-2026 14:04:52

305 Views

In this problem, we have a car starting at position 0 with speed 1 on a one-dimensional road. We need to find the minimum number of moves to reach a target position using two possible operations: Acceleration: position += speed and speed *= 2 Reverse: speed = -1 if speed > 0, otherwise speed = 1 For example, if the target is 10, the minimum number of moves required is 7. Algorithm Approach We use a depth-first search (DFS) with memoization to explore all possible move combinations. The algorithm considers different sequences of acceleration ... Read More

Advertisements