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

355 Views
Suppose we have an array of integers; we have to find the maximum sum for a non-empty subarray (contiguous elements) with at most one element deletion. In other words, we can say that we want to choose a subarray and optionally delete one element from it so that there is still at least one element left and the sum of the remaining elements is maximum possible. We have to keep in mind that the subarray needs to be non-empty after deleting one element. So if the input is like [1, -2, 0, 3], then the output will be 4. So ... Read More

391 Views
Suppose we have some sticks with positive integer lengths. We can connect any two sticks of lengths X and Y into one stick by paying a cost of X + Y. This will be performed until there is one stick remaining. We have to find the minimum cost of connecting all the given sticks into one stick in this way. So if the stack is [2, 4, 3], then the output will be 14.To solve this, we will follow these steps −Define a max heap priority queue pqinsert all elements of s into pqans := 0while pq has more than ... Read More

278 Views
Suppose we have the root of a binary tree, the level of its root is 1, the level of its children is 2, and so on. We have to return the smallest level X such that the sum of all the values of nodes at level X is maximal. So if the tree is like −Then the output will be 2, The level 1 sum = 1, level 2 sum is 7 + 0 = 7, level 2 sum is 7 + (-8) = -1, so max is of level 2, so output is 2.To solve this, we will follow ... Read More

1K+ Views
As we know a complete binary tree is a binary tree in which every level, except possibly the last, is completely filled, and all nodes are as far left as possible. We have to write a data structure CBTInserter that is initialized with a complete binary tree and it supports the following operations−CBTInserter(TreeNode root) this initializes the data structure on a given tree with head node root;CBTInserter.insert(int v) will used to insert a TreeNode into the tree with a value node.val = v so that the tree remains complete, and returns the value of the parent of the inserted TreeNode;CBTInserter.get_root() ... Read More

266 Views
Suppose we have an array of integers A. We have to find the sum of min(B), where B ranges over every (contiguous) subarray of A. Since the answer may be very large, then return the answer in modulo 10^9 + 7. So if the input is like [3, 1, 2, 4], then the output will be 17, because the subarrays are [3], [1], [2], [4], [3, 1], [1, 2], [2, 4], [3, 1, 2], [1, 2, 4], [3, 1, 2, 4], so minimums are [3, 1, 2, 4, 1, 1, 2, 1, 1, 1], and the sum is 17.To solve ... Read More

330 Views
Suppose a full binary tree is a binary tree where each node has exactly 0 or 2 children. So we have to find a list of all possible full binary trees with N nodes. Each node of each tree in the answer must have node.val = 0. The returned trees can be in any order. So if the input is 7, then the trees are −To solve this, we will follow these steps −Define a map m of integer type key and tree type value.define a method called allPossibleFBT(), this will take N as inputis N is 1, then create ... Read More

163 Views
Suppose we have a binary tree rooted at root, the depth of each node is the shortest distance to the root. Here a node is deepest if it has the largest depth possible among any node in the entire tree. The subtree of a node is that node, plus the set of all descendants of that node. We have to find the node with the largest depth such that it contains all the deepest nodes in its subtree. So if the tree is like −Then the deepest subtree will be −To solve this, we will follow these steps −Define a ... Read More

4K+ Views
Suppose we have a char array representing tasks CPU need to do. This contains uppercase letters A to Z where different letters represent different tasks. The tasks could be done without original order. Each task could be done in one interval. For each interval, CPU could finish one job or just be idle. However, there is a non-negative cooling interval called n that means between two same tasks, there must be at least n intervals that CPU are doing different tasks or just be idle. We have to find the least number of intervals the CPU will take to finish ... Read More

2K+ Views
Suppose we have a string s and a non-empty string p, we have to find all the start indices of p's anagrams in s. The strings consist of lowercase letters only and the length of both strings s and p will not be larger than 20 and 100. So for example, if s: "cbaebabacd" p: "abc", then the output will be [0, 6], at index 0, it is “cba”, and another is “bac”, these are the anagrams of “abc”.To solve this, we will follow these steps −Define a map m, n := size of s, set left := 0, right ... Read More

438 Views
Suppose one thief has found himself a new place for his thievery again. There is only one entrance to this area, the entrance is called the "root." Besides the root, each house has one and only one parent house. After a tour, the smart thief felt that "all houses in this place forms a binary tree". And It will automatically contact the police if two directly-linked houses were broken into on the same night. We have to find the maximum amount of money the thief can rob tonight without alerting the police. So if the tree is like −Then the ... Read More