Articles on Trending Technologies

Technical articles with clear explanations and examples

Program to find maximum distance between empty and occupied seats in Python

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

Suppose we have a list with only 0s and 1s called seats, where seats[i] represents a seat. When it is 1, the seat is occupied; otherwise, it's free. Given that there is at least one free seat and at least one occupied seat, we need to find the maximum distance from a free seat to the nearest occupied seat. For example, if the input is seats = [1, 0, 1, 0, 0, 0, 1], the output will be 2, because we can occupy seat seats[4], and the distance to the nearest occupied seat is 2. Algorithm Approach ...

Read More

Program to count number of BST with n nodes in Python

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

Suppose we have n different nodes, all distinct. We need to find how many ways we can arrange them to form a Binary Search Tree (BST). In a BST, the left subtree always holds smaller values and the right subtree holds greater values. To solve this problem, we use Catalan numbers. The Catalan number C(n) represents the number of structurally different binary search trees with n different keys. Catalan Number Formula The formula for the nth Catalan number is: C(n) = (2n)! / ((n+1)! × n!) Alternatively, it can be calculated as: C(n) = ...

Read More

Program to filter all values which are greater than x in an array

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

Filtering arrays based on a condition is a common task in Python programming. The filter() function provides an efficient way to extract elements that meet specific criteria. In this example, we'll filter numbers that are less than a given threshold value. Problem Statement Given a list of numbers and a threshold value x, we need to find all numbers that are less than x using Python's filter() function. For example, if nums = [1, 5, 8, 3, 6, 9, 12, 77, 55, 36, 2, 5, 6, 12, 87] and x = 50, the output should be [1, ...

Read More

Program to find replicated list by replicating each element n times

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

Suppose we have a list of n elements; we have to repeat each element in the list n number of times. So, if the input is like nums = [1, 5, 8, 3], then the output will be [1, 1, 1, 1, 5, 5, 5, 5, 8, 8, 8, 8, 3, 3, 3, 3] To solve this, we will follow these steps − n := size of nums ret := a new list for each num in nums, do ...

Read More

Program to find super digit of a number in Python

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

Suppose we have a number n. We have to find the super digit of this number. The super digit of a single digit number is the digit itself, but for multi-digit numbers, super digit is the sum of all digits repeatedly until the sum is a single digit number. So, if the input is like n = 513682, then the output will be 7 because (5+1+3+6+8+2) = 25, (2 + 5) = 7. Algorithm To solve this, we will follow these steps − s := 0 while ...

Read More

Program to find number of values factors of two set of numbers

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

Suppose we have two arrays called nums1 and nums2. We have to find the number of values that satisfy the following conditions: The elements in nums1 are the factors of the elements which are being selected The elements which are selected are factors of all elements of nums2 So, if the input is like nums1 = [3, 9] and nums2 = [27, 81], then the output will be 2 because the numbers are 9 and 27. Algorithm To solve this, we will follow these steps: ...

Read More

Program to check points are forming convex hull or not in Python

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

Suppose we have outer points of a polygon in clockwise order. We have to check these points are forming a convex hull or not. ...

Read More

Program to find ith element by rotating k times to right

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

Suppose we have an array nums, and a value k and another value i. We have to find the element at index i after rotating elements of nums, k number of times to the right. So, if the input is like nums = [2, 7, 9, 8, 10] k = 3 i = 2, then the output will be 10 because after 3rd rotation array will be [9, 8, 10, 2, 7], so now the ith element will be nums[2] = 10. Method 1: Using pop() and insert() We can simulate the rotation by moving the last ...

Read More

Program to count number of common divisors of two numbers in Python

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

When working with two numbers, we often need to find how many positive integers divide both numbers evenly. These are called common divisors. A key insight is that all common divisors of two numbers are also divisors of their GCD (Greatest Common Divisor). So, if the input is like a = 288 and b = 240, then the output will be 10 because the common divisors are [1, 2, 3, 4, 6, 8, 12, 16, 24, 48]. Algorithm To solve this problem, we follow these steps ? Find the GCD of ...

Read More

Python program to validate postal address format

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

Postal address validation is important for ensuring data integrity in applications. A valid postal code must meet specific criteria including proper length, numeric format, and digit pattern restrictions. Validation Criteria A valid postal code must satisfy the following conditions ? It must be exactly 6 digits long It must be a number in the range from 100000 to 999999 (cannot start with 0) It must not contain more than one alternating repetitive digit pair (digits at positions i and i+2 should not be the same more than once) Example Let's implement a function ...

Read More
Showing 3111–3120 of 61,299 articles
« Prev 1 310 311 312 313 314 6130 Next »
Advertisements