
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++

457 Views
Suppose we have a binary tree, a node X in the tree is named good when in the path from root to X there are no nodes whose value is greater than X. Here we have to find the number of good nodes in the binary tree.So, if the input is like, then the output will be 4, the colored nodes are good node.To solve this, we will follow these steps −Define a function dfs(), this will take node, val, if node is null, then −returnret := ret + (1 when val left){ if(val != NULL) ... Read More

464 Views
Suppose we have an undirected tree consisting of n vertices and these are numbered from 0 to n-1, which has some apples in their vertices. We spend 1 second to walk over one edge of the tree. We have to find the minimum time in seconds we have to spend in order to collect all apples in the tree starting at vertex 0 and coming back to this vertex.Here the edges of the undirected tree are given in the array edges, where edges[i] = [from_i, to_i] this means that exists an edge connecting the vertices from_i and to_i. Additionally, there ... Read More

271 Views
Suppose we have an array of integers arr. We want to select three indices like i, j and k where (0 = 0; j--) { x1 = x1 ^ arr[j]; m[x1]++; } for (int j = i; j < n; j++) { x2 = x2 ^ arr[j]; ret += m[x2]; } } return ret; } }; main(){ Solution ob; vector v = {2,3,1,6,7}; cout

507 Views
Suppose we have an array of integers called nums and an integer limit, we have to find the size of the longest non-empty subarray such that the absolute difference between any two items of this subarray is less than or equal to the given limit.So, if the input is like nums = [8, 2, 4, 7], limit = 4, then the output will be 2, this is because −[8] so |8-8| = 0 4.[8, 2, 4] so |8-2| = 6 > 4.[8, 2, 4, 7] so |8-2| = 6 > 4.[2] so |2-2| = 0 k) { ... Read More

183 Views
Suppose we have an array nums of 0s and 1s and an integer k, we have to check whether all 1's are at least k places away from each other, otherwise, return False.So, if the input is like nums = [1, 0, 0, 0, 1, 0, 0, 1], k = 2, then the output will be true, as each of the 1s are at least 2 places away from each other.To solve this, we will follow these steps −last := -1for initialize i := 0, when i < size of nums, update (increase i by 1), do −if nums[i] is ... Read More

268 Views
Suppose we have two strings s1 and s2 whose size are same; we have to check whether some permutation of string s1 can break some permutation of string s2 or vice-versa. A string a can break string b if x[i] >= y[i] (in alphabetical order) for all i in range 0 to n-1.So, if the input is like s1 = abc and s2 = xya, then the output will be true. This is because "ayx" is a permutation of s2 that can break to string "abc" which is a permutation of s1="abc".To solve this, we will follow these steps −Define ... Read More

213 Views
Suppose we have an integer num. We will apply the following steps exactly two times, the steps are like −Pick a digit x in range 0 to 9.Pick another digit y also in range 0 to 9. The digit y can be equal to x.Replace all the occurrences of x in the decimal representation of num by y. The new integer cannot have any leading zeros, also the new integer cannot be of value 0.Now consider a and b be the results of applying the operations to num the first and second times, respectively. Then find the max difference between ... Read More

178 Views
Suppose we have a list of lists called nums, we have to show all elements of nums in diagonal order.So, if the input is likethen the output will be [1, 6, 2, 8, 7, 3, 9, 4, 12, 10, 5, 13, 11, 14, 15, 16]To solve this, we will follow these steps −Define an array retDefine one 2D array vfor initialize i := 0, when i < size of nums, update (increase i by 1), do −for initialize j := 0, when j < size of nums[i], update (increase j by 1), do −insert { nums[i, j], i, j } ... Read More

315 Views
Suppose there are several cards arranged in a row, each card has associated points, and these points are given in the integer array called cardPoints. In one step, we can take one card from the beginning or from the end of the row. We have to take exactly k cards. The final score will be the sum of the points of the cards we have taken. So, if we have integer array cardPoints and the integer k, then find the maximum score we can obtain.So, if the input is like cardPoints = [1, 2, 3, 4, 5, 6, 1], k ... Read More