Programming Articles

Page 540 of 2547

Find a pair from the given array with maximum nCr value in Python

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

When working with arrays, we sometimes need to find a pair of elements that maximizes the binomial coefficient nCr value. Given an array of integers, we want to find arr[i] and arr[j] such that arr[i]C arr[j] is as large as possible. The key insight is that for a given n, nCr is maximized when r is closest to n/2. This mathematical property helps us efficiently find the optimal pair. Example If the input array is [4, 1, 2], we need to find the pair with maximum nCr value ? 4C1 = 4 4C2 = 6 ...

Read More

Minimum removals from array to make GCD Greater in Python

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

When we have a list of numbers, we may need to remove some elements to increase the GCD (Greatest Common Divisor) of the remaining numbers. This problem asks for the minimum number of removals required to make the GCD larger than the original GCD. For example, given [6, 9, 15, 30], the initial GCD is 3. After removing 6 and 9, we get [15, 30] with GCD = 15, which is greater than 3. So the answer is 2 removals. Algorithm Approach The solution uses prime factorization and the Sieve of Eratosthenes ? Find the ...

Read More

Find three element from different three arrays such that that a + b + c = sum in Python

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

Finding three elements from different arrays that sum to a target value is a common programming problem. We need to check if there exist elements a, b, c from arrays A, B, C respectively such that a + b + c equals the given sum. So, if the input is like A = [2, 3, 4, 5, 6], B = [3, 4, 7, 2, 3], C = [4, 3, 5, 6, 7], sum = 12, then the output will be True as 4+2+6 = 12, where 4, 2, 6 are taken from A, B, C respectively. Method 1: ...

Read More

Minimum edges required to add to make Euler Circuit in Python

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

An Euler Circuit is a path in a graph that visits every edge exactly once and returns to the starting vertex. For an undirected graph to have an Euler Circuit, all vertices must have even degree and the graph must be connected. This article shows how to find the minimum edges needed to make such a circuit possible. Theory Behind Euler Circuits For an undirected graph to have an Euler Circuit: All vertices must have even degree The graph must be connected If these conditions aren't met, we need to add minimum edges to satisfy ...

Read More

Find the winner of a game where scores are given as a binary string in Python

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

When analyzing volleyball match scores represented as binary strings, we need to determine the winner based on specific scoring rules. In this scenario, 1 represents our team scoring a point, while 0 represents the opponent scoring a point. Game Rules The volleyball match follows these conditions: The first team to reach 15 points wins the match Exception: If both teams reach 14 points, the winner must maintain a 2-point lead Algorithm Steps To solve this problem, we follow these steps: Track scores for both teams using a counter array Process each ...

Read More

Minimum Cuts can be made in the Chessboard such that it is not divided into 2 parts in Python

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

Suppose we have an A x B chessboard (matrix), we need to calculate the maximum number of cuts that can be made on this board such that it remains connected as one piece and is not divided into 2 separate parts. The key insight is that we can cut along the grid lines between squares. For an A x B chessboard, there are (A-1) horizontal lines and (B-1) vertical lines where cuts can be made. To keep the board connected, we can cut at most (A-1) × (B-1) grid intersections. Understanding the Problem Consider a 2 x ...

Read More

Find the winner by adding Pairwise difference of elements in the array until Possible in Python

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

Suppose we have an array A of positive integers with unique elements. Two players P and Q are playing a game where at each move, a player picks two numbers a and b from the array and adds |a - b| to the array if it's not already present. The player who cannot make a move loses the game. We need to find the winner if player P always starts first. So, if the input is like A = [8, 9, 10], then the output will be P. Algorithm To solve this problem, we follow these steps: ...

Read More

Minimum Cost to cut a board into squares in Python

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

Suppose we have a board of length p and width q; we have to break this board into p*q number of squares such that cost of breaking is as minimum as possible. Cutting cost for each edge will be given. The key insight is to use a greedy approach: always make the most expensive cut first, because expensive cuts will affect more pieces if made later. Problem Understanding Given: X_slice: costs of horizontal cuts Y_slice: costs of vertical cuts We need to find the minimum total cost to cut the board into unit squares. ...

Read More

Find the time which is palindromic and comes after the given time in Python

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

A palindromic time is a time string that reads the same forwards and backwards. Given a time in 24-hour format (HH:MM), we need to find the next closest palindromic time. For example, "12:21" is palindromic, but "12:34" is not. The algorithm checks if we can form a palindrome with the current hour by reversing it to get the minutes. If not, we increment the hour and try again. Algorithm Steps The solution follows these steps − Extract the hour and minute from the input time string Reverse the hour digits to get potential palindromic minutes ...

Read More

Find the Surface area of a 3D figure in Python

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

Finding the surface area of a 3D figure represented by a matrix involves calculating the exposed surfaces of each building block. Each cell A[i][j] represents the height of a building at position (i, j). Algorithm The surface area calculation considers ? Top and bottom surfaces ? Each cell contributes 2 units (top and bottom) Side surfaces ? Calculate height differences between adjacent cells Border surfaces ? Add full height for cells at matrix edges Step-by-Step Approach Initialize result = 0 For each cell (i, j), calculate height differences with top and left ...

Read More
Showing 5391–5400 of 25,466 articles
« Prev 1 538 539 540 541 542 2547 Next »
Advertisements