
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 26504 Articles for Server Side Programming

673 Views
Suppose we have directed graph, with nodes labelled 0, 1, ..., n-1. In this graph, each edge is colored with either red or blue colors, and there could be self-edges or parallel edges. Each [i, j] in red_edges indicates a red directed edge from node i to node j. Similarly, each [i, j] in blue_edges indicates a blue directed edge from node i to node j. We have to find an array answer of length n, where each answer[X] is the length of the shortest path from node 0 to node X such that the edge colors alternate along the ... Read More

170 Views
Suppose we have a rooted binary tree, we have to return the lowest common ancestor of its deepest leaves. We have to keep in mind that −The node of a binary tree is a leaf node if and only if it has no childrenThe depth of the root of the tree is 0, and when the depth of a node is d, the depth of each of its children is d+1.The lowest common ancestor of a set S of nodes in the node A with the largest depth such that every node in S is in the subtree with root ... Read More

182 Views
Suppose we have the root of a binary tree; we have to find the maximum average value of any subtree of that tree. So if the tree is like −The output will be 6, this is because, for node 5, it will be (5 + 6 + 1)/ 3 = 4, then for node 6 it will be 6 / 1 = 6, and for node 1, it will be 1 / 1 = 1, so the max is 6.To solve this, we will follow these steps −res := 0Define a method called solve(), this will take rootif root is ... Read More

221 Views
Suppose in an infinite binary tree where every node has two children, the nodes are labelled in row order. Now in the odd numbered rows (the first, third, fifth, ...), the labelling is left to right, and in the even numbered rows (second, fourth, sixth, ...), the labelling is right to left. So the tree will be like −So we have given the label of a node in this tree, we have to find the labels in the path from the root of the tree to the node with that label. So if the input is label = 14, then ... Read More

135 Views
Suppose in a social group, there are N different people, with unique integer ids from 0 to N-1. Here we have a list of logs, where each logs[i] = [time, id_A, id_B] contains a non-negative integer timestamp, and the ids of two different people. Each log is showing the time in which two different people became friends. If A is friends with B, then B is friends with A. Let's say that person A is acquainted with person B if A is friends with B, or A is a friend of someone acquainted with B. We have to find the ... Read More

361 Views
Suppose we have a broken calculator that has a number showing on its display, we can perform only two operations −Double − This will multiply the number on the display by 2, or;Decrement − This will decrease the number that is showing, by 1, Initially, the calculator is displaying the number X. We have to find the minimum number of operations needed to display the number Y.So if the input is like X = 5 and Y is 8, then the output will be 2, as decrement, it once, then double itTo solve this, we will follow these steps −res ... 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

268 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