自定义博客皮肤VIP专享

*博客头图:

格式为PNG、JPG,宽度*高度大于1920*100像素,不超过2MB,主视觉建议放在右侧,请参照线上博客头图

请上传大于1920*100像素的图片!

博客底图:

图片格式为PNG、JPG,不超过1MB,可上下左右平铺至整个背景

栏目图:

图片格式为PNG、JPG,图片宽度*高度为300*38像素,不超过0.5MB

主标题颜色:

RGB颜色,例如:#AFAFAF

Hover:

RGB颜色,例如:#AFAFAF

副标题颜色:

RGB颜色,例如:#AFAFAF

自定义博客皮肤

-+

ActiveCoder的博客

Algorithms seen

  • 博客(354)
  • 收藏
  • 关注

原创 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 recursivelyvoid insertToStack(stack& s, int value) { if(s.empty() || s.top() <= val

2016-08-07 04:37:36 431

原创 Delete node in BST

Question: delete the given value in BST.This question is pretty tricky, to delete a node in BST, there are several cases to consider.1: The node one of the leavesin this case, it is easy, ju

2016-08-06 07:04:23 379

原创 Observer Pattern

Observer Pattern: defines a one-to-many dependency between objects so that when one object changes state, all of its dependent are notified and updated automatically.The relationship is defined as f

2016-08-05 12:06:32 319

原创 Decorating Pattern

Decorate pattern is to give objects new responsibilities without making any code change to the underlying classes. The Decorator Pattern attaches additional responsibilities to an object dynamically.

2016-08-03 12:57:39 355

原创 Command Pattern

Command Pattern is usually used in the scenario that we want to perform multiple operations on the same data. For example, in a image processor, we could choose to rotate, flip or invert colors of the

2016-08-02 05:23:22 315

原创 Virtual Table -- C++

Vtables is also known as many different names: virtual function table, virtual method table, and even as a dispatch table.Usage of Vtables: Polymorphismwhen working with virtual function in C++, i

2016-08-01 22:58:35 414

原创 Strategy Pattern

The strategy pattern is to take the parts that vary and encapsulation them, so that later you can alter or extend the parts that vary without affecting those that don't.In the head first design patt

2016-08-01 12:28:52 264

原创 Balanced Partition of Array

Given an array which contains random positive integers, divide the array into two parts which has the smallest diff sum, return the smallest diff sum.This problem is solvable using dynamic programmi

2016-07-27 12:32:47 525

原创 LeetCode 375. Guess Number Higher or Lower II

We are playing the Guess Game. The game is as follows:I pick a number from 1 to n. You have to guess which number I picked.Every time you guess wrong, I'll tell you whether the number I pi

2016-07-26 03:51:16 574

原创 374. Guess Number Higher or Lower

We are playing the Guess Game. The game is as follows:I pick a number from 1 to n. You have to guess which number I picked.Every time you guess wrong, I'll tell you whether the number is h

2016-07-25 23:47:02 235

原创 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 empty.Example:Given binary tree  1 / \ 2 3

2016-07-25 23:29:15 307

原创 Maximum array distance Sum

Question: Given an array, find the maximum array distance sum. Array distance sum is defined as below. For any 0 For example, Given array {0, 2, -1}A[0][0] = 0, A[0][1] = 3, A[0][2] = 1; A[1][1] =

2016-07-25 12:46:31 234

原创 Dynamic Programming series

DP is absolutely the best way to category levels of programming..... and it is always the favourite questions being asked by FB or Google.1: Entry Level DP problem.    /* A sequence of numbers i

2016-07-21 07:08:54 292

原创 TODO: house robber IIII

TODO: when rob one, the neighbour explored, get the max rob value.

2016-07-20 11:27:42 253

原创 TODO: System design a recommendation system

TODO: design a recommendation system.

2016-07-18 10:40:43 302

原创 Shuffle related problem.

Shuffle is quite a frequently asked question in interviews. The most famous one is shuffle a deck of cards.Peiyush Jain, 2004 published a paper "A simple in-place Algorithm for in-Shuffle". However

2016-07-18 09:59:05 602

转载 Haffman Encoding and Decoding

Read this blog and it seems this is a quite decent interview question. Haffman encodingHaffman encoding is  a classic way to encode characters. It encodes characters according to building an optimis

2016-07-18 06:27:49 294

原创 Find Closet Pairs -- To be continue

1: Find closet pair number in an given array2: Find closet pair of points in an array of given points.3: Given a set of triangles, find the most overlapped points.  (TODO: Will update them on July

2016-07-09 12:00:42 367

原创 Subarray Sum to the given target value

Question: check if there is a subarray sum equals to the given target.This question should ask for clarifications. Whether the inputs are all positive, or it has negative numbers.1: If all the num

2016-07-07 06:13:00 545

原创 Primes Product

Maybe think about how to solve it iteratively??#include "header.h"using namespace std;void primeProduct(vector& nums, vector& res, int product, int pos) { if(pos > nums.size()) { return;

2016-07-07 02:15:08 308

原创 Random Number Series Questions

This webpage gives a perfect solution to generate K random numbers from given N size array: http://www.geeksforgeeks.org/reservoir-sampling/However, there are a varieties of related questions.1: i

2016-07-06 07:59:24 252

原创 Next Larger Value in BST

This question need some clarification of the TreeNode structure. Suppose the given TreeNode struct is as following:Struct TreeNode {int val;TreeNode* left;TreeNode* right;TreeNode(int v) :

2016-07-06 04:41:31 292

原创 K consecutive maxSum

// given an array, find n consecutive number which forms the largest sum.#include "header.h"using namespace std;int maxConsecutive(vector& array, int n) { if(n <= 0) return 0; vector dp(array.

2016-07-05 11:58:04 253

原创 Read Buffer II

The API: int read4(char *buf) reads 4 characters at a time from a file.The return value is the actual number of characters read. For example, it returns 3 if there is only 3 characters left in the

2016-06-23 13:01:15 508

原创 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.For example,MovingAverage m = new MovingAverage(3);m.next(1) = 1m.next(10) = (1

2016-06-20 12:09:05 413

转载 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 to group numbers and operators. The valid operators are +, - and *.Example 1

2016-06-20 11:51:48 229

原创 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 + bx + c to each element x in the array. The return array must be in sorted order

2016-06-19 11:16:06 593

原创 LeetCode 361. Bomb Enemy

We have a 2D grid. Each cell is either a wall, an enemy or empty.For example (0-empty, X-enemy, Y-wall):0 X 0 0X 0 Y X0 X 0 0You have one bomb and you want to kill as many as possible ene

2016-06-19 07:56:50 1985

原创 LeetCode 115. Distinct Subsequences

#include #include #include using namespace std;// for example, S = "ABCDE", P = "AEC" --> return 1// for example: S = "rabbbit", P = "rabbit" --> return 3.int distinctSubsequences(string s, st

2016-06-19 06:52:09 192

原创 Permute the array according to the given permutation.

Some one posted this interview question asked by Google.#include #include #include using namespace std;// array permutation according to the given permutation/* Given permutation {3, 2, 1, 0

2016-06-19 04:35:32 435

原创 LeetCode 356. Line Reflection

very straight forward.#include #include using namespace std;/* Given n points on a 2D plane and find if there is such a line parallel to y-axis that reflect the given set of points. Example:

2016-06-17 04:17:29 700

原创 LeetCode 358. Rearrange String k Distance Apart

1: First thought: brute force. Get all the permutations and check permutations one by one./* Given a non-empty str and an integer k, rearrange the string such that the same characters are at lea

2016-06-17 01:06:10 941

原创 Majority Element III

#include #include #include using namespace std;/* Given an array of integers and a number K, the majority number is the number that occurs more than 1/k if the size of the array. Note: ther

2016-06-16 23:43:59 272

原创 LeetCode 357. Count Numbers with Unique Digits

Given a non-negative integer n, count all numbers with unique digits, x, where 0 ≤ x n.Example:Given n = 2, return 91. (The answer should be the total numbers in the range of 0 ≤ x < 100, excludin

2016-06-16 11:22:20 197

原创 Design HashMap.

// use linked list for chaining.class LinkedHashEntry {private: int key; int value; LinkedHashEntry* next;public: LinkedHashEntry(int key, int value) { this->key = key; this->va

2016-06-16 07:32:44 249

原创 Print Boundry Nodes of a binary tree.

void printLeaves(TreeNode* root) { if(root) { printLeaves(root->left); if(!(root->left) && !(root->right)) cout val << endl; printLeaves(root->right); }}void PrintBoundryRight(TreeN

2016-06-16 05:11:19 203

原创 K sum

This is an extended question for 2 sum and 3 sum, 4 sum, DP problem int kSum(vector A, int k, int target) { // wirte your code here int n = A.size(); vector>> dp(n+1, vect

2016-06-15 12:38:59 203

原创 Find the Thief (Facebook Interview)

Suppose there is a thief and n rooms.We can only any door to check whether the thief is there or not. during the night, the theif can either move left one room or right one room. Given a sequence of

2016-06-15 07:26:35 625

转载 LeetCode 166. Fraction to Recurring Decimal

So, the best solution I have seen. 点击打开链接Integer part is easy to handle. For the fraction part, we need to remember where the loop start. Thus, we need to remember the position to insert '(' and

2016-06-13 04:18:13 273

原创 LeetCode 163. Missing Ranges

Two pointers.#include #include #include using namespace std;/* Given a sorted integer array where the range of element are [lower, upper] inclusive, return its missing ranges. For example

2016-06-13 02:54:05 265

空空如也

空空如也

TA创建的收藏夹 TA关注的收藏夹

TA关注的人

提示
确定要删除当前文章?
取消 删除