Found 26504 Articles for Server Side Programming

Program to find expected value of maximum occurred frequency values of expression results in Python

Arnab Chakraborty
Updated on 11-Oct-2021 09:20:44

147 Views

Suppose we have M different expressions, and the answers of these expressions are in range 1 to N (both inclusive) So consider x = max(f(i)) for each i in range 1 through N, we have to find the expected value of x.So, if the input is like M = 3, N = 3, then the output will be 2.2, becauseSequenceMaximum frequency1113112211321222123113312223223223323333$$E(x) = \sum P(x) * x = P(1) + 2P(2) + 3P(3) = \frac{1}{10} + 2 * \frac{6}{10} + 3 * \frac{3}{10} = \frac{22}{10}$$To solve this, we will follow these steps −combination := a new mapDefine a function nCr() . ... Read More

Program to find out the substrings of given strings at given positions in a set of all possible substrings in python

Arnab Chakraborty
Updated on 11-Oct-2021 09:08:44

183 Views

Suppose we are provided n number of strings; str1, str2, str3, ....., strn. Now, let's suppose that substri is a set that contains all the substrings of stri. The union of all the substr sets is substr_union. We now are given q number of queries, and we have to find the q-th element of the set substr_union. The set substr_union is lexicographically sorted and the indexes start from 1.So, if the input is like list of strings are = ['pqr', 'pqt'], queries are = [4, 7, 9], then the output will be ['pqt', 'qt', 't']The substrings from the first string ... Read More

Program to count number of isosceles triangle from colored vertex regular polygon in Python

Arnab Chakraborty
Updated on 11-Oct-2021 09:05:19

301 Views

Suppose we have one regular polygon with n sides represented as a binary string of size n. The vertices can be colored either in blue (0) or in red (1). They are colored in clockwise direction We have to count number of isosceles triangles whose vertices are vertices of the regular polygon, and their colors are same.So, if the input is like polygon = "111010", then the output will be 2 becausethere are two triangles ACE and AFE.To solve this, we will follow these steps −Define a function all() . This will take nif n mod 2 is same as ... Read More

Program to find the indexes where the substrings of a string match with another string fully or differ at one position in python

Arnab Chakraborty
Updated on 11-Oct-2021 08:59:46

229 Views

Suppose, we are provided with two strings. The first one has a length greater than the second one, and we have to check if the substrings from the first string match exactly with the second string or differ in one position. We return the indexes of the first string, where the substrings that can match with the second string start.So, if the input is like string1 = 'tpoint', string2 = 'pi', then the output will be 1 2.The substring from the first string that matches with the second string or differs in one position at index 1 and 2 are ... Read More

Program to find maximum possible value of an expression using given set of numbers in Python

Arnab Chakraborty
Updated on 11-Oct-2021 08:50:15

360 Views

Suppose we have two arrays called nums1 and nums2, they have same number of elements N. Now consider a set S with N elements from 1 through N. We have to find the value of (nums1[i1] + nums1[i2] + ... nums1[ik])^2 + (nums2[i1] + nums2[i2] + ... nums2[ik])^2 where {i1, i2, ... ik} is non empty subset of the set S.So, if the input is like nums1 = [-1, 6] nums2 = [5, 4], then the output will be 106 because(-1)^2 + (5)^2 = 26(6)^2 + (4)^2 = 50(-1 + 6)^2 + (5 + 4)^2 = 106To solve this, we ... Read More

Program to find out the similarity between a string and its suffixes in python

Arnab Chakraborty
Updated on 11-Oct-2021 08:47:00

182 Views

Suppose, we are given a string 'input_str'. If we determine all the suffixes from input_str; for example if the string is 'abcd', the suffixes are 'abc', 'bcd', 'cd', 'd'. Now, we check the similarity between input_str and all the suffixes by the length of the longest common prefix in input_str and a suffix. The sum of the similarities between input_str and all the suffixes has to be returned.So, if the input is like input_str = 'tpotp', then the output will be 7All the suffixes from the string 'tpotp' are 'tpotp', 'potp', 'otp', 'tp', and 'p'.If we check the similarity of ... Read More

Program to find out the letter at a particular index in a synthesized string in python

Arnab Chakraborty
Updated on 11-Oct-2021 08:41:28

123 Views

Suppose, we are given a string 'input_str'. Now, we are asked to determine every possible substring from the given string then concatenate all the substrings one after another in a lexical order into another string. We are also provided an integer value k. Our task is to return the letter at index k from the concatenated string.So, if the input is like input_str = 'pqrs', k = 6, then the output will be pThe substrings from the given string in lexical order are p, pq, pqr, pqrs, q, qr, qrs, r, rs, s.If we concatenate the strings, it becomes ppqpqrpqrsqqrqrsrrss. ... Read More

Program to find out the sum of numbers where the correct permutation can occur in python

Arnab Chakraborty
Updated on 11-Oct-2021 08:37:08

199 Views

Suppose, we are given a number n and are asked to write all the possible permutations with the positive integers up to n. The permutations are then sorted lexicographically and numbered from 1 to n. Among all the permutations, one permutation is taken and is termed as the special permutation. Now, among the special permutation; the values can be forgotten. The forgotten values are then replaced with 0s. We have to find the permutations that can be equal to the original permutations and then we add their perspective number to obtain a sum. The sum value is returned as the ... Read More

Program to determine the minimum cost to build a given string in python

Arnab Chakraborty
Updated on 11-Oct-2021 08:24:58

1K+ Views

Suppose, we have to build a string 'str' that is of length n. To build the string, we can perform two operations.A character can be added to the end of str for cost a.A substring sub_str can be added to the end of the str for cost r.We have to calculate the minimum cost of building the string str.So, if the input is like a = 5, r = 4, str = 'tpoint', then the output will be 29.To build the string 'tpoint', the cost is described below −str = 't'; a new character added, therefore the cost is 5. ... Read More

Program to find maximum score by splitting binary strings into two parts in Python

Arnab Chakraborty
Updated on 11-Oct-2021 08:17:59

351 Views

Suppose we have a binary string s. Now let us consider an operation, where we split the string into two non-empty substrings s1 and s2. The score of this split is the sum of "0"s count in s1 and sum of "1"s count in s2. We have to find the maximum score we can obtain.So, if the input is like s = "011001100111", then the output will be 8, because we can split the string like "01100" + "110111". Then, the score is 3 + 5 = 8.To solve this, we will follow these steps −ones := number of "1"s ... Read More

Advertisements