Arnab Chakraborty has Published 4452 Articles

Program to perform string compression in Python

Arnab Chakraborty

Arnab Chakraborty

Updated on 12-Oct-2021 08:40:13

14K+ Views

Suppose we have a string s. We have to compress this string into Run length encoding form. So when a character is repeated k number of times consecutively like 'bbbb' here letter 'b' is repeated four times consecutively, so the encoded form will be 'b4'. For single characters we shall ... Read More

Program to swap string characters pairwise in Python

Arnab Chakraborty

Arnab Chakraborty

Updated on 12-Oct-2021 08:36:40

14K+ Views

Suppose we have a string s. We have to swap all odd positioned elements with the even positioned elements. So finally we shall get a permutation of s where elements are pairwise swapped.So, if the input is like s = "programming", then the output will be "rpgoarmmnig"To solve this, we ... Read More

Python program to print number triangle

Arnab Chakraborty

Arnab Chakraborty

Updated on 12-Oct-2021 08:23:05

898 Views

Suppose we have a number n. We have to print a triangle with n rows and each line will hold line number i, i number of times.So, if the input is like n = 5, then the output will be1 22 333 4444 55555To solve this, we will follow these ... Read More

Python program to find probability of getting letter 'a' in some letters and k sized combinations

Arnab Chakraborty

Arnab Chakraborty

Updated on 12-Oct-2021 08:20:52

352 Views

Suppose we have an array with n different English letters. We also have another value k. We can select k different indices (1-indexed) with uniform distribution. We have to find the probability that at least one of the k indices selected will contain the letter 'a'.So, if the input is ... Read More

Python program to print palindrome triangle with n lines

Arnab Chakraborty

Arnab Chakraborty

Updated on 12-Oct-2021 08:16:08

3K+ Views

Suppose we have a number n. We have to find a triangle with n rows and each row contains palindrome.So, if the input is like n = 5, then the output will be1 121 12321 1234321 123454321To solve this, we will follow these steps −for i in range 1 to ... Read More

Program to find nth Fibonacci term in Python

Arnab Chakraborty

Arnab Chakraborty

Updated on 12-Oct-2021 08:14:32

5K+ Views

Suppose we have a number n. We have to find the nth Fibonacci term by defining a recursive function.So, if the input is like n = 8, then the output will be 13 as first few Fibonacci terms are 0, 1, 1, 2, 3, 5, 8, 13, 21, 34...To solve ... Read More

Python program to check whether we can pile up cubes or not

Arnab Chakraborty

Arnab Chakraborty

Updated on 12-Oct-2021 08:14:01

216 Views

Suppose we have an array nums containing size of n different cubes, they are placed horizontally. We have to make a pile of cubes vertically. The new cube should follow −if ith cube is on top of jth cube, then side length of jth one must be greater or equal ... Read More

Program to compute gcd of two numbers recursively in Python

Arnab Chakraborty

Arnab Chakraborty

Updated on 12-Oct-2021 08:11:17

6K+ Views

Suppose we have two numbers a and b. We have to find the GCD of these two numbers in recursive way. To get the GCD we shall use the Euclidean algorithm.So, if the input is like a = 25 b = 45, then the output will be 5To solve this, ... Read More

Python program to find top three mostly occurred letters from company name

Arnab Chakraborty

Arnab Chakraborty

Updated on 12-Oct-2021 08:09:00

410 Views

Suppose we have a company name as string. We have to find the most common three characters from the company name and show them by following these rules −Pick most frequent three lettersSort them in descending orderIf the frequencies of some characters are same then take by their alphabetical orderSo, ... Read More

Program to find area of a polygon in Python

Arnab Chakraborty

Arnab Chakraborty

Updated on 12-Oct-2021 08:07:29

2K+ Views

Suppose we have a list of ordered points represents a simple polygon endpoint on a 2D plane. We have to find the area of this polygon.So, if the input is like points = [(0, 0), (0, 5), (3, 5), (3, 0)], then the output will be 15.To solve this, we ... Read More

Advertisements