原创 Random Number Series Questions

This webpage gives a perfect solution to generate K random numbers from given N size array: http://www.geeksforgeeks.or

原创 LeetCode 356. Line Reflection

very straight forward. #include <vector> #include <iostream> using namespace std; /* Given n points on a 2D plane an

原创 LeetCode 360. Sort Transformed Array

/* Given a sorted array of integers nums and integer values a, b and c. Apply a function of the form f(x) = ax^2 +

原创 Print Boundry Nodes of a binary tree.

void printLeaves(TreeNode* root) { if(root) { printLeaves(root->left); if(!(root->left) && !(root->right)) co

原创 LeetCode 346. Moving Average from Data Stream

Given a stream of integers and a window size, calculate the moving average of all integers in the sliding window. F

原创 Next Larger Value in BST

This question need some clarification of the TreeNode structure.  Suppose the given TreeNode struct is as following: St

原创 K consecutive maxSum

// given an array, find n consecutive number which forms the largest sum. #include "header.h" using namespace std; int

原创 Permute the array according to the given permutation.

Some one posted this interview question asked by Google. #include <vector> #include <string> #include <iostream> using

原创 LeetCode 366. Find Leaves of Binary Tree

Given a binary tree, find all leaves and then remove those leaves. Then repeat the previous steps until the tree is em

原创 Find Closet Pairs -- To be continue

Sweep line algorithm: a vertical line that is conceptually "swept" across the plane. To better understand this algorith

原创 Dynamic Programming series

DP is absolutely the best way to category levels of programming..... and it is always the favourite questions being ask

原创 Sort Stack in increasing/decreasing Order.

Question: Sort a stack in increasing order. Two ways: sort it recursively and use an explicit stack. // solve it recurs

原创 LeetCode 241. Different Ways to Add Parentheses

Given a string of numbers and operators, return all possible results from computing all the different possible ways

原创 K sum

This is an extended question for 2 sum and 3 sum, 4 sum, DP problem. Given n distinct positive integers, integer k (k

原创 Majority Element III

#include <iostream> #include <vector> #include <unordered_map> using namespace std; /* Given an array of integers an