Find N Valid Bracket Sequences in C++

Arnab Chakraborty
Updated on 03-Mar-2022 07:28:11

480 Views

Suppose we have a number n. As we know, a bracket sequence is a string containing only characters "(" and ")". A valid bracket sequence is a bracket sequence which can be transformed into a correct arithmetic expression by inserting characters "1" and "+" between the original characters of the sequence. So, if a bracket sequence is like "()()" this is valid because we can put 1's like "(1)+(1)". From number n, we have to find exactly n different possible valid bracket sequences of length 2n.So, if the input is like n = 4, then the output will be ["()()()()", ... Read More

Python Numpy meshgrid

Syed Abeed
Updated on 03-Mar-2022 07:28:05

911 Views

numpy.meshgrid() is used to return coordinate matrices from coordinate vectors. Its syntax is as follows −numpy.meshgrid(*xi, **kwargs)ParametersMeshgrid can accept the following parameters −x1, x2, …, xn − It represents the coordinates of a grid.indexing − It is an optional parameter which defines the Cartesian 'xy' by default and matrix 'ij' index of output.sparse − It is an optional parameter. If we like to use sparse grid for conserving memory, then we have to set this parameter to True. By default, it is False.copy − It returns a copy of the original array for conversing memory when the parameter is True. ... Read More

Find Fourth Side of a Quadrilateral in C++

Arnab Chakraborty
Updated on 03-Mar-2022 07:24:58

286 Views

Suppose we have three numbers a, b and c. We want to make a closed fence in a shape of arbitrary non-degenerate simple quadrilateral. We already have three sides of length a, b and c. We have to find another side d.So, if the input is like a = 12; b = 34; c = 56, then the output will be 42, other answers are also possible.StepsTo solve this, we will follow these steps −return a + b + c - 2ExampleLet us see the following implementation to get better understanding −#include using namespace std; int solve(int a, int ... Read More

C++ Program to Find Range Whose Sum is Same as N

Arnab Chakraborty
Updated on 03-Mar-2022 07:22:36

203 Views

Suppose we have a number n. We need to find two integers l and r, such that l < r and l + (l + 1) + ... + (r - 1) + r = n.So, if the input is like n = 25, then the output will be l = -2 and r = 7, because (−2) + (−1) + 0 + 1 + 2 + 3 + 4 + 5 + 6 + 7 = 25. Other answers are also possible.StepsTo solve this, we will follow these steps −return -(n-1) and nExampleLet us see the following implementation to get better understanding −#include using namespace std; void solve(int n){    cout

Count Number of Dodecagons of Size D in C++

Arnab Chakraborty
Updated on 03-Mar-2022 07:22:22

148 Views

Suppose we have a number d. Consider there is an infinite number of square tiles and regular triangular tiles with sides length 1. We have to find in how many ways we can form regular dodecagon (12-sided polygon) with sides d using these tiles. If the answer is too large, return result mod 998244353.StepsTo solve this, we will follow these steps−b := floor of d/2 - 1 c := 1 for initialize i := 2, when i < d, update (increase i by 1), do:    b := b * (floor of d/2)    c := c * i return ... Read More

Python NumPy Reshape

Syed Abeed
Updated on 03-Mar-2022 07:19:58

502 Views

numpy.reshape() gives a new shape to an array without changing its data. Its syntax is as follows −numpy.reshape(arr, newshape, order='C')Parametersnumpy.reshape() can accept the following parameters −arr − Input array.shape − endpoint of the sequencenewshape − If an integer, then the result it will be a 1-D array of that length, and one dimension can be -1.order − It defines the order in which the input array elements should be read.If the order is ‘C’, then it reads and writes the elements which are using a C-like index order where the last index changes the fastest and the first axis index ... Read More

Find Circumference of Circular Pond with Radius r in C++

Arnab Chakraborty
Updated on 03-Mar-2022 07:17:43

121 Views

Suppose we have a number R, represents the radius of a pond. We have to find the circumference of this pond.So, if the input is like R = 73, then the output will be 458.67252742410977361942StepsTo solve this, we will follow these steps −res := r * 2 * cos-inverse (-1) return resLet us see the following implementation to get better understandingExampleLet us see the following implementation to get better understanding −#include using namespace std; double solve(int r){    double res = r * 2 * acos(-1);    return res; } int main(){    int R = 73;    cout

Find String After Adding Character to Become Non-Palindrome in C++

Arnab Chakraborty
Updated on 03-Mar-2022 07:17:30

161 Views

Suppose we have a string S with lowercase English letters. We must insert exactly one character 'a' in S. After inserting that if we can make S not a palindrome then return that string, otherwise return "impossible".So, if the input is like S = "bpapb", then the output will be "bpaapb"StepsTo solve this, we will follow these steps −if concatenation of S and "a" is not palindrome, then:    return S concatenation 'a' otherwise when concatenation of "a" + S is not palindrome, then:    return 'a' concatenation S Otherwise    return "Impossible"ExampleLet us see the following implementation to get ... Read More

C++ Program to Convert Kth Character to Lowercase

Arnab Chakraborty
Updated on 03-Mar-2022 07:15:49

216 Views

Suppose we have a string S with N characters. S contains only three types of characters 'A', 'B' or 'C'. We also have another integer K. We have to print S after lowercasing the Kth character in it.So, if the input is like K = 2; S = "AABACC", then the output will be "AaBACC"StepsTo solve this, we will follow these steps −S[K - 1] = S[K - 1] + 32 return SExampleLet us see the following implementation to get better understanding −#include using namespace std; string solve(int K, string S){    S[K - 1] = S[K - ... Read More

NumPy geomspace Function in Python

Syed Abeed
Updated on 03-Mar-2022 07:14:26

555 Views

numpy.geomspace() returns a set of numbers spaced evenly on a log scale (a geometric progression).Linspace − It is similar to geomspace, but endpoints specified using the log and base.Logspace − It is similar to geomspace, but endpoints specified with arithmetic instead of geometric progression.Syntaxnumpy.goemspace(start, stop, num = 50, endpoint = True/False, dtype = None)ParametersThe above function can accept the following parameters −start − Start of the sequence; default is zero.stop − Endpoint of the sequence.num − Number of elements which are generated between the start and stop sequence.endpoint − It controls whether the stop value is included in the output ... Read More

Advertisements