Programming Articles

Page 501 of 2547

Program to find a sub-list of size at least 2 whose sum is multiple of k in Python

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

Suppose we have a list of non-negative numbers called nums and another positive value k. We have to check whether there is any sublist of length at least 2 whose sum is multiple of k or not. So, if the input is like nums = [12, 6, 3, 4] k = 5, then the output will be True, as the sublist is [12, 3] sums to 15 which is divisible by 5. Algorithm To solve this, we will follow these steps ? sum := 0 m := ...

Read More

Program to find number of elements in A are strictly less than at least k elements in B in Python

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

When working with two lists of numbers, we sometimes need to find how many elements from the first list are strictly smaller than at least k elements in the second list. This problem can be solved efficiently by sorting and comparison. So, if the input is like A = [6, -2, 100, 11], B = [33, 6, 30, 8, 14], k = 3, then the output will be 3, as -2, 6, and 11 are strictly less than 3 elements in B. Algorithm To solve this, we will follow these steps − if k is ...

Read More

Program to check number of global and local inversions are same or not in Python

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

Suppose we have a list of distinct numbers called nums. Here a global inversion is when there are indices i < j such that nums[i] > nums[j]. And a local inversion is when there is an index i such that nums[i] > nums[i + 1]. We have to check whether the number of global inversions is equal to the number of local inversions or not. So, if the input is like nums = [3, 2, 4], then the output will be True, as the indices 0 and 1 are both a global and local inversion. Key Insight ...

Read More

Program to find overlapping intervals and return them in ascending order in Python

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

Overlapping intervals occur when two intervals share common values. Given two sorted lists of non-overlapping intervals, we need to find their intersections and return them in ascending order. The key insight is to use a two-pointer approach to compare intervals from both lists and calculate their overlap using the maximum of start points and minimum of end points. Problem Statement Given two lists of intervals where each list is sorted and non-overlapping internally, find all overlapping intervals between the two lists. Example If we have inv1 = [[50, 100], [190, 270], [310, 330]] and inv2 ...

Read More

Program to find total unique duration from a list of intervals in Python

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

Suppose we have a list of intervals where each interval represents a range [start, end] (inclusive). We need to find the total unique duration covered by all intervals combined, handling any overlaps correctly. So, if the input is like intervals = [[2, 11], [13, 31], [41, 61]], then the output will be 50, as the total unique covered distance is (11 - 2 + 1) = 10 then (31 - 13 + 1) = 19 and (61 - 41 + 1) = 21, so total is 50. Algorithm To solve this, we will follow these steps − ...

Read More

Program to find intervals that do not intersect the cut interval in Python

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

Given a sorted list of disjoint intervals and a cut interval, we need to remove all parts that intersect with the cut interval and return the remaining portions. This is useful for scheduling, range queries, and interval manipulation problems. Problem Understanding For each interval in our list, we check if it intersects with the cut interval. If it does, we keep only the non-overlapping parts. If it doesn't intersect at all, we keep the entire interval. Interval Cutting Example Original: [2, ...

Read More

Program to find number of minimum steps to reach last index in Python

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

Suppose we have a list of numbers called nums and we are placed currently at nums[0]. On each step, we can either jump from the current index i to i + 1 or i - 1 or j where nums[i] == nums[j]. We have to find the minimum number of steps required to reach the final index. So, if the input is like nums = [4, 8, 8, 5, 4, 6, 5], then the output will be 3, as we can jump from index 0 to index 4 as their values are both 4. And then we jump back ...

Read More

Program to find number of friend groups in a set of friends connections in Python

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

Finding friend groups in a network is a classic graph connectivity problem. We need to count the number of connected components where each person is represented as a node and friendships as edges. This can be solved using Depth-First Search (DFS) to traverse connected friends. Understanding the Problem Given a friends list where friends[i] contains the indices of people that person i is friends with, we need to find how many separate friend groups exist. Two people belong to the same group if there's a path of mutual friendships connecting them. ...

Read More

Program to find maximum sum by flipping each row elements in Python

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

Suppose we have a 2D binary matrix. For any row or column in the given matrix we can flip all the bits. If we can perform any number of these operations, and we treat each row as a binary number, we have to find the largest sum that can be made of these numbers. So, if the input is like ? 0 ...

Read More

Campus Bikes II in Python

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

The Campus Bikes II problem involves assigning unique bikes to workers on a 2D grid such that the total Manhattan distance is minimized. Given N workers and M bikes (where N ≤ M), we need to find the optimal assignment. The Manhattan distance between two points p1 and p2 is calculated as: |p1.x - p2.x| + |p1.y - p2.y|. Problem Example Given workers = [[0, 0], [2, 1]] and bikes = [[1, 2], [3, 3]]: ...

Read More
Showing 5001–5010 of 25,466 articles
« Prev 1 499 500 501 502 503 2547 Next »
Advertisements