Found 26504 Articles for Server Side Programming

Program to Find Out the Minimum Parsing Tree in C++

Arnab Chakraborty
Updated on 23-Dec-2020 06:35:50

410 Views

Suppose we have a list of unique and sorted numbers that represent breakpoints in a string. We want to create a tree out of these rules −There are nodes that have a value (a, b) where a and b are breakpoints. This means the node spans from indices [a, b] in the string.The root node spans over every breakpoint. (the whole string).The spans of a node's left and right child are ordered, contiguous, and contains the parent node's span.Leaf nodes' index of 'a' in breakpoints is 1 before the index of 'b' in breakpoints.The cost of a tree is determined ... Read More

Program to Find Out the Minimal Submatrices in Python

Arnab Chakraborty
Updated on 23-Dec-2020 06:31:53

282 Views

Suppose we have a 2D matrix and another value k. Our goal is to return a matrix that contains the lowest values of all k x k sub-matrices.So, if the input is like3568654312and k =2, then the output will be [[3, 5], [3, 3]] .From the input, we can see that the top left submatrix has the lowest value of 33 5 8 6The top right submatrix has the lowest value of 55 6 6 5The bottom left submatrix has the lowest value of 38 6 4 3The bottom right submatrix has the lowest value of 36 5 3 12To ... Read More

Program to find sum of widths of all subsequences of list of numbers in Python

Arnab Chakraborty
Updated on 23-Dec-2020 06:29:06

153 Views

Suppose we have a list of numbers called nums, The width of a sequence of numbers as the difference between the maximum and minimum number in the sequence. We have to find the sum of widths of all subsequences of nums. If the answer is very large then mod the result by 10^9+7.So, if the input is like nums = [7, 4, 9], then the output will be 15, as we have the subsequences like: [7], [4], [9], [7, 4], [7, 9], [4, 9], [7, 4, 9] and So the widths are 0, 0, 0, 3, 2, 5, 5, so ... Read More

Program to find number of sublists containing maximum and minimum after deleting only one element in Python

Arnab Chakraborty
Updated on 23-Dec-2020 06:27:51

224 Views

Suppose we have a list of numbers called nums and we can delete at most one element in the list. We have to find the maximum number of sublists that contain both the maximum and minimum values of the resulting list.So, if the input is like nums = [3, 2, 6, 2, 4, 10], then the output will be 8, as if we remove 10 we will get [3, 2, 6, 2, 4] and there are eight sublists where it contains both the max and the min −[2, 6][6, 2][2, 6, 2][3, 2, 6][6, 2, 4][2, 6, 2, 4][3, 2, ... Read More

Program to find size of sublist where product of minimum of A and size of A is maximized in Python

Arnab Chakraborty
Updated on 23-Dec-2020 06:25:49

154 Views

Suppose we have a list of numbers called nums and another value pos. We have to find a sublist A of nums that includes the index pos such that (minimum of A) * (size of A) is maximized then return the value.So, if the input is like nums = [-2, 2, 5, 4] pos = 3, then the output will be 8, as the best sublist is [5, 4], because (5, 4) = 4 and its size is 2 we have 4 * 2 = 8.To solve this, we will follow these steps −ans := A[pos], m := A[pos]i := ... Read More

Program to expand string represented as n(t) format in Python

Arnab Chakraborty
Updated on 23-Dec-2020 06:23:51

369 Views

Suppose we have a string s, this is encoding a longer string. s is represented as the concatenation of n(t), n(t) represents the concatenation of t, n times, and t is either a regular string or it is another encoded string recursively. We have to find the decoded version of s.So, if the input is like s = "3(pi)2(3(am))0(f)1(u)", then the output will be "pipipiamamamamamamu"To solve this, we will follow these steps −i := 0Define a function parse() . This will takeans := a new listwhile i < size of s and s[i] is not same as ")", doif s[i] ... Read More

Program to find k where given matrix has k by k square of same value in C++

Arnab Chakraborty
Updated on 23-Dec-2020 06:21:22

178 Views

Suppose we have a 2d matrix, we have to find the largest k × k submatrix where all of its elements are containing the same value, then find the value of k.So, if the input is like1183155525554555then the output will be 3, as there is a 3 × 3 square matrix of value 5.To solve this, we will follow these steps −n := row count of matrixm := column count of matrixDefine one 2D array dp of size (n x m) and fill with 1ret := 1for initialize i := n - 1, when i >= 0, update (decrease i ... Read More

Program to count number of palindromes after minimum number of split of the string in C++

Arnab Chakraborty
Updated on 23-Dec-2020 06:18:41

148 Views

Suppose we have a lowercase string s, we have to split it into as few strings as possible such that each string is a palindrome and then find the number of strings.So, if the input is like s = "levelracecar", then the output will be 2, as there are two palindromes "level" and "racecar".To solve this, we will follow these steps −n := size of ADefine an array result of size (n + 1)result[n] := -1for initialize i := n - 1, when i >= 0, update (decrease i by 1), do −result[i] := n - i - 1for initialize ... Read More

Program to find minimum largest sum of k sublists in C++

Arnab Chakraborty
Updated on 23-Dec-2020 06:17:00

183 Views

Suppose we have a list of numbers called nums and another value k. We can split the list into k non-empty sublists. We have to find the minimum largest sum of the k sublists.So, if the input is like nums = [2, 4, 3, 5, 12] k = 2, then the output will be 14, as we can split the list like: [2, 4, 3, 5] and [12].To solve this, we will follow these steps −Define a function ok(), this will take array v, k, x,cnt := 0, sum := 0for each element i in v −if sum + i > x, then −sum := i(increase cnt by 1)Otherwisesum := sum + ireturn true when cnt

Program to find minimum cost to increase heights of trees where no adjacent tree has same height in Python

Arnab Chakraborty
Updated on 23-Dec-2020 06:14:54

246 Views

Suppose we have a list of numbers called heights that represents the height of plants and we have another list of values called costs that represents the price needed to increase height of a plant by one. We have to find the smallest cost to make each height in the heights list different from adjacent heights.So, if the input is like heights = [3, 2, 2] costs = [2, 5, 3], then the output will be 3, as we can increase the last height by 1, which costs 3.To solve this, we will follow these steps −Define a function dp() ... Read More

Advertisements