Found 7347 Articles for C++

Count triplets in a sorted doubly linked list whose product is equal to a given value x in C++

Sunidhi Bansal
Updated on 05-Jan-2021 05:09:32

154 Views

Given a sorted doubly linked list containing integer values. The goal is to find triplets whose product is equal to the given value x. If input linked list is 3−4−1−2 and x is 6 then count will be 1 (triplet (3, 1, 2))For ExampleInputlinked list: [ 200−4−16−5−10−10−2 ] x=200OutputCount of triplets in a sorted doubly linked list whose product is equal to a given value x are: 3ExplanationTriplets will be: (4, 5, 10), (4, 5, 10) and (10, 10, 2)Inputlinked list: [ 4−3−1−5−2−4−2] x=12OutputCount of triplets in a sorted doubly linked list whose product is equal to a given value ... Read More

Count occurrences of the average of array elements with a given number in C++

Sunidhi Bansal
Updated on 05-Jan-2021 05:00:41

93 Views

Given an array arr[] containing integer elements and an integer num. The goal is to find the average of each element arr[i] and num and print the count of the number of times that average appeared in the original array.If array arr[] is [ 5, 2, 3 ] and num is 2. Averages will be [ 3, 2, 2 ] occurrences in arr[] is [ 1, 1, 1 ]For ExampleInputarr[] = { 1, 6, 4, 3, 6, 4 } num=2Output1 2 1 0 2 1Count of occurrences of the average of array elements with a given number are − 5ExplanationThe ... Read More

Count occurrences of a character in a repeated string in C++

Sunidhi Bansal
Updated on 05-Jan-2021 04:56:55

5K+ Views

Given a string str, a character and a positive integer N. The string str is repeated indefinitely. The goal is to find the count of occurrences of character in str in first N characters of repetitions.If str is “abac”, character is ch=‘b’ and N is 10.In first 10 characters of “abacabacabacabac…….” b occurs twice.Note − Take str and character ch within the same case.Let us understand with examples.For ExampleInputstr = "TPTTTT" ch = 'T' n = 12OutputCount of occurrences of a character in a repeated string are: 10ExplanationThe number of ‘T’ in str is 5. Length of str is 6. ... Read More

Check if any two intervals overlap among a given set of intervals in C++

Arnab Chakraborty
Updated on 30-Dec-2020 13:11:59

680 Views

Suppose, we are given a set of intervals that consists of values (time1, time2) where time1 represents the starting time, and time2 represents the ending time of an event. Our task is to check whether any of these intervals overlap any other interval in this set. If any of the intervals overlap, we return the result as True, otherwise we return False.So, if the input is like [(4, 7), (5, 11), (7, 11), (5, 8)] then the output will be True.To solve this, we will follow these steps −sort the list inputArrfor i in range 1 to size of inputArr, ... Read More

Check if an array is stack sortable in C++

Arnab Chakraborty
Updated on 30-Dec-2020 12:45:27

210 Views

Suppose we have an array nums of unique elements from 1 through n. We have to check whether it is stack-sortable or not. An array is stack sortable when it can be stored in some other array using a temporary stack.To solve this, we can use any of these operations on the array −Delete the starting element of array and push that item into the stack.Delete the top element of the stack and insert it to the end of second array.Now if all the element of the given array is transferred to the second array by these operations so the ... Read More

Delete alternate nodes of a Linked List in C++

Hafeezul Kareem
Updated on 30-Dec-2020 07:01:21

1K+ Views

In this tutorial, we are going to learn how to delete all prime nodes from a singly linked list.Let's see the steps to solve the problem.Write struct with data and next pointer.Write a function to insert the node into the singly linked list.Initialize the singly linked list with dummy data.Iterate over the singly linked list.Delete alternate node by maintaining the previous node.Write a function to delete the node. Consider the following three cases while deleting the node.If the node is head node, then move the head to next node.If the node is middle node, then link the next node to ... Read More

Delete all the nodes from the list that are greater than x in C++

Hafeezul Kareem
Updated on 30-Dec-2020 06:59:33

2K+ Views

In this tutorial, we are going to learn how to delete all prime nodes from a singly linked list.Let's see the steps to solve the problem.Write struct with data and next pointer.Write a function to insert the node into the singly linked list.Initialize the singly linked list with dummy data.Iterate over the singly linked list. Find whether the current node data is greater than x or not.If the current data is greater than x, then delete the node.Write a function to delete the node. Consider the following three cases while deleting the node.If the node is head node, then move ... Read More

Delete all the nodes from the doubly linked list that are greater than a given value in C++

Hafeezul Kareem
Updated on 30-Dec-2020 06:57:36

84 Views

In this tutorial, we are going to learn how to delete all prime nodes from a doubly linked list.Let's see the steps to solve the problem.Write struct with data, prev and next pointers.Write a function to insert the node into the doubly linked list.Initialize the doubly linked list with dummy data.Iterate over the doubly linked list. Find whether the current node data is greater than given value or not.If the current data is greater than the given value, then delete the node.Write a function to delete the node. Consider the following three cases while deleting the node.If the node is ... Read More

Delete all the nodes from a doubly linked list that are smaller than a given value in C++

Hafeezul Kareem
Updated on 30-Dec-2020 06:55:49

200 Views

In this tutorial, we are going to learn how to delete all prime nodes from a doubly linked list.Let's see the steps to solve the problem.Write struct with data, prev and next pointers.Write a function to insert the node into the doubly linked list.Initialize the doubly linked list with dummy data.Iterate over the doubly linked list. Find whether the current node data is less than given value or not.If the current data is less than the given value, then delete the node.Write a function to delete the node. Consider the following three cases while deleting the node.If the node is ... Read More

Delete all the even nodes from a Doubly Linked List in C++

Hafeezul Kareem
Updated on 30-Dec-2020 06:53:58

722 Views

In this tutorial, we are going to learn how to delete all prime nodes from a doubly linked list.Let's see the steps to solve the problem.Write struct with data, prev and next pointers.Write a function to insert the node into the doubly linked list.Initialize the doubly linked list with dummy data.Iterate over the doubly linked list. Find whether the current node data is even or not.If the current data is even, then delete the node.Write a function to delete the node. Consider the following three cases while deleting the node.If the node is head node, then move the head to ... Read More

Advertisements