Found 26504 Articles for Server Side Programming

Count divisible pairs in an array in C++

Sunidhi Bansal
Updated on 15-May-2020 11:46:43

275 Views

We are given an array of any size containing integer elements and the task is to calculate the count of pairs in an array such that one element of a pair divides another element of a pair.Arrays a kind of data structure that can store a fixed-size sequential collection of elements of the same type. An array is used to store a collection of data, but it is often more useful to think of an array as a collection of variables of the same type.For ExampleInput − int arr[] = {1, 2, 3, 6} Output − count is 4Explanation − ... Read More

Count number of elements between two given elements in array in C++

Sunidhi Bansal
Updated on 15-May-2020 10:42:22

1K+ Views

We are given an array containing integer elements and two numbers start and end and the task is to calculate the count of elements present between start and end in an array.Arrays a kind of data structure that can store a fixed-size sequential collection of elements of the same type. An array is used to store a collection of data, but it is often more useful to think of an array as a collection of variables of the same type. If the start element is occurring multiple times then we will consider the first occurrence of the start element and ... Read More

Count elements present in first array but not in second in C++

Sunidhi Bansal
Updated on 15-May-2020 10:40:00

133 Views

We are given an array of any size containing integer elements and the task is to calculate the count of elements that are present in the first array but not in the second array..Arrays a kind of data structure that can store a fixed-size sequential collection of elements of the same type. An array is used to store a collection of data, but it is often more useful to think of an array as a collection of variables of the same type.For exampleInput− int arr_1[] = {1, 2, 3, 4}       Int arr_2[] = {1, 5, 6, 7, ... Read More

Count distinct elements in an array in C++

Ravi Ranjan
Updated on 11-Jun-2025 18:42:43

8K+ Views

In this article, we have an unsorted array of integers having repetitive elements. Our task is to count the distinct elements in the given array in C++. Example Here is an example of counting the unique number in the given array: Input: array = {4, 2, 32, 26, 57, 52, 40, 2, 57, 40, 33} Output: Distinct elements in the array: 8 Here is a list of approaches for counting distinct elements in the given array: Using Nested for Loop Using Sorting ... Read More

Count and Print the alphabets having ASCII value not in the range [l, r] in C++

Sunidhi Bansal
Updated on 15-May-2020 10:35:11

164 Views

We are given with a string of any length and the task is to calculate the count and print the alphabets in a string having ASCII value not in the range [l, r]ASCII value for character A-Z are given belowABCDEFGHIJKLMNOPQRS65666768697071727374757677787980818283TUVWXYZ84858687888990ASCII value for characters a-z are given belowabcdefghijklmnopqrs979899100101102103104105106107108109110111112113114115tuvwxyz116117118119120121122For ExampleInput − String str = “point       First = 111, Last = 117 Output − characters not in the given range are: i, n       Count is: 2Explanation − since i and n don't lies in the range of [111, 117] these characters will be counted.Input − String str ... Read More

Count and Print the alphabets having ASCII value in the range [l, r] in C++

Sunidhi Bansal
Updated on 15-May-2020 10:31:23

331 Views

We are given with a string of any length and the task is to calculate the count and print the alphabets in a string having ASCII value in the range [l, r]ASCII value for character A-Z are given belowABCDEFGHIJKLMNOPQRS65666768697071727374757677787980818283TUVWXYZ84858687888990ASCII value for characters a-z are given below −abcdefghijklmnopqrs979899100101102103104105106107108109110111112113114115tuvwxyz116117118119120121122For ExampleInput − String str = “point       First = 111, Last = 117 Output − characters in the given range are: p, o , t       Count is: 3Explanation − since p, o and t lies in the range of [111, 117] these characters will be counted.Input − String ... Read More

Count Non-Leaf nodes in a Binary Tree in C++

Sunidhi Bansal
Updated on 15-May-2020 10:28:05

2K+ Views

We are given with a binary tree and the task is to calculate the count of non-leaf nodes available in a binary tree.Binary Tree is a special data structure used for data storage purposes. A binary tree has a special condition that each node can have a maximum of two children. A binary tree has the benefits of both an ordered array and a linked list as search is as quick as in a sorted array and insertion or deletion operation are as fast as in linked list. Non-leaf nodes are also known as parent nodes as they have more ... Read More

Count nodes in Circular linked list in C++

Sunidhi Bansal
Updated on 15-May-2020 10:24:30

1K+ Views

We are given a circular linked list with the nodes and the task is to calculate the count of nodes present in a circular linked list.Circular Linked List is a variation of Linked list in which the first element points to the last element and the last element points to the first element. Both Singly Linked List and Doubly Linked List can be made into a circular linked list.In the below program, we are implementing a singly linked list as a circular linked list to calculate the count of nodes in that.For ExampleInput − nodes-: 20, 1, 2, 3, 4, ... Read More

Count all triplets whose sum is equal to a perfect cube in C++

Sunidhi Bansal
Updated on 15-May-2020 09:40:12

240 Views

We are given with an array of n integers and the task is to calculate the count all the triplets whose sum is equal to perfect cubeWhat is the perfect cubeA perfect cube is a number which is a cube of any number, like 125 is a cube of 5 so we can say that 125 is a perfect cube. Some of the perfect cube integers are 1, 8, 27, 64, 125….So, according to the problem in the array we have to find and count those triplets (set of 3 values) whose sum is equal to a perfect cube number. ... Read More

Count characters with same neighbors in C++

Sunidhi Bansal
Updated on 15-May-2020 09:27:28

258 Views

We are given a string with, let’s say, str and the task is to compute the count of characters in a string str having the same neighbors and that will include both left and right side of a character in a string. Also, in this scenario the first and last character in a string will always be considered as they have only one adjacent character.For ExampleInput − string str = “poiot” Output − count is 3Explanation − In the given string characters p, t and i are having the same neighbors so the count will be increased to 3.Input − ... Read More

Advertisements