Articles on Trending Technologies

Technical articles with clear explanations and examples

Remove Every K-th Node Of The Linked List

Prateek Jangid
Prateek Jangid
Updated on 26-Nov-2021 631 Views

In this article, we will explain the way to remove every k-th node of the linked list. We must delete every node that sits on the multiple of k, i.e., we have to delete the node on positions k, 2*k, 3*k, etc.Input : 112->231->31->41->54->63->71->85    k = 3 Output : 112->231->41->54->71->85 Explanation: As 3 is the k-th node after its deletion list would be : First iteration :112->231->41->54->63->71->85 Now we count from 41 the next kth node is 63 After the second iteration our list will become : 112->231->41->54->71->85 And our iteration continues like this. Input: 14->21->23->54->56->61    k ...

Read More

Rearrange an Array to Maximize i*arr[i] using C++

Prateek Jangid
Prateek Jangid
Updated on 26-Nov-2021 1K+ Views

In this article, we will discuss the problem of rearranging a given array of n numbers. Basically, we have to select elements from the array. For selecting each element, we get some points that will be evaluated by the value of the current element * a number of elements selected before the current element. You should select elements to get maximum points. For Example −Input : arr[ ] = { 3, 1, 5, 6, 3 } If we select the elements in the way it is given, our points will be    = 3 * 0 + 1 * ...

Read More

Rearrange An Array In Order – Smallest, Largest, 2nd Smallest, 2nd Largest,. Using C++

Prateek Jangid
Prateek Jangid
Updated on 26-Nov-2021 888 Views

We are given an array; we need to arrange this array in an order that the first element should be a minimum element, the second element should be a maximum element, the third element should be 2nd minimum element, the fourth element should be the 2nd maximum element and so on for example −Input : arr[ ] = { 13, 34, 30, 56, 78, 3 } Output : { 3, 78, 13, 56, 34, 30 } Explanation : array is rearranged in the order { 1st min, 1st max, 2nd min, 2nd max, 3rd min, 3rd max } Input ...

Read More

Rearrange an Array in Maximum Minimum Form using C++

Prateek Jangid
Prateek Jangid
Updated on 26-Nov-2021 396 Views

We are given a sorted array. We need to arrange this array in maximum, minimum form, i.e., the first element is the maximum element, the second element is the minimum element, the third element is 2nd maximum element, the fourth element is 2nd minimum element, and so on, for example −Input : arr[ ] = { 10, 20, 30, 40, 50, 60 } Output : { 60, 10, 50, 20, 40, 30 } Explanation : array is rearranged in the form { 1st max, 1st min, 2nd max, 2nd min, 3rd max, 3rd min } Input : arr [ ...

Read More

Rank of All Elements in an Array using C++

Prateek Jangid
Prateek Jangid
Updated on 26-Nov-2021 1K+ Views

In the given problem, we need to rank all the given elements of an array, with the smallest number having the smallest rank and the largest having the largest rank. We also need to change the ranks of a number depending on their frequencies, for examples −Input : 20 30 10 Output : 2.0 3.0 1.0 Input : 10 12 15 12 10 25 12 Output : 1.5, 4.0, 6.0, 4.0, 1.5, 7.0, 4.0 Here the rank of 10 is 1.5 because there are two 10s present in the given array now if we assume they both take ...

Read More

Range Sum Queries Without Updates using C++

Prateek Jangid
Prateek Jangid
Updated on 26-Nov-2021 510 Views

In this article, we will give an array of size n, which will be an integer. Then, we will compute the sum of elements from index L to index R and execute the queries multiple times, or we need to calculate the sum of the given range from [L, R]. For example −Input : arr[] = {1, 2, 3, 4, 5}    L = 1, R = 3    L = 2, R = 4 Output : 9    12 Input : arr[] = {1, 2, 3, 4, 5}    L = 0, R = 4    L = ...

Read More

Queries to Print All the Divisors of n using C++

Prateek Jangid
Prateek Jangid
Updated on 26-Nov-2021 605 Views

In the given problem, we are required to print all the divisors of a given integer n.Input: 15 Output: 1 3 5 15 Explanation Divisors of 15 are: 1, 3, 5, 15 Input: 30 Output: 1 2 3 5 15 30In the given problem, we can apply the approach used in the sieve of Eratosthenes for finding all the divisors of n.Approach to find The SolutionIn the given approach, we will apply the concept in which the sieve of Eratosthenes is based and find the divisors of n.Example#include #define MOD 1000000007 using namespace std; vector divisors[100001]; ...

Read More

Queries for number of array elements in a range with Kth Bit Set using C++

Prateek Jangid
Prateek Jangid
Updated on 26-Nov-2021 400 Views

In this article we will discuss a problem of finding the number of elements present in the given range that have a kth bit set, for example −Input : arr[] = { 4, 5, 7, 2 } Query 1: L = 2, R = 4, K = 4 Query 2: L = 3, R = 5, K = 1 Output :    0    1We are going to solve this problem by a brute force approach and see if this approach can work for higher constraints or not. If not, then we try to think of a new efficient approach.Brute ...

Read More

Queries for greater than and not less than using C++

Prateek Jangid
Prateek Jangid
Updated on 26-Nov-2021 561 Views

In this article, we are given a problem, we are given an array, and there are two types of queries we need to answer.Type 0 − we have to calculate the number of greater elements than or equal to x(given value).Type 1 − we have to calculate the number of strictly greater elements than x(given value).So here is a simple example −Input : arr[] = { 10, 15, 30 , 40, 45 } and Q = 3    Query 1: 0 50    Query 2: 1 40    Query 3: 0 30 Output :    0    1    3 ...

Read More

Queries for bitwise AND in the index range [L, R] of the given Array using C++

Prateek Jangid
Prateek Jangid
Updated on 26-Nov-2021 1K+ Views

In this article, we have given a problem in which we are given an array of integers, and we are tasked to find the bitwise AND of the given ranges, for example 7minus;Input: arr[ ] = {1, 3, 1, 2, 32, 3, 3, 4, 4}, q[ ] = {{0, 1}, {3, 5}} Output: 1 0 0 1 AND 31 = 1 23 AND 34 AND 4 = 00 Input: arr[ ] = {1, 2, 3, 4, 510, 10 , 12, 16, 8}, q[ ] = {{0, 42}, {1, 33, 4}} Output: 0 8 0We are going to apply the brute ...

Read More
Showing 46871–46880 of 61,297 articles
Advertisements