随笔分类 - GeeksForGeeks
摘要:Given a sorted array of n distinct integers where each integer is in the range from 0 to m - 1 and m > n. Find the smallest number that is missing fro
阅读全文
摘要:Given a Binary Tree, write a function to check whether the given Binary Tree is a prefect Binary Tree or not. A Binary tree is Perfect Binary Tree in
阅读全文
摘要:Given a binary tree, you need to check whether sum of all covered elements is equal to sum of all uncovered elements or not. In a binary tree, a node
阅读全文
摘要:Given an unsorted array of nonnegative integers, find a continous subarray which adds to a given number. Examples: There may be more than one subarray
阅读全文
摘要:Given a binary tree, generate all root to leaf paths of a binary tree. Example: Example Tree The output for the above example is [[1, 2, 4], [1, 2, 5]
阅读全文
摘要:Given A binary Tree, how do you remove all the half nodes (which has only one child)? Note leaves should not be touched as they have both children as
阅读全文
摘要:Given n friends, each one can remain single or can be paired up with some other friend. Each friend can be paired only once. Find out the total number
阅读全文
摘要:The diameter of a tree (sometimes called the width) is the number of nodes on the longest path between two leaves in the tree. The diagram below shows
阅读全文
摘要:Given a binary tree with each node having one extra field of nextRight. nextRight points to the next right node of the same level. Initially all nodes
阅读全文
摘要:Given a Binary Tree, find if there exist edge whose removal creates two trees of equal size. Examples: To find whether such an edge exists, we need to
阅读全文
摘要:Given a binary tree, check whether it is a mirror of itself using both recursion and iterative approach. Examples: Solution 1. Recursion For two trees
阅读全文
摘要:Given a Binary Tree, extract all leaves of it in a Doubly Linked List (DLL). Note that the DLL need to be created in-place. Assume that the node struc
阅读全文
摘要:Consider a game where a player can score 3 or 5 or 10 points in a move. Given a total score n, find the number of ways to reach the given score. Examp
阅读全文
摘要:You are given n pairs of numbers. In every pair, the first number is always smaller than the second number. A pair (c, d) can follow another pair (a,
阅读全文
摘要:Given a binary search tree with the following tree node definition. next points to a node's inorder successor. Populate inorder successor for all node
阅读全文
摘要:Given a binary tree, get all nodes that don't have sibling node, excluding the root node. Level order and pre order solutions.
阅读全文
摘要:Find Maximum Number that can be formed using all digits in the given integer. Solution 1. O(n * log n) runtime, O(n) space using sorting A simple solu
阅读全文
摘要:Given an unsorted array of integers, sort this array using tree sort. 1. Create a binary search tree by inserting array elements. 2. Perform in order
阅读全文
摘要:Given Inorder and Preorder traversals of a binary tree, print Postorder traversal. Example: A naive solution is to first construct the given tree, the
阅读全文
摘要:Give a binary tree, find its minimum depth. The minimum depth is the number of nodes along the shortest path from root node down to the nearest leaf n
阅读全文