Server Side Programming Articles

Page 1208 of 2109

Count pairs in a sorted array whose sum is less than x in C++

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

We are given a sorted array of integer type elements and an integer variable x and the task is to form the pairs from the given array and calculate the sum of elements in the pair and check whether the calculated sum is less than x or not.Input − int arr[] = {2, 7, 1, 0, 8}, int x = 8Output − Count of pairs in a sorted array whose sum is less than x are − 4Explanation − The pairs that can be formed from the given array are: (2, 7) = 9(greater than x), (2, 1) = 3(less ...

Read More

Count pairs in a sorted array whose product is less than k in C++

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

We are given a sorted array of integer type elements and an integer variable x and the task is to form the pairs from the given array and calculate the product of elements in the pair and check whether the calculated product is less than k or not.Input int arr[] = {2, 7, 1, 0, 8}, int k = 10Output Count of pairs in a sorted array whose product is less than k are: 7Explanation The pairs that can be formed from the given array are: (2, 7) = 14(greater than k), (2, 1) = 2(less than k), (2, 0) = 0(less than ...

Read More

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

Sunidhi Bansal
Sunidhi Bansal
Updated on 11-Mar-2026 269 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

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

Sunidhi Bansal
Sunidhi Bansal
Updated on 11-Mar-2026 174 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 of elements of an array present in every row of NxM matrix in C++

Sunidhi Bansal
Sunidhi Bansal
Updated on 11-Mar-2026 901 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 of numbers having only 1 set bit in the range [0, n] in C++

Sunidhi Bansal
Sunidhi Bansal
Updated on 11-Mar-2026 313 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 the number of elements in an array which are divisible by k in C++

Sunidhi Bansal
Sunidhi Bansal
Updated on 11-Mar-2026 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

How to find the frequency of a particular string in a column based on another column in an R data frame using dplyr package?

Nizamuddin Siddiqui
Nizamuddin Siddiqui
Updated on 11-Mar-2026 669 Views

When we have two or more categorical columns in an R data frame with strings as level of the categories or numbers as strings/integers then we can find the frequency of one based on another. This will help us to identify the cross-column frequencies and we can understand the distribution of one categorical based on another column. To do this with dplyr package, we can use filter function.ExampleClass%filter(Class=="First")%>%count(Gender) Gender n 1 Female 2 2 Male 2 df2%>%filter(Class=="Second")%>%count(Gender) Gender n 1 Female 6 2 Male 2

Read More

How to remove rows that contains all zeros in an R data frame?

Nizamuddin Siddiqui
Nizamuddin Siddiqui
Updated on 11-Mar-2026 10K+ Views

Often, we get missing data and sometimes missing data is filled with zeros if zero is not the actual range for a variable. In this type of situations, we can remove the rows where all the values are zero. For this purpose, we can use rowSums function and if the sum is greater than zero then keep the row otherwise neglect it.Example1y1

Read More

How to remove multiple rows from an R data frame using dplyr package?

Nizamuddin Siddiqui
Nizamuddin Siddiqui
Updated on 11-Mar-2026 611 Views

Sometimes we get unnecessary information in our data set that needs to be removed, this information could be a single case, multiple cases, whole variable or any other thing that is not helpful in achieving our analytical objective, hence we want to remove it. If we want to remove such type of rows from an R data frame with the help of dplyr package then anti_join function can be used.ExampleConsider the below data frame:> set.seed(2514) > x1 x2 df1 df1Output x1 x2 1 5.567262 4.998607 2 5.343063 4.931962 3 2.211267 5.034461 ...

Read More
Showing 12071–12080 of 21,090 articles
Advertisements