C++ Articles

Page 42 of 597

Count of Numbers in a Range divisible by m and having digit d in even positions in C++

Sunidhi Bansal
Sunidhi Bansal
Updated on 11-Mar-2026 274 Views

We are given with an integer range, a variable m which is used as divisor and a variable d which is used to check whether the digit 'd' is at even position or not and the task is to calculate the count of those numbers in a range which are divisible by the variable m and have digit d in even positions.For ExampleInput - int start = 20, end = 50, d = 8 and m = 4Output - Count of Numbers in a Range divisible by m and having digit d in even positions are: 2Explanation - The range ...

Read More

Count of cyclic permutations having XOR with other binary string as 0 in C++

Sunidhi Bansal
Sunidhi Bansal
Updated on 11-Mar-2026 721 Views

We are given with two binary strings let's say str_1 and str_2 containing the combination of 1's and 0's and the task is to firstly form the set let's say “SET” of different permutations possible from the string str_1 and then we will perform XOR operations of the elements in set with the binary string str_2 and then check whether the XOR is returning 0 or not. If yes, then consider the case else ignore it.Let us understand with examples.For ExampleInput -  string str_1 = "1111", string str_2 = "1111"Output - Count of cyclic permutations having XOR with other binary string ...

Read More

Count of divisors having more set bits than quotient on dividing N in C++

Sunidhi Bansal
Sunidhi Bansal
Updated on 11-Mar-2026 181 Views

We are given with an integer number let's say, N which is considered as a divisor and it will be divided with the numbers starting from the 1 - N and the task is to calculate the count of those divisors which have more number of set bits than the quotient when divided with the given number N.For ExampleInput - int N = 6Output - Count of divisors having more set bits than quotient on dividing N are: 5Explanation - Firstly, we will divide the number N with the numbers starting from 1 - N and calculate the set bits of ...

Read More

Count of arrays having consecutive element with different values in C++

Sunidhi Bansal
Sunidhi Bansal
Updated on 11-Mar-2026 482 Views

Given three variables size, max_val, last_element as input. The goal is to find the count of different arrays that can be formed in a manner such that they have size elements, have elements between 1 and max_val and the first element is always 1 and the last element is always max_val. Also make sure that no two consecutive elements are the same.Let us understand with examples.For ExampleInput - size = 5, max_val = 3, last_element = 3Output - Count of arrays having consecutive element with different values are: 5Explanation - The arrays will be:-[ 1, 2, 3, 1, 3 ], ...

Read More

Count number of paths whose weight is exactly X and has at-least one edge of weight M in C++

Sunidhi Bansal
Sunidhi Bansal
Updated on 11-Mar-2026 254 Views

We are given a tree which can have endless levels, a variable child which will store the number of children a node can have, a variable weight which will store the weight associated with the path and a variable path that will store the path and task is to calculate the count of number of paths which has weights equals to the X and there must be an at least one edge with the given weight.For ExampleInput - int child = 4, weight = 4, path = 4; Output - Count of number of paths whose weight is exactly X and ...

Read More

Count of AP (Arithmetic Progression) Subsequences in an array in C++

Sunidhi Bansal
Sunidhi Bansal
Updated on 11-Mar-2026 681 Views

Given an array arr[] containing integer elements. The goal is to count the number of Arithmetic Progression subsequences inside arr[]. The range of elements inside arr[] are [1, 1000000].Empty sequence or single element will also be counted.Let us understand with examples.For ExampleInput - arr[] = {1, 2, 3}Output - Count of AP (Arithmetic Progression) Subsequences in an array are: 8Explanation - The following subsequences will form AP:-{}, {1}, {2}, {3}, {1, 2}, {2, 3}, {1, 3}, {1, 2, 3}Input - arr[] = {2, 4, 5, 8}Output - Count of AP (Arithmetic Progression) Subsequences in an array are: 12Explanation - The following subsequences ...

Read More

Find a peak element in a 2D array in C++

Hafeezul Kareem
Hafeezul Kareem
Updated on 11-Mar-2026 464 Views

In this tutorial, we are going to write a program that finds the peak element in a 2D array.An element is called a peak element if all the elements around it are smaller than the element.Let's see the steps to solve the problem.Initialize the 2D array with dummy data.Iterate over the 2D array.First, check the corner elements of the 2D array.Next, write the conditions for the first and last rows of the 2D array.Now, check for the first and last columns of the 2D array.And finally, check the middle elements.In each case, we have to compare the current element with ...

Read More

Find a triplet from three linked lists with a sum equal to a given number in C++

Hafeezul Kareem
Hafeezul Kareem
Updated on 11-Mar-2026 283 Views

In this tutorial, we are going to write a program that finds the triplet in the linked list whose sum is equal to the given number.Let's see the steps to solve the problem.Create a struct node for the linked list.Create the linked list with dummy data.Write three inner loops for three elements which iterate until the end of the linked list.Add the three elements.Compare the sum with the given number.If both are equal, then print the elements and break the loops.ExampleLet's see the code.#include using namespace std; class Node {    public:    int data;    Node* next; }; ...

Read More

Delete a tail node from the given singly Linked List using C++

Dev Prakash Sharma
Dev Prakash Sharma
Updated on 11-Mar-2026 3K+ Views

A Linked List is a linear Data Structure that contains nodes and each node has two fields; one is the value or data to be inserted and the other field stores the address of the next node.Our task here is to delete a node from the end of a Linked List. The last node is known as the tail node. If there is no node in the Linked List, then return NULL.For example −Input 1 − 1 → 2 → 3 → 4 → 5Output − 1 → 2 → 3 → 4 →Explanation − In the given singly linked ...

Read More

Write a program in C++ to find the most frequent element in a given array of integers

Dev Prakash Sharma
Dev Prakash Sharma
Updated on 11-Mar-2026 4K+ Views

Let’s suppose we have an array of integers of size N. The task is to find the most frequent element present in the given array of integers. For example, Input-1 −N = 8 A[ ] = {1, 2, 4, 3, 3, 1, 1, 5}Output −1Explanation − In the given array of integers, the most appearing number is ‘1’. Thus the output is ‘1’.Input-2 −N = 6 A[ ] = {1, 4, 4, 4, 1, 1}Output-a −1Output-b −4Explanation: In the given array of integers, the most appearing number is ‘1’ and ‘4’. Thus we can return the output to any one ...

Read More
Showing 411–420 of 5,962 articles
« Prev 1 40 41 42 43 44 597 Next »
Advertisements