Article Categories
- All Categories
-
Data Structure
-
Networking
-
RDBMS
-
Operating System
-
Java
-
MS Excel
-
iOS
-
HTML
-
CSS
-
Android
-
Python
-
C Programming
-
C++
-
C#
-
MongoDB
-
MySQL
-
Javascript
-
PHP
-
Economics & Finance
Articles by Arnab Chakraborty
Page 17 of 377
Array sum after dividing numbers from previous?
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 MoreArray elements with prime frequencies?
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 MoreArray elements that appear more than once?
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 MoreArray element with minimum sum of absolute differences?
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 MoreArray element moved by k using single moves?
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 MoreArrangement of words without changing the relative position of vowel and consonants?
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 MoreArrange first N natural numbers such that absolute difference between all adjacent elements > 1?
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 MoreArea of Reuleaux Triangle?
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 MoreArea of a n-sided regular polygon with given Radius?
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 MoreArea of a leaf inside a square?
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