Arnab Chakraborty

Arnab Chakraborty

3,768 Articles Published

Articles by Arnab Chakraborty

Page 281 of 377

Program to find largest kth index value of one list in Python

Arnab Chakraborty
Arnab Chakraborty
Updated on 19-Oct-2021 242 Views

Suppose we have three values n, total, and k. Now consider a list of size n whose sum is same as total and where the absolute difference between any two consecutive elements is at most 1. We have to find the maximum value at index k of such a list.So, if the input is like n = 5 total = 15 k = 3, then the output will be 4, because one possible list is like [3, 2, 3, 4, 3], maximum element that is found at index 3 is 4.To solve this, we will follow these steps −x := ...

Read More

Program to find kth smallest element in linear time in Python

Arnab Chakraborty
Arnab Chakraborty
Updated on 19-Oct-2021 2K+ Views

Suppose we have a list of numbers called nums, we also have another value k, we have to find the kth (starting from 0) smallest element in the list. We have to solve this problem in O(n) time on average.So, if the input is like nums = [6, 4, 9, 3, 1] k = 2, then the output will be 4, as after sorting the list will be like [1, 3, 4, 6, 9], the kth smallest element is 4.To solve this, we will follow these steps −maxHeap := a new empty heapfor i in range 0 to k, doinsert ...

Read More

Program to find maximum number of K-sized groups with distinct type items are possible in Python

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

Suppose we have a list of numbers called counts where counts[i] represents the number of items are of type i. We also have another value k. We have to find the maximum number of groups of size k we can find, such that each group must have items of distinct types.So, if the input is like counts = [2, 3, 5, 3] k = 2, then the output will be 6, because let four types of items are represented by a, b, c, d respectively. We can have the following groups of k = 2, where all elements are of ...

Read More

Program to count how many blocks are covered k times by walking in Python

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

Suppose we have two lists called walks and target. At the beginning we are at position 0 in a one-dimensional line. Now |walks[i]| represents the number of steps have been walked. And when walk[i] is positive then indicates walked right, and negative for left. When we walk, we move one block, that is the next or previous integer position. We have to find the number of blocks that's been walked on at least target number of times.So, if the input is like walks = [3, -7, 2] target = 2, then the output will be 5, from the following figure, ...

Read More

Program to count number of overlapping islands in two maps in Python

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

Suppose we have two binary matrices mat1 and mat2. Here 1 represents land and 0 represents water, if there is a group of 1(land) surrounded by water is called island. We have to find the number of islands that exist in both mat1 and mat2 at the exact same coordinates.So, if the input is like mat1 =101100100And mat2 =101100101then the output will be 2, because the overlapping islands are, 101100101so there are two overlapping islands.To solve this, we will follow these steps −r := row count of mat1c := column count of mat1last_row := r - 1last_col := c - ...

Read More

Program to find index, where we can insert element to keep list sorted in Python

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

Suppose we have a list of numbers called nums, they are sorted in ascending order, we also have another number target, we have to find the index where target should be inserted to keep nums sorted. If target already present in nums, then return the largest index where target can be inserted. We have to solve this without using library functions and solve it in O(log n) time.So, if the input is like nums = [1, 5, 6, 6, 8, 9] target = 6, then the output will be 4, because 6 is already there, so to insert it, the ...

Read More

Program to find how many updates required to make string half monotonous in Python

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

Suppose we have a lowercase string s whose length is even. We have to find the minimum number of characters that need to be updated such that one of the following three conditions is satisfied for all i, where 0 ≤ i < n/2 and j, n/2 ≤ j < n −s[i] > s[j]s[i] < s[j]s[i] == s[j]So, if the input is like s = "pppxxp", then the output will be 1 because if we change the last "p" to "x", then this can satisfy the condition s[i] < s[j]To solve this, we will follow these steps −n := size ...

Read More

Program to find minimum costs needed to fill fruits in optimized way in Python

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

Suppose we have a list called fruits and another two values k and cap. Where each fruits[i] has three values: [c, s, t], this indicates fruit i costs c each, size of each of them is s, and there is total t of them. The k represents number of fruit baskets of capacity cap. We want to fill the fruit baskets with the following constraints in this order −Each basket can only hold same type fruitsEach basket should be as full as possibleEach basket should be as cheap as possibleSo we have to find the minimum cost required to fill ...

Read More

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 218 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 274 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
Showing 2801–2810 of 3,768 articles
« Prev 1 279 280 281 282 283 377 Next »
Advertisements