Arnab Chakraborty

Arnab Chakraborty

3,768 Articles Published

Articles by Arnab Chakraborty

Page 275 of 377

Program to find number of ways we can merge two lists such that ordering does not change in Python

Arnab Chakraborty
Arnab Chakraborty
Updated on 25-Oct-2021 253 Views

Suppose we have two lists nums1 and nums2. Now the constraint is when we merge the order of elements in each list does not change, for example, if the elements are [1, 2, 3] and [4, 5, 6], then some valid merged lists are [1, 4, 2, 3, 5, 6] and [1, 2, 3, 4, 5, 6], there may be some other valid merge sequence. So if we have the size of lists N and M. We have to find number of ways we can merge them to get valid list. If the answer is too large the return result ...

Read More

Program to find list of all possible combinations of letters of a given string s in Python

Arnab Chakraborty
Arnab Chakraborty
Updated on 25-Oct-2021 7K+ Views

Suppose we have a string s. We have to find all possible combinations of letters of s. If there are two strings with same set of characters, then show the lexicographically smallest of them. And one constraint is each character in s are unique.So, if the input is like s = "pqr", then the output will be ['r', 'qr', 'q', 'pr', 'pqr', 'pq', 'p']To solve this, we will follow these steps −st_arr := a new listfor i in range size of s - 1 to 0, decrease by 1, dofor j in range 0 to size of st_arr - 1, ...

Read More

Program to find nCr values for r in range 0 to n, in an efficient way in Python

Arnab Chakraborty
Arnab Chakraborty
Updated on 23-Oct-2021 647 Views

Suppose we have to calculate nCr values many times. We can solve this very efficient way. If we store the lower values of nCr we can easily find higher values. So if we have n, we have to find list of nC0 to nCn. If answer is too large then return that modulo 10^9.So, if the input is like n = 6, then the output will be [1, 6, 15, 20, 15, 6, 1].To solve this, we will follow these steps −items := a list with single element 1for r in range 1 to n, doinsert floor of (last element ...

Read More

Program to find total area covered by two rectangles in Python

Arnab Chakraborty
Arnab Chakraborty
Updated on 23-Oct-2021 407 Views

Suppose we want to find the total area covered by two rectilinear rectangles in a 2D plane. Here each rectangle is defined by its bottom left corner and top right corner as shown in the figure.To solve this, we will follow these steps −width_1 := |C-A|, height_1 := |D-B|width_2 := |G-E|, height_2 := |H-F|area := width_1*height_1 + width_2*height_2if (GC) or (F>D) or (HD) or (H

Read More

Program to find maximum size of any sequence of given array where every pair is nice in Python

Arnab Chakraborty
Arnab Chakraborty
Updated on 23-Oct-2021 298 Views

Suppose we have a sequence nums of size n. We have to find the maximum size of subsequence of nums in which every pair (p, q) is a nice pair? A pait is said to be nice pair if and only if it holds at least one of these conditions: 1. The parity of the number of distinct prime divisors of p is equal to that of b. For example, the value 18 has two distinct prime divisors: 2 and 3. 2. The parity of the sum of all positive divisors of p is same as q.So, if the input ...

Read More

Program to find modulus of a number by concatenating n times in Python

Arnab Chakraborty
Arnab Chakraborty
Updated on 23-Oct-2021 252 Views

Suppose we have a number A. We have to generate a large number X by concatenating A, n times in a row and find the value of X modulo m.So, if the input is like A = 15 n = 3 m = 8, then the output will be 3, because the number x will be 151515, and 151515 mod 8 = 3.To solve this, we will follow these steps −if A is same as 0, thenreturn 0an:= Ac:= number of digits in Ac:= 10^cd:= c-1newmod := d*mval := (c ^ n mod newmod) -1val :=(val + newmod) mod newmodan ...

Read More

Program to find number of ways we can select sequence from Ajob Sequence in Python

Arnab Chakraborty
Arnab Chakraborty
Updated on 23-Oct-2021 267 Views

Suppose there is a strange language called Ajob language. It has infinite number of letters. We know n words in this language. The first word is one character long, second one is two character long and so on. And all letters in a word are unique. If we select any one of the n words and form a subsequence from it. The length of the subsequence should be k less than the length of original word. For an example, if the length of the chosen word is say L, then the length of the subsequence should be (L - k). ...

Read More

Program to find number of pairs between x, whose multiplication is x and they are coprime in Python

Arnab Chakraborty
Arnab Chakraborty
Updated on 23-Oct-2021 229 Views

Suppose there is a function f(x), that counts number of (p, q) pairs, such that1 < p

Read More

Program to find out the position of a ball after n reversals in Python

Arnab Chakraborty
Arnab Chakraborty
Updated on 23-Oct-2021 301 Views

Suppose, there are n number of balls. The balls are ordered in a fashion 1, 2, 3, 4, ..., n. Now the balls are reversed in order, or ordered in a way n, n-1, n-2, ......, 2, 1. The balls are again reversed in order, this time they are reversed from position 1 to n, or now the order becomes n, 1, 2, ....., n-1. This reversing process is repeated n times and each time the starting position is moved 1 place to the right. We now have to find out the position of a ball initially in position 'index' ...

Read More

Program to reset a polygon to its initial state in Python

Arnab Chakraborty
Arnab Chakraborty
Updated on 23-Oct-2021 252 Views

Suppose, there is a polygon with n vertices, n flipping axis, and n rotation points. The following are true for the flipping axes and rotation pointsIf n is odd, each flipping axis passes through only one vertex and the middle of the opposite side.If n is even, half of the axes pass through a pair of opposite vertex and the other half passes through a pair of opposite sides.Two following axes have an angle of 360/2n.Now, we rotate the polygon provided. We have n different types of rotators, a k-rotator rotates the polygon at axis k clockwise by (360 x ...

Read More
Showing 2741–2750 of 3,768 articles
« Prev 1 273 274 275 276 277 377 Next »
Advertisements