Arnab Chakraborty

Arnab Chakraborty

3,768 Articles Published

Articles by Arnab Chakraborty

Page 188 of 377

Program to find minimum sum of difficulties to complete jobs over k days in C++

Arnab Chakraborty
Arnab Chakraborty
Updated on 11-Mar-2026 245 Views

Suppose we have a list of numbers called jobs and another value k. Now we want to finish all jobs in k different days. The jobs must be performed in the given order and in each day we have to complete one task. The difficulty of job i is stored at jobs[i] and the difficulty of completing a list of jobs on a day will be the maximum difficulty job performed on that day. So we have to find the minimum sum of the difficulties to perform the jobs over k different days.So, if the input is like jobs = ...

Read More

Program to justify a set of words by converting them into same length lines in C++

Arnab Chakraborty
Arnab Chakraborty
Updated on 11-Mar-2026 140 Views

Suppose we have an list of words and a width k, we have to arrange the text such that each line has exactly k number of characters and the text is fully justified. Here we shall pack our words as many words as we can insert in each line. And we shall pad extra spaces ' ' when necessary so that each line has exactly k characters.Here extra spaces between words should be distributed as evenly as possible. If the number of spaces on a line do not divide evenly between words, empty slots on the left will be assigned ...

Read More

Program to find sum of k non-overlapping sublists whose sum is maximum in C++

Arnab Chakraborty
Arnab Chakraborty
Updated on 11-Mar-2026 268 Views

Suppose we have a list of numbers called nums, and another value k, we have to find the k non-overlapping, non-empty sublists such that the sum of their sums is maximum. We can consider k is less than or equal to the size of nums.So, if the input is like nums = [11, -1, 2, 1, 6, -24, 11, -9, 6] k = 3, then the output will be 36, as we can select the sublists [11, -1, 2, 1, 6], [11], and [6] to get sums of [19, 11, 6] = 36.To solve this, we will follow these steps ...

Read More

Program to find maximum sum of two sets where sums are equal in C++

Arnab Chakraborty
Arnab Chakraborty
Updated on 11-Mar-2026 229 Views

Suppose we have a list of numbers called nums, now find two sets as their sums are same and maximum, then find sum value.So, if the input is like nums = [2, 5, 4, 6], then the output will be 6, as the sets are [2, 4] and [6].To solve this, we will follow these steps −sum := 0for each number i in nums, dosum := sum + in := size of numsDefine one 2D array dp of size (n + 1) x (2 * sum + 5) and fill with -1dp[0, sum] := 0for initialize i := 1, when ...

Read More

Program to Find Out the Best Interval to Remove in C++

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

Suppose we have a list of intervals (inclusive) that are potentially overlapping. Now consider there is an operation where we delete one interval, then merge the remaining intervals and then count the number of intervals left over. We have to find the maximum number of leftover intervals possible after removal.So, if the input is like intervals = [ [5, 8], [6, 7], [7, 10], [9, 11]], then the output will be 2. This is because −If we delete the interval [5, 8] we get [6, 11] as the merge.If we delete the interval [6, 7] we get [5, 11] as ...

Read More

Check if an array is stack sortable in C++

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

Suppose we have an array nums of unique elements from 1 through n. We have to check whether it is stack-sortable or not. An array is stack sortable when it can be stored in some other array using a temporary stack.To solve this, we can use any of these operations on the array −Delete the starting element of array and push that item into the stack.Delete the top element of the stack and insert it to the end of second array.Now if all the element of the given array is transferred to the second array by these operations so the ...

Read More

Program to get next integer permutation of a number in C++

Arnab Chakraborty
Arnab Chakraborty
Updated on 11-Mar-2026 508 Views

Suppose we have a number n, we have to find the next bigger permutation of its digits. When n is already in its largest permutation, then rotate it down to the smallest permutation.So, if the input is like n = 319, then the output will be 391.To solve this, we will follow these steps −Define a function makeArray(), this will take x, Define an array retwhile x is non-zero, do −insert x mod 10 at the end of retx := x / 10reverse the array retreturn retDefine a function combine(), this will take an array v, ret := 0for each ...

Read More

Program to find number of operations needed to decrease n to 0 in C++

Arnab Chakraborty
Arnab Chakraborty
Updated on 11-Mar-2026 272 Views

Suppose we have a number n. Now consider an operation where we can either 1. Decrement n by one 2. If n is even number, then decrement it by n / 2 3. If n is divisible by 3, then decrement by 2 * (n / 3) Finally find the minimum number of operations required to decrement n to zero.So, if the input is like n = 16, then the output will be 5, as n = 16 even then decreases it by n/2 4 times, it will be 1. Then reduce it by 1 to get 0. So total ...

Read More

Program to find maximum number of package that can be bought by buyers in C++

Arnab Chakraborty
Arnab Chakraborty
Updated on 11-Mar-2026 348 Views

Suppose we have two lists sales and buyers. Each element in sales contains two values in the form [day, price] this indicates the package is available for sale only on that day for that given price. And each element in buyers in the form [payday, amount] indicates that the buyer has that amount of money to spend on payday and afterward. If each buyer can buy at most one package, and each package can be sold to only one person, find the maximum number of packages that can be bought.So, if the input is like sales = [[0, 5], [0, ...

Read More

Program to count number of ways we can place nonoverlapping edges to connect all nodes in C++

Arnab Chakraborty
Arnab Chakraborty
Updated on 11-Mar-2026 146 Views

Suppose we have a number n that is representing the number of nodes that are placed circularly. We have to find the number of ways we can place n / 2 edges such that every node is connected by an edge, and that edges does not intersect with each other. If the answer is very large then return result mod 10^9 + 7.So, if the input is like n = 4, then the output will be 2, as we can group them like below −To solve this, we will follow these steps −Define an array dp of size (n/2 + ...

Read More
Showing 1871–1880 of 3,768 articles
« Prev 1 186 187 188 189 190 377 Next »
Advertisements