Programming Articles

Page 497 of 2547

Program to find minimum number of movie theatres required to show all movies in python

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

Suppose we have a list of intervals for different movie showings (they can be overlapped), we have to find the minimum number of theatres required to be able to show all of the movies. So, if the input is like intervals = [[20, 65], [0, 40], [50, 140]], then the output will be 2, as [20, 65] and [0, 40] are overlapping. [20, 65] and [50, 140] are also overlapping but [0, 40] and [50, 140] are not. So we need 2 theaters. Algorithm To solve this, we will follow these steps ? Create a ...

Read More

Program to find most occurring number after k increments in python

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

Suppose we have a list of numbers called nums and another value k. We can perform an operation where we increase some element by one, at most k times. We have to find the value of the most frequently occurring number we can obtain after these increments. If there are multiple solutions, we select the smallest possible number. So, if the input is like nums = [1, 0, 0, 0, 8, 8, 8, 8] and k = 8, then the output will be 8. We can increase 1 seven times to get 8, and increase any 0 to 1, ...

Read More

Program to find sum of minimum trees from the list of leaves in python

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

Suppose we have a list of numbers called nums. This list represents the leaf nodes in inorder traversal of a binary tree. The internal nodes have exactly 2 children and their value equals the product of the largest leaf value of its left subtree and the largest leaf value of its right subtree. We need to find the sum of all values in the tree that produces the minimum total sum. So, if the input is like nums = [3, 5, 10], then the output will be 83. ...

Read More

Program to find minimum sum subsequence by taking at least one element from consecutive 3 elements in python

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

Suppose we have a list of numbers called nums, we have to find a minimum sum subsequence from the given list such that at least one number for all groups of three consecutive numbers is selected. If the length of given list is less than 3, a number should still be selected. So, if the input is like nums = [2, 3, 4, 5, 6, 7], then the output will be 7, as we can select 2 and 5. Algorithm To solve this problem, we will use dynamic programming with the following approach ? ...

Read More

Program to find minimum number of operations required to make lists strictly Increasing in python

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

Given two lists A and B of equal length, we can swap elements at position i between the lists (swap A[i] with B[i]). The goal is to find the minimum number of swaps required to make both lists strictly increasing. For example, with A = [2, 8, 7, 10] and B = [2, 4, 9, 10], we can swap elements at index 2 (swap 7 and 9) to get A = [2, 8, 9, 10] and B = [2, 4, 7, 10], both strictly increasing with just 1 swap. Algorithm Approach We use dynamic programming with recursion ...

Read More

Program to fill Min-max game tree in Python

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

The Min-max game tree algorithm is used in two-player games where one player wants to maximize the score while the other wants to minimize it. In this implementation, Player 1 (maximizer) plays at even levels and Player 2 (minimizer) plays at odd levels. How the Algorithm Works The algorithm uses a bottom-up approach: Leaf nodes contain the actual game scores Internal nodes at even levels (Player 1) choose the maximum value from their children Internal nodes at odd levels (Player 2) choose the minimum value from their children Example Tree Structure ...

Read More

Program to find maximum sum of two non-overlapping sublists in Python

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

Finding the maximum sum of two non-overlapping sublists is a classic dynamic programming problem. Given a list of numbers and two lengths x and y, we need to find two sublists with these lengths that don't overlap and have the maximum combined sum. So, if the input is like nums = [3, 2, 10, -2, 7, 6], x = 3, y = 1, then the output will be 22, as the sublist with length 3 we select [3, 2, 10] (sum = 15) and for the other we select [7] (sum = 7). Algorithm Steps To solve ...

Read More

Program to find maximum sum by removing K numbers from ends in python

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

Suppose we have a list of numbers called nums and another value k. We have to find the maximum sum of elements that we can delete, given that we must pop exactly k times, where each pop can be from the left or the right end. So, if the input is like nums = [2, 4, 5, 3, 1] and k = 2, then the output will be 6, as we can delete 2 and 4 from the left end. Algorithm To solve this, we will follow these steps − window ...

Read More

Program to find maximum additive score by deleting numbers in Python

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

Suppose we have a list of numbers called nums. We can perform an operation where we select a number (not the first or last), remove it, and increase our score by the sum of that number and its two adjacent numbers. We have to find the maximal score possible by performing this operation as many times as we want. So, if the input is like nums = [2, 3, 4, 5, 6], then the output will be 39. We can select 5, then sum will be (4 + 5 + 6) = 15, array becomes [2, 3, 4, 6]. ...

Read More

Program to find a target value inside given matrix or not in Python

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

Suppose we have a 2D matrix where each row and column is sorted in non-decreasing order. We need to check whether a given target value is present inside it or not. So, if the input is like ? 2 4 30 3 4 31 6 6 32 And target = 31, then the output will be True. Approach To solve this efficiently, we can start from the top-right corner of the matrix and move either left or down based on the comparison with the target ...

Read More
Showing 4961–4970 of 25,466 articles
« Prev 1 495 496 497 498 499 2547 Next »
Advertisements