Articles on Trending Technologies

Technical articles with clear explanations and examples

Check if matrix A can be converted to B by changing parity of corner elements of any submatrix in Python

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

Suppose we have two N X M binary matrices A and B. In a single operation, we can select a sub-matrix (at least 2x2) and flip the parity of its four corner elements (toggle bits 0↔1). We need to check whether matrix A can be converted to B by performing any number of such operations. Understanding the Problem When we select a 2x2 submatrix and flip its corners, we're essentially performing an XOR operation on four specific positions. The key insight is that we can systematically work through the matrix from bottom-right to top-left, fixing mismatches using operations ...

Read More

Check if lowercase and uppercase characters are in same order in Python

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

Suppose we have a string with only lowercase or uppercase letters. We need to check whether both lowercase and uppercase letters follow the same order respectively. This means if we extract all lowercase letters and all uppercase letters separately, converting the lowercase sequence to uppercase should match the uppercase sequence. So, if the input is like s = "piPpIePE", then the output will be True, as the lowercase letters "piepe" when converted to uppercase become "PIEPE", which matches the extracted uppercase sequence "PIEPE". Algorithm To solve this, we follow these steps ? ...

Read More

Check if linked list is sorted (Iterative and Recursive) in Python

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

A linked list is sorted in non-increasing order when each node's value is greater than or equal to the next node's value. We can check this condition using both iterative and recursive approaches. So, if the input is like L = [15, 13, 8, 6, 4, 2], then the output will be True because 15 ≥ 13 ≥ 8 ≥ 6 ≥ 4 ≥ 2. LinkedList Node Structure First, let's define the basic structure of a linked list node ? class ListNode: def __init__(self, data, next=None): ...

Read More

Check if leaf traversal of two Binary Trees is same in Python

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

Suppose we have two binary trees. We need to check whether the leaf traversal of these two trees is the same or not. The leaf traversal is the sequence of leaf nodes traversed from left to right. So, if the input is like ? Tree 1 2 3 4 5 ...

Read More

Check if LCM of array elements is divisible by a prime number or not in Python

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

Suppose we have an array called nums and another value k, we have to check whether LCM of nums is divisible by k or not. So, if the input is like nums = [12, 15, 10, 75] and k = 10, then the output will be True as the LCM of the array elements is 300, which is divisible by 10. Mathematical Approach The key insight is that if any element in the array is divisible by k, then the LCM of all elements will also be divisible by k. This is because LCM contains all prime ...

Read More

Check if item can be measured using a scale and some weights in Python

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

When you have weights like a0, a1, a2, ..., a100 and a weighing scale where weights can be placed on both sides, you need to determine if a particular item of weight W can be measured. This involves finding a combination where some weights are added and some are subtracted to equal the target weight. For example, if a = 4 and W = 17, the weights are 1, 4, 16, 64, ... We can achieve 17 by using 16 + 1 = 17. Algorithm The solution uses recursive backtracking to try all possible combinations of weights: ...

Read More

Check if it possible to partition in k subarrays with equal sum in Python

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

Given an array of numbers and a value K, we need to check whether we can partition the array into K contiguous subarrays such that each subarray has equal sum. This problem requires calculating cumulative sums and checking if valid partitions exist. For example, with nums = [2, 5, 3, 4, 7] and k = 3, we can create partitions [(2, 5), (3, 4), (7)] where each subarray sums to 7. Algorithm Steps To solve this problem, we follow these steps: Calculate the total sum of all elements Check if total sum is divisible by ...

Read More

Check if it is possible to transform one string to another in Python

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

When we need to check if one string can be transformed into another by converting lowercase letters to uppercase and removing remaining lowercase letters, we can use dynamic programming to solve this step by step. Given two strings s and t (where t is in uppercase), we need to determine if we can transform s to t by performing these operations: Convert some lowercase letters to uppercase Remove all remaining lowercase letters Problem Understanding For example, if s = "fanToM" and t = "TOM", we can: Convert 'o' to 'O' Remove lowercase letters ...

Read More

Check if it is possible to survive on Island in Python

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

Suppose there is an island with only one store that remains open every day except Sunday. We need to determine if someone can survive for a given number of days and find the minimum number of days they need to buy food. Given the following parameters: N - Maximum number of food units someone can buy each day S - Number of days someone is required to survive M - Number of food units required each day to survive Starting from Monday, we need to check ...

Read More

How can BeautifulSoup be used to extract 'href' links from a website?

AmitDiwan
AmitDiwan
Updated on 25-Mar-2026 13K+ Views

BeautifulSoup is a Python library used for web scraping and parsing HTML/XML documents. It provides a simple way to navigate, search, and extract data from web pages, including extracting href attributes from anchor tags. Installation Install BeautifulSoup using pip ? pip install beautifulsoup4 requests Basic Syntax for Extracting href Links The general approach involves fetching the webpage, parsing it with BeautifulSoup, and using find_all('a') to locate anchor tags ? from bs4 import BeautifulSoup import requests # Basic syntax structure # soup = BeautifulSoup(html_content, "html.parser") # links = soup.find_all('a') # href_value = link.get('href') Example: Extracting All href Links ...

Read More
Showing 5611–5620 of 61,299 articles
« Prev 1 560 561 562 563 564 6130 Next »
Advertisements