Found 7347 Articles for C++

Queries to check if it is possible to join boxes in a circle in C++

Ayush Gupta
Updated on 24-Aug-2020 05:37:23

74 Views

In this tutorial, we will be discussing a program to find queries to check if it is possible to join boxes in a circle.For this we will be provided with a circle of boxes running from 1 to n. Our task is to find whether box i can be connected to box j with a rod without intersecting the previous rodes.Example Live Demo#include using namespace std; //checking if making a circle from boxes is possible void isPossible(int n, int q, int queryi[], int queryj[]) {    int arr[50];    for (int i = 0; i queryj[k]) {     ... Read More

Queries to check if a number lies in N ranges of L-R in C++

Ayush Gupta
Updated on 09-Oct-2020 09:11:02

358 Views

In this problem, we are given N ranges [L, R] and Q queries each containing a number val. Our task is to create a program to solve Queries to check if a number lies in N ranges of L-R in C++.Problem DescriptionWe are given N ranges of type of [L, R] that contain integer values from L to R, for example, range [3, 6] contains 3, 4, 5, 6. In each query, we are given a val, whose presence is to be checked. The program will return true if the val is present in any one of the ranges otherwise ... Read More

Queries to answer the X-th smallest sub-string lexicographically in C++

Ayush Gupta
Updated on 09-Oct-2020 09:13:05

120 Views

In this problem, we are given a string str and Q queries. Each Query has a number X. Our task is to create a program to solve the Queries to answer the X-th smallest sub-string lexicographically in C++.Problem DescriptionWe need to find the Xth lexicographically smallest substring for each query i.e. based on alphabetical order sorting we will have to find Xth substring.Let’s take an example to understand the problem, Input: str = “point”Q = 4 query = {4, 7, 2, 13}Output:n, oi, in, poinExplanationAll substrings of str in lexicographical order are−i, in, int, n, nt, o, oi, oin, oint, ... Read More

Find distance between two nodes of a Binary Tree in C++ Program

Ayush Gupta
Updated on 09-Oct-2020 09:14:45

183 Views

In this problem, we are given a binary tree and two nodes. Our task is to create a program to Find distance between two nodes of a Binary Tree.Problem DescriptionWe need to find the distance between two nodes which is the minimum number of edges that will be traversed when we go from one node to another node.Let’s take an example to understand the problem, Input: binary treeNode1 = 3 ,Node2 = 5Output: 3ExplanationThe path from node 3 to node 5 is 3 -> 1 -> 2 -> 5. There are 3 edges traversed that make distance 3.Solution ApproachA simple ... Read More

Queries to add, remove and return the difference of maximum and minimum in C++

Ayush Gupta
Updated on 09-Oct-2020 08:50:07

99 Views

In this problem, we are given Q queries. These are of three types, they are −Query 1: Add number N to the list.Query 2: Remove number N to the list.Query 3: Return the difference of minimum and maximum element of the list.Our task is to create a program to solve queries to add, remove, and return the difference of maximum and minimum in C++.Problem DescriptionWe will be given a Q number of queries that we will be performing on the list. There are 3 types of queries to add, remove, and find the difference of maximum and minimum element of ... Read More

Different methods to copy in C++ STL - std::copy(), copy_n(), copy_if(), copy_backwards()

Sunidhi Bansal
Updated on 14-Aug-2020 08:43:35

327 Views

As the method name suggests copy() method is used to copy the data through various methods available in C++ STL. All the methods differ in functionalities and the parameters. These methods are available in header file. Let’s discuss each method and their functionalities.Copy(start_i1, end_i1, start_i2)This method is used to copy the data from one iterator to another iterator within specified range where both the start and end elements of an iterator are inclusive. It takes three types of arguments i.e. −Start_i1 − It will point to the initial element of the iterator, let’s say, i_1 from where the element ... Read More

Different ways to declare variable as constant in C and C++

Sunidhi Bansal
Updated on 14-Aug-2020 08:40:57

663 Views

There are multiple ways of declaring constants in C and C++. First of all, we need to understand what constant is.What is a Constant?Constant means which can’t be changed. In terms of programming, constants are the fixed values that are assigned to the variables such that they can’t be altered by any other variable or component during the execution of a program. Constants can be of any data type. They are used in the programming for defining the non-changing component of a program. There are some data or variables which have fixed value like Pi have fixed float value as ... Read More

Upper bound and Lower bound for non increasing vector in C++

Sunidhi Bansal
Updated on 14-Aug-2020 08:31:50

4K+ Views

In this article we are going to discuss the vector::upper_bound() and vector::lower_bound() for an array sorted in non-increasing order in C++ STL.Vectors are similar to the dynamic arrays; they have the ability to modify its size itself whenever a value is inserted into or removed from the container where we are storing the value.In a Vector, lower bound returns an iterator pointing to the first element in the range that does not compare the given value. Upper Bound returns an iterator pointing element in the range that smaller than given value.Input 30 30 30 20 20 20 10 10Output Lower bound of ... Read More

map count( ) function in C++

Sunidhi Bansal
Updated on 14-Aug-2020 08:29:37

4K+ Views

In this article we will be discussing the working, syntax and examples of map::empty() function in C++ STL.What is Map in C++ STL?Maps are the associative container, which facilitates to store the elements formed by a combination on key value and mapped value in a specific order. In a map container the data is internally always sorted with the help of its associated keys. The values in map container is accessed by its unique keys.What is map::count()?The map::count( ) is a function which comes under header file. This function counts the elements with specific key, it returns 1 if ... Read More

Sin( ) function for complex number in C++

Sunidhi Bansal
Updated on 14-Aug-2020 08:27:16

115 Views

We are given with the task to find the working of sin() function for complex number. The sin( ) function for complex numbers are present in the complex header file which means for calculating the value of sin() we need to add the complex header file in the code. In mathematics this function is used to calculate the value of sin having complex numbers.SyntaxSyntax for sin() function is −sin(z);Parameterparameter z can be any complex number and this parameter is defined in the definition of sin() function which makes this parameter mandatory.Return typeThis function returns the complex value of sin( ) ... Read More

Advertisements