Arnab Chakraborty

Arnab Chakraborty

3,768 Articles Published

Articles by Arnab Chakraborty

Page 52 of 377

Program to find minimum cost to send same number of people to two different cities in Python

Arnab Chakraborty
Arnab Chakraborty
Updated on 18-Oct-2021 213 Views

Suppose we have a list called costs. Where costs[i] has [c1, c2] indicates that for person i it costs c1 amount to reach city 0 and costs c2 amount to reach city 1. We want the same number of people to go to city 0 as city 1, we have to find the minimum cost required.So, if the input is like costs = [[2, 6], [10, 3], [4, 9], [5, 8]], then the output will be 17, because person 0 and 2 will go to city 0 and person 1 and 3 to city 1, so for city 0, the ...

Read More

Program to check first player can win by reaching total sum to target in Python

Arnab Chakraborty
Arnab Chakraborty
Updated on 18-Oct-2021 271 Views

Suppose we have two numbers k and target. Now consider Amal and Bimal are playing a game. In each round Amal picks a number from 1 to k to add to the total score that initially starts from 0. Whoever crosses the total to target wins. Amal always plays first, we have to check whether he can force a win if both of them plays optimally.So, if the input is like k = 5 target = 10, then the output will be True, as if Amal picks 4 first, then whether Bimal picks 1, 2, ..., or 5, Amal can ...

Read More

Program to find indices or local peaks in Python

Arnab Chakraborty
Arnab Chakraborty
Updated on 18-Oct-2021 283 Views

Suppose we have a list of numbers called nums. We have to find the index of every peak element in the nums, sorted in ascending order. An index i of a peak element when all of these three conditions are satisfied: 1. The next number on its right that's different than nums[i] doesn't present or must be smaller than nums[i] 2. The previous number on its left that's different than nums[i] doesn't present or must be smaller than nums[i] 3. There is at least one number on its left side or right side that is different from nums[i].So, if the ...

Read More

Program to find sum of the minimums of each sublist from a list in Python

Arnab Chakraborty
Arnab Chakraborty
Updated on 18-Oct-2021 333 Views

Suppose we have a list of numbers called nums. We have to find the sum of minimum of x for every sublist x in nums. If the answer is too large, then mod the result by 10^9 + 7.So, if the input is like nums = [5, 10, 20, 10, 0], then the output will be 90 because, the sublists are [[5], [10], [20], [10], [0], [5,10], [10,20], [20,10], [10,0], [5,10,20], [10,20,10], [20,10,0], [5,10,20,10], [10,20,10,0], [5,10,20,10,0]], and their minimum values are [5, 10, 20, 10, 0, 5, 10, 10, 0, 5, 10, 0, 5, 0, 0], so the sum is 90.To solve this, we will follow these steps −ans := 0s := a new listtemp_sum := 0for each index and value in nums, dowhile s and value

Read More

Program to check every sublist in a list containing at least one unique element in Python

Arnab Chakraborty
Arnab Chakraborty
Updated on 18-Oct-2021 383 Views

Suppose we have a list of elements called nums, we have to check whether every sublist has at least 1 element in it that occurs exactly once in the sublist or not. We have to solve this problem in linear time.So, if the input is like nums = [5, 10, 20, 10, 0], then the output will be True, because every sublist in nums has at least one element which has occurred only once. [[5], [10], [20], [10], [0], [5, 10], [10, 20], [20, 10], [10, 0], [5, 10, 20], [10, 20, 10], [20, 10, 0], [5, 10, 20, 10], ...

Read More

Minimum number of moves to escape maze matrix in Python

Arnab Chakraborty
Arnab Chakraborty
Updated on 18-Oct-2021 1K+ Views

Suppose we have a binary matrix, where 0 is representing an empty cell, and 1 is a wall. If we start from top left corner (0, 0), we have to find the minimum number of cells it would take to get to bottom right corner (R-1, C-1) Here R is number of rows and C is number of columns. If we cannot find any answer, return -1.So, if the input is like00010001100001111000then the output will be 8 because, we can select path like −00010001100001111000To solve this, we will follow these steps −R := number of rowsC := number of columnsq ...

Read More

Program to find number of quadruples for which product of first and last pairs are same in Python

Arnab Chakraborty
Arnab Chakraborty
Updated on 18-Oct-2021 315 Views

Suppose we have a list of numbers called nums, with unique positive numbers nums. We have to find the number of quadruples like (a, b, c, d) from nums such that a*b = c*d, a, b, c and d all are distinct elements of nums.So, if the input is like nums = [3, 6, 4, 8], then the output will be 8, because the quadruples are [[3, 8, 6, 4], [3, 8, 4, 6], [8, 3, 6, 4], [8, 3, 4, 6], [6, 4, 3, 8], [4, 6, 3, 8], [6, 4, 8, 3], [4, 6, 8, 3]].To solve this, ...

Read More

Program to find number of operations needed to make pairs from first and last side are with same sum in Python

Arnab Chakraborty
Arnab Chakraborty
Updated on 18-Oct-2021 176 Views

Suppose we have a list of numbers called nums. The length of this list is even. Now consider an operation where we select any number in nums and update it with a value in range [1 and maximum of nums]. We have to find the minimum number of such operations required such that, for every i, nums[i] + nums[n-1-i] equals to the same number.So, if the input is like nums = [8, 6, 2, 5, 9, 2], then the output will be 2, because if we change first 2 at nums[2] to 5, and 9 at nums[4] to 4, then ...

Read More

Program to find number of elements can be removed to make odd and even indexed elements sum equal in Python

Arnab Chakraborty
Arnab Chakraborty
Updated on 18-Oct-2021 717 Views

Suppose we have a list of numbers called nums. Now consider a function say f(i) which deletes the element at index i and then returns true or false, depending the resulting list's sum of even index values is same as the sum of odd index values or not. So we need the number of indexes for which f would return true.So, if the input is like nums = [6, 8, 5, 2, 3], then the output will be 2 becuase, if we remove 8, the array will be [6, 5, 2, 3], the odd and even index elements sum is ...

Read More

Program to find stone removal rate in K hours in Python

Arnab Chakraborty
Arnab Chakraborty
Updated on 18-Oct-2021 156 Views

Suppose we have a list of numbers called piles and a value k. The piles[i] represents, the number of stones on the pile i. On each hour, we select any pile and remove r number of stones from that pile. If we pick a pile with fewer than r stones, it still takes an hour to clear the pile. We have to find the minimum value of r, such that we can remove all the stones in less than or equal to k hours.So, if the input is like piles = [3, 6, 4] k = 5, then the output ...

Read More
Showing 511–520 of 3,768 articles
« Prev 1 50 51 52 53 54 377 Next »
Advertisements