Server Side Programming Articles

Page 452 of 2109

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 209 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 323 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 271 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 488 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 620 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

Check if it is possible to sort the array after rotating it in Python

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

Sometimes we have an array that can be sorted by rotating it. Rotation means taking some contiguous elements from the end and moving them to the front. We need to check if such a rotation can make the array sorted. For example, the array [4, 5, 6, 1, 2, 3] can be sorted by rotating the last three elements [1, 2, 3] to the front, giving us [1, 2, 3, 4, 5, 6]. Algorithm The approach works by finding the rotation point where the sorted order breaks ? If the array is already sorted, return ...

Read More

Check if it is possible to sort an array with conditional swapping of adjacent allowed in Python

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

Suppose we have an unordered array of numbers called nums and all elements are in range 0 to n-1. We can swap adjacent elements in nums as many times as required but only when the absolute difference between these elements is 1. We have to check whether we can sort the nums or not. So, if the input is like nums = [1, 0, 3, 2, 5, 4], then the output will be True as we can swap these pairs [(1, 0), (3, 2), (5, 4)] to sort [0, 1, 2, 3, 4, 5]. Algorithm To solve ...

Read More

Check if it is possible to rearrange rectangles in a non-ascending order of breadths in Python

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

Sometimes we have a list of rectangles represented by their length and breadth coordinates, and we need to arrange them in non-ascending (non-increasing) order of breadths. Since rectangles can be rotated 90 degrees, we can swap length and breadth to optimize the arrangement. The key insight is that for each rectangle, we can choose either dimension as the breadth. We need to make optimal choices to create a non-increasing sequence. Problem Understanding Given rectangles with dimensions [length, breadth], we want to: Optionally rotate each rectangle (swap dimensions) Arrange them so breadths are in non-increasing order ...

Read More

Check if it is possible to serve customer queue with different notes in Python

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

Suppose we have an array called notes representing different rupee notes held by customers in a queue. They are all waiting to buy tickets worth Rs 50. The possible notes are [50, 100, and 200]. We need to check whether we can sell tickets to all customers in order, starting with Rs 0 in our hand. For example, if the input is notes = [50, 50, 100, 100], the output will be True. For the first two customers, we don't need to return any change, but we collect two Rs 50 notes. For the last two customers with Rs ...

Read More
Showing 4511–4520 of 21,090 articles
« Prev 1 450 451 452 453 454 2109 Next »
Advertisements