随笔分类 -  GeeksForGeeks

摘要:Write a function to print spiral order traversal of a binary tree. For below tree, function should print 1, 2, 3, 4, 5, 6, 7. Solution. For a normal l 阅读全文
posted @ 2017-08-18 13:49 Review->Improve 阅读(377) 评论(0) 推荐(0)
摘要:Given an array with n distinct elements, convert the given array to a form where all elements are in range from 0 to n-1. The order of elements is sam 阅读全文
posted @ 2017-08-17 06:05 Review->Improve 阅读(373) 评论(0) 推荐(0)
摘要:Given a sorted array, this array is rotated by some unknown times. Find if there is a pair in this array that sums to a given value. Solution 1. O(n * 阅读全文
posted @ 2017-08-17 05:41 Review->Improve 阅读(341) 评论(0) 推荐(0)
摘要:Write a program to delete a tree. Solution. To delete all tree nodes, we need to set all non-leaf nodes' children nodes to null. So for a given non-le 阅读全文
posted @ 2017-08-16 09:53 Review->Improve 阅读(161) 评论(0) 推荐(0)
摘要:Write a function to detect if two trees are isomorphic. Two trees are called isomorphic if one of them can be obtained from other by a series of flips 阅读全文
posted @ 2017-08-16 09:42 Review->Improve 阅读(280) 评论(0) 推荐(0)
摘要:Given a binary tree, where every node value is a number . Find the sum of all the numbers which are formed from root to leaf paths. For example consid 阅读全文
posted @ 2017-08-16 03:25 Review->Improve 阅读(214) 评论(0) 推荐(0)
摘要:Given an array, find the minimum length unsorted subarray. After soring this unsorted subarray, the whole array is sorted. Example, if the input array 阅读全文
posted @ 2017-08-12 13:48 Review->Improve 阅读(200) 评论(0) 推荐(0)
摘要:Given an array of integers, write a program that cyclically rotates the array by one. Example: given {1,2,3,4,5}, your program should rotate the array 阅读全文
posted @ 2017-08-12 08:01 Review->Improve 阅读(310) 评论(0) 推荐(0)
摘要:Given a binary tree, convert it to its mirror tree. Mirror of a binary tree T is another binary tree M with the left and right children of all non-lea 阅读全文
posted @ 2017-08-10 02:42 Review->Improve 阅读(438) 评论(0) 推荐(0)
摘要:Given a singly linked list whose nodes contain an integer as their keys. All keys are distinct. Swap the node that has key x with the node that has ke 阅读全文
posted @ 2017-08-09 07:24 Review->Improve 阅读(172) 评论(0) 推荐(0)
摘要:Given an array, write a program to generate a random permuation of array elements. This question is also asked as "shuffle a deck of cards" or "random 阅读全文
posted @ 2017-08-08 02:48 Review->Improve 阅读(151) 评论(0) 推荐(0)
摘要:Given a binary tree, find the maximum depth or height of this tree. Solution 1. In order traversal to count the maximum depth 1 import java.util.Linke 阅读全文
posted @ 2017-08-08 02:27 Review->Improve 阅读(232) 评论(0) 推荐(0)
摘要:Given a BST whose keys are integers. Find the inorder successor and predecessor of a given key. In case the given key is not found in the BST, return 阅读全文
posted @ 2017-08-08 02:05 Review->Improve 阅读(408) 评论(0) 推荐(0)
摘要:Given a sorted array. Write a program that creates a Balanced Binary Search Tree using array elements. If there are n elements in array, then floor(n/ 阅读全文
posted @ 2017-08-04 00:45 Review->Improve 阅读(230) 评论(0) 推荐(0)
摘要:Given a Binary Tree, Print the corner nodes at each level. The node at the leftmost and the node at the rightmost. For example, output for following i 阅读全文
posted @ 2017-08-03 11:42 Review->Improve 阅读(285) 评论(0) 推荐(0)
摘要:A Maze is given as N*N binary matrix of blocks where source block is the upper left most block i.e., maze[0][0] and destination block is lower rightmo 阅读全文
posted @ 2017-08-01 07:03 Review->Improve 阅读(820) 评论(0) 推荐(0)
摘要:Give a number n, check if it is a fibonacci number. Solution 1. Generate a sequence of fibonacci number until we have a fibonacci number that is eithe 阅读全文
posted @ 2017-08-01 00:48 Review->Improve 阅读(144) 评论(0) 推荐(0)
摘要:Given an unsorted array, find the largest pair sum. Solution 1. O(n*logn) runtime, using sorting Solution 2. O(n) runtime, using heapify (max priority 阅读全文
posted @ 2017-07-22 05:17 Review->Improve 阅读(251) 评论(0) 推荐(0)
摘要:Given a string, reverse it without using any temporary variables. This problem is a variation of the problem swapping two integers without using any t 阅读全文
posted @ 2017-07-22 01:03 Review->Improve 阅读(162) 评论(0) 推荐(0)
摘要:Given an integer x, write a method that multiplies x with 3.5 and returns the integer result. You are not allowed to use %, /, or *. Examples: input 2 阅读全文
posted @ 2017-07-20 06:53 Review->Improve 阅读(130) 评论(0) 推荐(0)