
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
Found 7197 Articles for C++

302 Views
In this problem, we are given an n tree and there are some queries that are nodes of the tree. Our task is to print the XOR of all nodes of the sub-tree formed by the given node.Let’s take an example to understand the problem, Queries − {1, 6, 5}Output −0 0 5Explanation −1^6^3^2^4^7^5 6^2^4 5To solve this problem, we will compute the xor of all nodes of the sub-tree by traversing the tree once and store it. Now, we will compute the xor of all nodes of the sub-tree if the child nodes and then computing for all given ... Read More

159 Views
In this problem, we are given an array of n elements and there are some queries which are range from a start point to endpoint in the array. Our task is two finds the XOR of elements that appeared even a number of times in the range.Let’s take an example to understand the problem, Input −array = {1, 2, 3, 1, 1, 2, 2, 3} querries = 2 R = 4 L = 2, R = 5 L = 2, R = 7Output −0 1 0The solution to this problem is quite easy, we will find the sum of XOR ... Read More

318 Views
In this problem, we are given a binary tree and two nodes of the binary tree. Our task is to print the XOR of all nodes that come in the path between the two nodes.Let’s take an example to understand the problem, We need to find the xor of all nodes between 2 and 3.The path from 2 to 3, 2 → 6 → 1 → 3.We will find 2^3^1^3.Output −To solve this problem, we need to find the paths from one to another node. For this, we will find the XOR of all nodes in the path from the ... Read More

195 Views
In this problem, we are given a string of characters, our task is to print the XOR of frequencies of characters of the string whose frequency of occurrence is a prime number.Let’s take an example to understand the problem, Input − TutorialsPointOutput −Here, we will check the frequency of occurrence of each character of the string and then find XOR of all the characters whose frequency is a prime number. For this will create an array of prime frequencies. Then we will store frequencies of characters of a string in a map and then matching with prime frequency array. If ... Read More

258 Views
In this problem, we are given an array of n elements. Our task is to generate a sequence of size n*n whose elements are the sum of a pair of all elements of A with itself. And print the xor elements of this sum array formed.Let’s take an example to understand the problem, Input − A (1, 4, 5)Output − 0Explanation −B (1+1, 1+4, 1+5, 4+1, 4+4, 4+5, 5+1, 5+4, 5+5) B(2, 5, 6, 5, 8, 9, 6, 9, 10) Xor of all values = 2^5^6^5^8^9^6^9^10 = 0.To solve this problem, we need to know some properties of Xor. The ... Read More

710 Views
Here, we are given a linked list and an index. We have to write a function to get Nth node in a linked list.Let’s take an example to understand the problem, Inputlinked list = 34 -> 4 -> 9 -> 1 , n = 2Output9To go to the node specified by n. We will go node by node in the linked list and increase the index count until the required nth position is reached.Program to illustrate the program, Example Live Demo#include using namespace std; class Node{ public: int data; Node* next; }; void insertNode(Node** head_ref, int new_data) ... Read More

166 Views
Write a program that compiler and runs both in c and c++ and produces different results.There are multiple types of programs that give different results when compiled in c and c++.i. Using character literals− c and c++ both treat characters differently. In C, they are treated as integer literals whereas, in C++, they are treated as characters.Example Live Demo#include int main(){ printf("%d", sizeof('a')); return 0; }OutputC : 4 C++: 1ii. Use of binary number − binary values are not considered as binary in c, instead treat it as integer. But in c++, they are treated as binary.Example Live Demo#include int ... Read More

1K+ Views
Here, we are given an array or a string of characters. We will create a program to reverse the elements of an array or string.Let’s take an example to understand the problem, Inputarray = {2, 5, 7, 1, 9}Output{9, 1, 7, 5, 2}Inputstring = “Hello!”Output!0lleHTo create a program, we will loop through the elements of the array/string(both work in the same way). Taking one variable for start and one of end. And swap both elements. Increment the start variable and decrement the end variable. The swapping will continue till start variable’s value is less than end variable.The program can be ... Read More

1K+ Views
In this problem, we are given an unsigned integer n. Our task is to create a program that returns the number which is generated by reversing all the bits of the number.Let’s take an example to understand the problem, Inputn = 1Output2147483648Explanationbinary of 1 is 000...0001, the reverse is 100...0000.To solve this problem, we simple solution will be using a simple formula. We will loop through the binary of the number. And find the position of the set bit in the number lets say it i. The result will be calculated using the formula, ((total_number_of_bits) - 1) - iProgram to ... Read More

545 Views
In this problem, we are given two integers x and y. Our task is to create a function that will be equivalent to pow(x, y) using an iterative approach that will complete the task in time complexity of 0(Log y).Let’s take a few examples to understand the problem, Inputx = 7 , y = 3Output343The iterative function for pow(x, y) will iterate and update the result for odd values of y multiplying it by x and update x to x2 at every iteration.Program to show the implementation of the solutionExample Live Demo#include using namespace std; void calcPower(int x, unsigned int ... Read More