Data Structure
Networking
RDBMS
Operating System
Java
MS Excel
iOS
HTML
CSS
Android
Python
C Programming
C++
C#
MongoDB
MySQL
Javascript
PHP
- Selected Reading
- UPSC IAS Exams Notes
- Developer's Best Practices
- Questions and Answers
- Effective Resume Writing
- HR Interview Questions
- Computer Glossary
- Who is Who
C++ Articles - Page 305 of 719
189 Views
In this problem, we are given a binary tree and we are given Q queries. Our task is to create a program to solve Queries to find distance between two nodes of a Binary tree – O(logn) method in C++.Problem DescriptionIn each query, we are given two nodes of the binary tree and we need to find the number distance between two nodes i.e. the number of edges to be traversed to reach one node from another node.Let’s take an example to understand the problem, Input: Binary TreeQueries = 3Q1 -> [2, 6]Q2 -> [4, 1]Q3 -> [5, 3]Output:3, 2, ... Read More
300 Views
In this problem, we are given Q queries each contains a number N. Our task is to create a program to solve Queries to count the number of unordered coprime pairs from 1 to N in C++.Co-prime also known as relatively prime or mutually prime are the pair of numbers that have only one factor i.e. 1.Let’s take an example to understand the problem, Input: Q = 2, queries = [5, 6] Output: 10ExplanationThe pairs are : (1, 1), (1, 2), (1, 3), (1, 4), (1, 5), (2, 3), (2, 5), (3, 4), (3, 5), (4, 5)Solution ApproachThe most promising solution ... Read More
359 Views
In this problem, we have given an array arr[] and some queries each consisting of three values, L and R, and val. Our task is to create a program to solve Queries to check whether a given digit is present in the given Range in C++.Problem Description−To solve each query, we need to check if the given element val is present in the given Range between L and R or not.Let’s take an example to understand the problem, Input:arr[] = {4, 8, 1, 7, 2, 9, 3, 5, 1}Q = 3query = {{1, 4, 3}, {0, 2, 1}, {4, 7, ... Read More
125 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
534 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
194 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
305 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
139 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
469 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
915 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