Arnab Chakraborty

Arnab Chakraborty

3,768 Articles Published

Articles by Arnab Chakraborty

Page 61 of 377

Program to check we can make arithmetic progression from sequence in Python

Arnab Chakraborty
Arnab Chakraborty
Updated on 25-Mar-2026 2K+ Views

Suppose we have a list of numbers. We need to check whether these numbers can form an Arithmetic Progression (AP) when arranged in proper order. In an AP series, the common difference between any two consecutive elements is the same. So, if the input is like nums = [9, 1, 17, 5, 13], then the output will be True because if we sort them, it will be [1, 5, 9, 13, 17] and here common difference is 4 for each pair of elements. Algorithm To solve this, we will follow these steps: ...

Read More

Program to find average salary excluding the minimum and maximum salary in Python

Arnab Chakraborty
Arnab Chakraborty
Updated on 25-Mar-2026 2K+ Views

Suppose we have an array with distinct elements called salary where salary[i] is the salary of ith employee. We have to find the average salary of employees excluding the minimum and maximum salary. So, if the input is like salary = [8000, 6000, 2000, 8500, 2500, 4000], then the output will be 5125.0, as the minimum and maximum salary values are 2000 and 8500. Excluding them, the remaining salary values are [8000, 6000, 2500, 4000], so the average is (8000 + 6000 + 2500 + 4000)/4 = 5125. Algorithm To solve this problem, we will follow these ...

Read More

Program to perform XOR operation in an array using Python

Arnab Chakraborty
Arnab Chakraborty
Updated on 25-Mar-2026 917 Views

Suppose we have an integer n and another integer start. We need to create an array called nums where nums[i] = start + 2*i (where i starts from 0) and n is the size of nums. Then find the bitwise XOR of all elements of nums. So, if the input is like n = 6, start = 2, then the output will be 14 because the array will be like [2+2*0, 2+2*1, ... 2+2*5] = [2, 4, 6, 8, 10, 12], then XOR of each element present in the array is 14. Understanding the Problem Let's first ...

Read More

Program to find running sum of 1d array in Python

Arnab Chakraborty
Arnab Chakraborty
Updated on 25-Mar-2026 4K+ Views

A running sum array calculates the cumulative sum at each position. For a given array, the running sum at index i equals the sum of all elements from index 0 to i. For example, if nums = [8, 3, 6, 2, 1, 4, 5], then the running sum will be [8, 11, 17, 19, 20, 24, 29] because: rs[0] = nums[0] = 8 rs[1] = sum of nums[0..1] = 8 + 3 = 11 rs[2] = sum of nums[0..2] = 8 + 3 + 6 = 17 and so on Method 1: Using ...

Read More

Program to find Final Prices With a Special Discount in a Shop in Python

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

Given an array of prices, we need to find the final prices after applying a special discount. For each item at index i, we get a discount equal to the price of the first item at index j where j > i and prices[j] ≤ prices[i]. Problem Understanding The discount rule works as follows ? For item at index i, look for the first item at index j where j > i If prices[j] ≤ prices[i], then discount = prices[j] Final price = prices[i] − prices[j] If no such j exists, no discount is applied ...

Read More

Program to delete n nodes after m nodes from a linked list in Python

Arnab Chakraborty
Arnab Chakraborty
Updated on 25-Mar-2026 361 Views

Suppose we are given a linked list that has the start node as "head", and two integer numbers m and n. We have to traverse the list and delete some nodes such that the first m nodes are kept in the list and the next n nodes after the first m nodes are deleted. We perform this until we encounter the end of the linked list. We start from the head node, and the modified linked list is to be returned. The linked list structure is given to us as ? Node value ...

Read More

Check if Queue Elements are pairwise consecutive in Python

Arnab Chakraborty
Arnab Chakraborty
Updated on 25-Mar-2026 300 Views

A queue contains numbers and we need to check if consecutive pairs of elements are pairwise consecutive (differ by exactly 1). This means we group elements in pairs and verify each pair has consecutive numbers. So, if the input is like que = [3, 4, 6, 7, 8, 9], then the output will be True because pairs (3, 4), (6, 7), and (8, 9) are all consecutive. Algorithm To solve this, we will follow these steps − Create a queue and insert all elements from the given list Extract all elements from queue into a ...

Read More

Check if product of first N natural numbers is divisible by their sum in Python

Arnab Chakraborty
Arnab Chakraborty
Updated on 25-Mar-2026 276 Views

Suppose we have a number n. We have to check whether the product of (1*2*...*n) is divisible by (1+2+...+n) or not. So, if the input is like num = 5, then the output will be True as (1*2*3*4*5) = 120 and (1+2+3+4+5) = 15, and 120 is divisible by 15. Mathematical Approach Instead of calculating the actual product and sum, we can use a mathematical property. The product of first n natural numbers is n! (factorial), and the sum is n*(n+1)/2. The key insight is: If num + 1 is prime, then the factorial is ...

Read More

Check if product of digits of a number at even and odd places is equal in Python

Arnab Chakraborty
Arnab Chakraborty
Updated on 25-Mar-2026 371 Views

In this problem, we need to check whether the product of digits at odd positions equals the product of digits at even positions in a number. The positions are counted from right to left, starting with position 1. For example, in the number 2364: Odd positions (1st, 3rd): 4, 6 → Product = 4 × 6 = 24 Even positions (2nd, 4th): 3, 2 → Product = 3 × 2 = 6 Let's correct this with a proper example where products are equal ? Algorithm To solve this, we will follow these steps − ...

Read More

Check if product of array containing prime numbers is a perfect square in Python

Arnab Chakraborty
Arnab Chakraborty
Updated on 25-Mar-2026 242 Views

Suppose we have an array nums with all prime numbers. We have to check whether the product of all numbers present in nums is a perfect square or not. A perfect square is formed when every prime factor appears an even number of times. Since our array contains only prime numbers, we need to count the frequency of each prime and ensure all frequencies are even. So, if the input is like nums = [3, 3, 7, 7], then the output will be True as product of all elements in nums is 441 which is a perfect square ...

Read More
Showing 601–610 of 3,768 articles
« Prev 1 59 60 61 62 63 377 Next »
Advertisements