Found 7197 Articles for C++

Program to find maximum number enemies will be killed to place a bomb in C++?

Arnab Chakraborty
Updated on 10-Nov-2020 08:03:05

454 Views

Suppose we have a 2D matrix of three different values, 2s, 1s, and 0s, where a 2 represents an enemy, 1 represents a wall and 0 represents an empty cell. We have to find the maximum enemies we can kill using one bomb. The bomb kills all the enemies in the same row and column from the planted point until it hits the wall. And we can put bombs only on blank spaces.So, if the input is likethen the output will be 3, as we can place the bomb at the green box to kill maximum 3 enemies.ret := 0n ... Read More

Program to convert binary search tree to a singly linked list in C++?

Farhan Muhamed
Updated on 19-Aug-2025 17:27:40

640 Views

A Binary Search Tree is a data structure that stores data in a sorted order such that for every node, the left subtree contains values less than the node's value, and the right subtree contains values greater than the node's value. In this article, we will discuss how to convert a Binary Search Tree (BST) into a singly linked list in C++. Flatten Binary Search Tree to Singly Linked List Given a Binary Search Tree, the goal is to convert it into a singly linked list where the linked list nodes are in the same order as the in-order ... Read More

Count the pairs of vowels in the given string in C++

Sunidhi Bansal
Updated on 02-Nov-2020 06:20:11

365 Views

We are given with a string of characters and the task is to calculate the count of pairs having both the elements as vowels. As we know there are five vowels in English alphabet i.e. a, i, e, o, u and other characters are known as Consonants.Input − string str = "tutorials point”Output − Count the pairs of vowels in the given string are: 2Explanation − From the given string we can form pairs as (t, u), (u, t), (t, o), (o, r), (r, i), (i, a), (a, l), (l, s), (s, p), (p, o), (o, i), (i, n) and ... Read More

Count the number of elements in an array which are divisible by k in C++

Sunidhi Bansal
Updated on 02-Nov-2020 06:18:19

1K+ Views

We are given with an array of positive integer numbers and an integer variable k. The task is to calculate the count of the number of elements in an array which is divisible by the given value k.Input − int arr[] = {4, 2, 6, 1, 3, 8, 10, 9}, k = 2Output − Count the number of elements in an array which are divisible by 2 are − 5Explanation − we will divide the elements in an array by a value k and check whether the reminder is 0 or not. So, 4 is divisible by 2, 2 is ... Read More

Count of character pairs at same distance as in English alphabets in C++

Sunidhi Bansal
Updated on 02-Nov-2020 06:16:00

170 Views

We are given a string of characters and the task is to calculate the count of character pairs having pairs at the same distance as we have in english alphabets.Input − string str = ‘Tutorials Point’Output − Count of character pairs at same distance as in English alphabets are: 5Explanation − The character pairs with same distance as in english alphabets are (u, t), (u, r), (t, r), (i, o) and (s, n). So in total there are 5 pairs.Input − string str = ‘Learning is the best habit’Output − Count of character pairs at same distance as in English ... Read More

Count of numbers having only 1 set bit in the range [0, n] in C++

Sunidhi Bansal
Updated on 02-Nov-2020 06:14:40

259 Views

We are given a number and the task is to calculate the count of numbers from the range 0 till the given number let’s say, num having exactly one set bitSet bits in a binary number is represented by 1. Whenever we calculate the binary number of an integer value then it is formed as the combination of 0’s and 1’s. So, the digit 1 is known as set bit in the terms of the computer.Input − int num = 15Output − Count of numbers having only 1 set bit in the range [0, 15] are − 4Explanation − The ... Read More

Count of matrices (of different orders) with given number of elements in C++

Sunidhi Bansal
Updated on 02-Nov-2020 06:12:30

266 Views

We are given the total number of elements and the task is to calculate the total number of matrices with different orders that can be formed with the given data. A matrix has an order mxn where m are the number of rows and n are the number of columns.Input − int numbers = 6Output −Count of matrices of different orders that can be formed with the given number of elements are: 4Explanation − we are given with the total number of elements that a matrix of any order can contain which is 6. So the possible matrix order with ... Read More

Count of elements of an array present in every row of NxM matrix in C++

Sunidhi Bansal
Updated on 02-Nov-2020 06:11:21

812 Views

We are given an array of integer type elements and a matrix or 2-D array of given row and column size and the task is to calculate the count of elements of an array that are present in each row of a matrix.Input int arr = { 2, 4, 6} and int matrix[row][col] = { { 2, 4, 6 }, {3, 4, 6}, {6, 2, 1}}Output Elements of array in row 1 are: 3 Elements of array in row 2 are: 2 Elements of array in row 3 are: 2Explanation we are having array containing 2, 4 and 6 as elements and now ... Read More

Count pairs from two linked lists whose product is equal to a given value in C++

Sunidhi Bansal
Updated on 02-Nov-2020 06:08:56

123 Views

We are given with two linked lists and the task is to form the pairs using the integer elements of linked lists such that their product is equal to a given value which is let’s say, k. A linked list is a sequence of data structures, which are connected together via links.Input vector v_1 = {5, 7, 8, 10, 11}, . vector v_2 = {6, 4, 3, 2, 0} , int k = 20Output Count of pairs from two linked lists whose product is equal to a given value k are: 2Explanation The pairs which can be formed using the given linked lists ... Read More

Count pairs from two linked lists whose sum is equal to a given value in C++

Sunidhi Bansal
Updated on 02-Nov-2020 06:06:40

190 Views

We are given with two linked lists and the task is to form the pairs using the integer elements of linked lists such that their sum is equal to a given value which is let’s say, k. A linked list is a sequence of data structures, which are connected together via links.Input vector v_1 = {5, 7, 8, 10, 11}, . vector v_2 = {6, 4, 3, 2, 0} , int k = 11Output Count of pairs from two linked lists whose sum is equal to a given value k are: 4Explanation The pairs which can be formed using the given linked lists ... Read More

Advertisements