Arnab Chakraborty

Arnab Chakraborty

3,768 Articles Published

Articles by Arnab Chakraborty

Page 24 of 377

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

Arnab Chakraborty
Arnab Chakraborty
Updated on 26-Mar-2026 513 Views

Suppose we have an array with n different English letters and a value k. We can select k different indices with uniform distribution and need to find the probability that at least one of the k indices selected will contain the letter 'a'. For example, if we have letters = ['a', 'c', 'a', 'b', 'l', 'a', 'b', 'z'] and k = 2, we need to find all possible combinations of 2 letters and count how many contain at least one 'a'. Algorithm To solve this problem, we follow these steps − Initialize ...

Read More

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

Arnab Chakraborty
Arnab Chakraborty
Updated on 26-Mar-2026 374 Views

Suppose we have an array nums containing sizes of n different cubes placed horizontally. We need to make a vertical pile of cubes following this rule: If the ith cube is on top of the jth cube, then the side length of the jth cube must be greater than or equal to the side length of the ith cube. When making the vertical pile, we can only take cubes from the left side or right side, but not from the middle. We need to check whether we can pile them up successfully or not. Problem ...

Read More

Program to compute gcd of two numbers recursively in Python

Arnab Chakraborty
Arnab Chakraborty
Updated on 26-Mar-2026 8K+ Views

Finding the Greatest Common Divisor (GCD) of two numbers is a fundamental mathematical operation. The Euclidean algorithm provides an efficient recursive approach by repeatedly applying the principle that GCD(a, b) = GCD(b, a mod b). So, if the input is like a = 25, b = 45, then the output will be 5. Algorithm Steps To solve this recursively, we will follow these steps − Define a function gcd(). This will take a, b if a is same as b, then ...

Read More

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

Arnab Chakraborty
Arnab Chakraborty
Updated on 26-Mar-2026 656 Views

Sometimes we need to find the most frequently occurring characters in a company name. This program identifies the top three most common letters and displays them with their frequencies following specific sorting rules. Problem Requirements Given a company name as a string, we need to find the three most common characters by following these rules ? Pick the most frequent three letters Sort them in descending order by frequency If frequencies are equal, sort alphabetically For example, if the input is s = "TUTORIALSPOINT", the output should be [[3, 'T'], [2, 'I'], [2, 'O']]. ...

Read More

Program to find area of a polygon in Python

Arnab Chakraborty
Arnab Chakraborty
Updated on 26-Mar-2026 3K+ Views

Suppose we have a list of ordered points that represents a simple polygon on a 2D plane. We need to find the area of this polygon using the Shoelace formula (also known as the surveyor's formula). So, if the input is like points = [(0, 0), (0, 5), (3, 5), (3, 0)], then the output will be 15. ...

Read More

Python program to count pairs for consecutive elements

Arnab Chakraborty
Arnab Chakraborty
Updated on 26-Mar-2026 644 Views

When working with numeric strings, you often need to count how many times each digit appears consecutively. Python's itertools.groupby() function is perfect for this task as it groups consecutive identical elements together. For example, if the input is s = "11522226551", the output should be [(1, 2), (5, 1), (2, 4), (6, 1), (5, 2), (1, 1)] because digit 1 appears twice consecutively at the beginning, then single 5, then four 2s, and so on. Algorithm To solve this problem, we will follow these steps ? Use groupby() function to group consecutive identical digits Create ...

Read More

Python program to count distinct words and count frequency of them

Arnab Chakraborty
Arnab Chakraborty
Updated on 26-Mar-2026 934 Views

When working with text data, we often need to count how many distinct words appear and track their frequencies. Python provides several approaches to solve this problem efficiently. In this example, we have a list of words where some words may appear multiple times. We need to return the count of distinct words and their frequencies in order of first appearance. Problem Example Given the input: words = ["Book", "Sound", "Language", "Computer", "Book", "Language"] The expected output is (4, '2 1 2 1') because: There are 4 distinct words ...

Read More

Program to check whether domain and range are forming function or not in Python

Arnab Chakraborty
Arnab Chakraborty
Updated on 26-Mar-2026 549 Views

Suppose we have a list of data x that represents a domain and a list of data y (same size as x) that represents a range. We need to check whether the mapping x → y forms a valid function. In mathematics, a function is a relation where each input (domain element) maps to exactly one output (range element). So, if the input is like x = [1, 3, 2, 6, 5] y = [1, 9, 4, 36, 25], then the output will be True, because each element in x maps to exactly one corresponding element in y (in ...

Read More

Python program to find happiness by checking participation of elements into sets

Arnab Chakraborty
Arnab Chakraborty
Updated on 26-Mar-2026 410 Views

Suppose we have an array nums with n different integers. We also have two disjoint sets A and B. We have one happiness parameter which is set to 0 initially. We go through each integer i in nums. If i is in A then add happiness by 1 and if i is in B decrease it by 1. We have to finally find the final happiness value. So, if the input is like nums = [1, 2, 5, 8, 6, 3], A = {5, 8, 9, 7, 3}, B = {2, 4, 12, 15}, then the output will be ...

Read More

Program to find ex in an efficient way in Python

Arnab Chakraborty
Arnab Chakraborty
Updated on 26-Mar-2026 166 Views

The mathematical constant e raised to the power x (ex) can be calculated efficiently using the Taylor series expansion without library functions. The formula for ex is: ex = 1 + x + x²/2! + x³/3! + x⁴/4! + ... For example, if x = 5, then e5 ≈ 148.4131 because e5 = 1 + 5 + (5²/2!) + (5³/3!) + ... = 148.4131... Algorithm To solve this efficiently, we follow these steps ? Initialize factorial = 1, result = 1, and numerator = x Set n = 20 (number of terms for precision) ...

Read More
Showing 231–240 of 3,768 articles
« Prev 1 22 23 24 25 26 377 Next »
Advertisements