Arnab Chakraborty

Arnab Chakraborty

3,768 Articles Published

Articles by Arnab Chakraborty

Page 17 of 377

Array sum after dividing numbers from previous?

Arnab Chakraborty
Arnab Chakraborty
Updated on 15-Mar-2026 158 Views

Here we will see one interesting problem. We will take one array, then find the sum by taking each element after dividing it by the previous elements. Let us consider an array is {5, 6, 7, 2, 1, 4}. Then the result will be 5 + (6 / 5) + (7 / 6) + (2 / 7) + (1 / 2) + (4 / 1) = 12.15238. Syntax float divSum(int arr[], int n); Algorithm divSum(arr, n) begin sum := arr[0] for i := 1 to ...

Read More

Array elements with prime frequencies?

Arnab Chakraborty
Arnab Chakraborty
Updated on 15-Mar-2026 511 Views

In this problem, we need to count how many distinct elements in an array appear a prime number of times. For example, if the array is {1, 2, 2, 0, 1, 5, 2, 5, 0, 0, 1, 1}, then 1 appears 4 times (not prime), 2 appears 3 times (prime), 0 appears 3 times (prime), and 5 appears 2 times (prime). So there are three elements {2, 0, 5} with prime frequencies, giving us a count of 3. Syntax int countPrimeOccurrence(int arr[], int n); bool isPrime(int n); Algorithm countPrimeOccurrence(arr, n) Begin ...

Read More

Array elements that appear more than once?

Arnab Chakraborty
Arnab Chakraborty
Updated on 15-Mar-2026 389 Views

In C programming, finding array elements that appear more than once is a common problem. Given an array, we need to identify which elements have a frequency greater than 1. For example, in the array {1, 5, 2, 5, 3, 1, 5, 2, 7}, elements 1, 2, and 5 appear multiple times, so they should be included in our result. Syntax void findDuplicates(int arr[], int n); Algorithm Begin Create frequency array to count occurrences For each element in array: Increment its ...

Read More

Array element with minimum sum of absolute differences?

Arnab Chakraborty
Arnab Chakraborty
Updated on 15-Mar-2026 451 Views

In C programming, finding the array element with minimum sum of absolute differences is a classic optimization problem. Given an array of N elements, we need to find a value x that minimizes the sum |a[0] - x| + |a[1] - x| + ... + |a[n-1] - x|. For example, with array {1, 3, 9, 6, 3}, the optimal x is 3, giving us a sum of |1 - 3| + |3 - 3| + |9 - 3| + |6 - 3| + |3 - 3| = 11. The key insight is that the median of the array ...

Read More

Array element moved by k using single moves?

Arnab Chakraborty
Arnab Chakraborty
Updated on 15-Mar-2026 151 Views

This problem involves simulating a badminton tournament where players compete until someone wins K consecutive matches. We have an array representing the queue of players, and we need to find who becomes the ultimate winner. Syntax int winner(int arr[], int n, int k); Algorithm The key insight is that we don't need to simulate every match. Instead, we can observe that − If K >= n-1, the largest element will always win Otherwise, we track the best player encountered and count consecutive wins Begin if k ...

Read More

Arrangement of words without changing the relative position of vowel and consonants?

Arnab Chakraborty
Arnab Chakraborty
Updated on 15-Mar-2026 210 Views

In this problem, we need to find the number of ways to arrange letters in a string while maintaining the relative positions of vowels and consonants. This means vowels stay in vowel positions and consonants stay in consonant positions. The approach involves counting vowels and consonants separately, calculating permutations for each group considering duplicate letters, then multiplying the results. Syntax long long arrangeWayCount(char str[]); Algorithm arrangeWayCount(str) Begin define an array 'freq' to store frequency. count and place frequency of each characters in freq array. such ...

Read More

Arrange first N natural numbers such that absolute difference between all adjacent elements > 1?

Arnab Chakraborty
Arnab Chakraborty
Updated on 15-Mar-2026 458 Views

We need to arrange the first N natural numbers such that the absolute difference between every two consecutive elements is greater than 1. If no such permutation exists, we return -1. The approach uses a greedy strategy − arrange all odd numbers in descending order, followed by all even numbers in descending order. This ensures adjacent elements always differ by at least 2. Syntax void arrangeN(int N); Algorithm Begin if N is 1, then return 1 if N is 2 or 3, then return -1 as no such ...

Read More

Area of Reuleaux Triangle?

Arnab Chakraborty
Arnab Chakraborty
Updated on 15-Mar-2026 587 Views

A Reuleaux Triangle is a special geometric shape formed by the intersection of three circles. It is constructed using an equilateral triangle as a base, where each side of the triangle becomes the radius of a circle centered at the opposite vertex. The area calculation involves three circular sectors minus the overlapping equilateral triangle areas. ...

Read More

Area of a n-sided regular polygon with given Radius?

Arnab Chakraborty
Arnab Chakraborty
Updated on 15-Mar-2026 317 Views

Here we will see how to get the area of an n-sided regular polygon whose radius is given. Here the radius is the distance from the center to any vertex. To solve this problem, we draw a perpendicular from the center to one side. Let each side have length 'a'. The perpendicular divides the side into two equal parts, each of length a/2. The perpendicular and the radius form an angle x, and let the radius length be r. ...

Read More

Area of a leaf inside a square?

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

Here we will see how to calculate the area of a leaf-shaped region inside a square ABCD, where each side of the square has length 'a'. A B C D Center a The leaf consists of two equal circular segments. Each segment is formed by the intersection of ...

Read More
Showing 161–170 of 3,768 articles
« Prev 1 15 16 17 18 19 377 Next »
Advertisements