Article Categories
- All Categories
-
Data Structure
-
Networking
-
RDBMS
-
Operating System
-
Java
-
MS Excel
-
iOS
-
HTML
-
CSS
-
Android
-
Python
-
C Programming
-
C++
-
C#
-
MongoDB
-
MySQL
-
Javascript
-
PHP
Articles by Arnab Chakraborty
Page 59 of 377
Program to find minimum number of operations required to make lists strictly Increasing in python
Suppose we have two list of numbers called A and B, and they are of same length. Now consider we can perform an operation where we can swap numbers A[i] and B[i]. We have to find the number of operations required to make both lists strictly increasing.So, if the input is like A = [2, 8, 7, 10] B = [2, 4, 9, 10], then the output will be 1, as we can swap 7 in A and 9 in B. Then the lists will be like A = [2, 8, 9, 10] and B = [2, 4, 7, 10] ...
Read MoreProgram to find number of coins needed to make the changes in Python
Suppose we have coins of different denominations (1, 5, 10, 25) and a total amount of money amount. We have to define one function to compute the fewest number of coins that we need to make up that amount. So if the input is 64, the output is 7. This is formed using 25 + 25 + 10 + 1 + 1 + 1 + 1 = 64.To solve this, we will follow these steps −if amount = 0, then return 0if minimum of coins array > amount, then return -1define one array called dp, of size amount + 1, ...
Read MoreMaximum Points You Can Obtain from Cards in C++
Suppose there are several cards arranged in a row, each card has associated points, and these points are given in the integer array called cardPoints. In one step, we can take one card from the beginning or from the end of the row. We have to take exactly k cards. The final score will be the sum of the points of the cards we have taken. So, if we have integer array cardPoints and the integer k, then find the maximum score we can obtain.So, if the input is like cardPoints = [1, 2, 3, 4, 5, 6, 1], k ...
Read MoreProgram to find two pairs of numbers where difference between sum of these pairs are minimized in python
Suppose we have a list of numbers called nums and we want to select two pairs of numbers from it such that the absolute difference between the sum of these two pairs is minimized.So, if the input is like nums = [3, 4, 5, 10, 7], then the output will be 1, as we can select these pairs (3 + 7) - (4 + 5) = 1.To solve this, we will follow these steps:distances := a new listfor i in range 0 to size of nums - 2, dofor j in range i + 1 to size of nums - ...
Read MoreDiagonal Traverse II in C++
Suppose we have a list of lists called nums, we have to show all elements of nums in diagonal order.So, if the input is likethen the output will be [1, 6, 2, 8, 7, 3, 9, 4, 12, 10, 5, 13, 11, 14, 15, 16]To solve this, we will follow these steps −Define an array retDefine one 2D array vfor initialize i := 0, when i < size of nums, update (increase i by 1), do −for initialize j := 0, when j < size of nums[i], update (increase j by 1), do −insert { nums[i, j], i, j } ...
Read MoreProgram to find minimum sum subsequence by taking at least one element from consecutive 3 elements in python
Suppose we have a 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.To solve this, we will follow these steps:n := size of numsif n is same as 0, thenreturn 0if n is same ...
Read MoreProgram to make pairwise adjacent sums small in Python
Suppose we have a list of non-negative numbers say nums and a non-negative value k. Now suppose we can perform an operation where we select a single positive umber in nums and decrease it by 1. We have to find the minimum number of operations required such that every pair of adjacent values in the list sums
Read MoreMax Difference You Can Get From Changing an Integer in C++
Suppose we have an integer num. We will apply the following steps exactly two times, the steps are like −Pick a digit x in range 0 to 9.Pick another digit y also in range 0 to 9. The digit y can be equal to x.Replace all the occurrences of x in the decimal representation of num by y. The new integer cannot have any leading zeros, also the new integer cannot be of value 0.Now consider a and b be the results of applying the operations to num the first and second times, respectively. Then find the max difference between ...
Read MoreProgram to find sum of minimum trees from the list of leaves in python
Suppose we have a list of numbers called nums. This list is representing the leaf nodes in inorder traversal of a tree. Here the internal nodes have have 2 children and their value is same as the product of the largest leaf value of its left subtree and the largest leaf value of its right subtree. We have to find the sum of the tree with the minimum sum of its valuesSo, if the input is like nums = [3, 5, 10], then the output will be 83.To solve this, we will follow these steps:res := sum of all elements ...
Read MoreProgram to maximize the minimum value after increasing K sublists in Python
Suppose we have a list of numbers called nums and two values, size and k. Now suppose there is an operation where we take a contiguous sublist of length size and increment every element by one. We can perform this operation k times, we have to find the largest minimum value possible in nums.So, if the input is like nums = [2, 5, 2, 2, 7], size = 3, k = 2, then the output will be 3, as we can increase [2, 5, 2] to get [3, 6, 3, 2, 7] and then increment [6, 3, 2] to get ...
Read More