Server Side Programming Articles

Page 529 of 2109

Latin Square in Python

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

A Latin square is a square matrix where each row and column contains every number from 1 to n exactly once. Let's examine the pattern in different sized Latin squares. Understanding the Pattern Here are examples of Latin squares of different sizes ? 1 2 2 1 1 2 3 3 1 2 2 3 1 1 2 3 4 4 1 2 3 3 4 1 2 2 3 4 1 The key pattern is: the last number of the previous row becomes the first element of the next row. This ...

Read More

Largest product of contiguous digits in Python

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

Finding the largest product of contiguous digits is a common programming problem. Given a number and k, we need to find k consecutive digits that produce the maximum product. Problem Statement Given two numbers num and k, find the largest product of k contiguous digits in num. The number is guaranteed to have at least k digits. For example, if num = 52689762 and k = 4, the output should be 3024 because the largest product of 4 consecutive digits is 8×9×7×6 = 3024. Algorithm Steps To solve this problem, we follow these steps: ...

Read More

Largest Gap in Python

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

In this problem, we need to find the largest difference between two consecutive numbers in a sorted list. This is commonly known as finding the "largest gap" in a dataset. For example, if we have the list [5, 2, 3, 9, 10, 11], after sorting it becomes [2, 3, 5, 9, 10, 11]. The consecutive differences are: 1, 2, 4, 1, 1. The largest gap is 4 (between 5 and 9). Algorithm Steps To solve this problem, we follow these steps: Sort the input list in ascending order Calculate the difference between each pair of ...

Read More

Knights' Attack in Python

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

The knight attack problem checks if any two knights on a chessboard can attack each other. A knight moves in an L-shape: two squares in one direction and one square perpendicular, or vice versa. Problem Understanding Given a binary matrix where 0 represents an empty cell and 1 represents a knight, we need to determine if any two knights are attacking each other. For the input matrix: 00000 01000 00010 The output is True because the knight at position (1, 1) can attack the knight at position (2, 3). Knight ...

Read More

K and -K in Python

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

In Python, finding the largest number k where both k and -k exist in a list is a common programming problem. This means we need to find pairs of numbers that are additive inverses of each other. So, if the input is like [-5, 2, 9, -6, 5, -9], then the output will be 9 because both 9 and -9 exist in the list. Algorithm Approach To solve this problem, we follow these steps: Create L1: a list of non-negative elements (≥ 0) from nums Create L2: a list of non-positive elements (≤ 0) from ...

Read More

Remove One to Make Average k in Python

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

Suppose we have a list of numbers called nums and an integer k, we have to check whether we can remove exactly one element from the list to make the average equal to exactly k. Now we have to keep in mind that, there are some constraints − 2 ≤ n ≤ 1, 000 where n is number of elements of nums list nums[i], k ≤ 1, 000, 000 So, if the input is like [5, 3, 2, 4, 6, 10], k = 4, then the output will ...

Read More

Inverse Factorial in Python

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

An inverse factorial problem asks us to find which number n produces a given factorial value. Given a number a, we need to find n such that n! = a. If no such integer exists, we return -1. For example, if a = 120, we need to find n where n! = 120. Since 5! = 5 × 4 × 3 × 2 × 1 = 120, the answer is 5. Algorithm To solve this problem, we follow these steps ? Initialize i = 0 and num = 1 Create an empty list L to ...

Read More

Find Intersecting Intervals in Python

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

When working with intervals in Python, you often need to find the intersection of multiple intervals. An interval intersection is the overlapping portion that exists within all given intervals. Each interval is represented as [start, end] where both endpoints are inclusive. For example, given intervals [[10, 110], [20, 60], [25, 75]], the intersection is [25, 60] because this range is common to all three intervals. Algorithm Overview To find the intersection of intervals, we need to ? Find the maximum start time among all intervals Find the minimum end time among all intervals The intersection ...

Read More

String Interleaving in Python

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

String interleaving combines two strings by alternating characters from each string, starting with the first string. If one string is longer, the remaining characters are appended to the end. For example, if we have s = "abcd" and t = "pqrstu", the interleaved result will be "apbqcrdstu". Algorithm Steps To solve this problem, we follow these steps − Initialize an empty result string Find the minimum length between both strings Iterate up to the minimum length, alternating characters from each string Append any remaining characters from the longer string Using a Class Method ...

Read More

In-place Move Zeros to End of List in Python

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

Moving zeros to the end of a list while maintaining the relative order of non-zero elements is a common array manipulation problem. This can be solved efficiently using a two-pointer technique that modifies the list in-place with O(1) extra space. The algorithm works by using one pointer to track the position for non-zero elements and another to iterate through the entire list. Algorithm Steps The approach follows these steps: Use a pointer k to track the position for the next non-zero element Iterate through the list and move all non-zero elements to the front Fill ...

Read More
Showing 5281–5290 of 21,090 articles
« Prev 1 527 528 529 530 531 2109 Next »
Advertisements