Tony's Log

Algorithms, Distributed System, Machine Learning

  博客园 :: 首页 :: 新随笔 :: 联系 :: 订阅 :: 管理 ::

11 2015 档案

摘要:Taking advantage of 'sparse'class Solution {public: vector> multiply(vector>& A, vector>& B) { vector> ret; int ha = A.si... 阅读全文
posted @ 2015-11-30 07:38 Tonix 阅读(448) 评论(0) 推荐(0)

摘要:Simple data structure but not that easy to figure out.. MHT -> balanced tree.https://leetcode.com/problems/minimum-height-trees/Lesson learnt: Focus o... 阅读全文
posted @ 2015-11-26 16:02 Tonix 阅读(191) 评论(0) 推荐(0)

摘要:A sly knapsack problem in disguise! Thanks tohttps://github.com/bhajunsingh/programming-challanges/tree/master/hackerrank/algorithms/the-indian-jobLes... 阅读全文
posted @ 2015-11-26 08:44 Tonix 阅读(311) 评论(0) 推荐(0)

摘要:I had the same BFS idea as one of the AC code this: because dying pattern is spead from the initial dying ones :)#include #include #include using name... 阅读全文
posted @ 2015-11-26 07:10 Tonix 阅读(1009) 评论(0) 推荐(0)

摘要:Learnt from here:http://www.cnblogs.com/lautsie/p/3798165.htmlIdea is: we union all pure black edges so we get 1+ pure black edge groups. Then we can ... 阅读全文
posted @ 2015-11-26 03:51 Tonix 阅读(246) 评论(0) 推荐(0)

摘要:Very good DP one.First I figured out a O(n^2) solution:class Solution {public: int maxProfit(vector& prices) { int n = prices.si... 阅读全文
posted @ 2015-11-26 02:47 Tonix 阅读(250) 评论(0) 推荐(0)

摘要:[Concepts]Consistent Hashing: instead of MOD, hash() to certain point within 0-2^31. Range based[Logistics\Glue]Zookeeper: locking\service finder\lead... 阅读全文
posted @ 2015-11-25 11:55 Tonix 阅读(135) 评论(0) 推荐(0)

摘要:Actually I think problem statement is somewhat misleading. No need to mention range [L, R] at all.The intention is a variation to "Largest Rectangle" ... 阅读全文
posted @ 2015-11-23 15:49 Tonix 阅读(254) 评论(0) 推荐(0)

摘要:2D Segment Tree -> Quad Tree. class Node // 2D Segment Tree { public: Node(vector> &m, int ix0, int iy0, int ix1, int iy1) ... 阅读全文
posted @ 2015-11-23 06:43 Tonix 阅读(414) 评论(0) 推荐(0)

摘要:The most interesting, flexible and juicy binary tree problem I have ever seen.I learnt it from here: https://codepair.hackerrank.com/paper/5fIoGg74?b=... 阅读全文
posted @ 2015-11-22 12:51 Tonix 阅读(476) 评论(0) 推荐(0)

摘要:XOR -> 0 is the key (make it even pair): http://www.cnblogs.com/lautsie/p/3908006.htmlSomething to learn about basic Game Theory: http://www.cdf.toron... 阅读全文
posted @ 2015-11-22 11:56 Tonix 阅读(191) 评论(0) 推荐(0)

摘要:A typical game theory problem - Recursion + Memorized Searchhttp://justprogrammng.blogspot.com/2012/06/interviewstreet-challenges-permutation.html#.Vl... 阅读全文
posted @ 2015-11-22 10:34 Tonix 阅读(286) 评论(0) 推荐(0)

摘要:Same as LintCode "Sliding Window Median", but requires more care on details - no trailing zeroes.#include #include #include #include #include #include... 阅读全文
posted @ 2015-11-21 14:38 Tonix 阅读(227) 评论(0) 推荐(0)

摘要:Something to learn: Rotation ops in AVL tree does not require recursion.https://github.com/andreimaximov/hacker-rank/blob/master/data-structures/tree/... 阅读全文
posted @ 2015-11-21 13:42 Tonix 阅读(292) 评论(0) 推荐(0)

摘要:Something to learn:http://blog.csdn.net/yuwenshi/article/details/36666453Shortest Job First Algorithm - kinda greedy: we do shorter job first BUT we o... 阅读全文
posted @ 2015-11-19 07:20 Tonix 阅读(441) 评论(0) 推荐(0)

摘要:Regular Union-Find practice one.#include #include #include #include #include #include #include #include #include using namespace std;unordered_map ps;... 阅读全文
posted @ 2015-11-19 06:02 Tonix 阅读(308) 评论(0) 推荐(0)

摘要:Fenwick tree can do this job.class NumArray { vector in; vector ft; int query(int i) { i += 1; i = min(i, int(ft.size() - 1... 阅读全文
posted @ 2015-11-19 04:01 Tonix 阅读(264) 评论(0) 推荐(0)

摘要:A natural DFS thought. Several pruning tricks can be applied. Please take care of date type(long long).class Solution { bool _check(string a, strin... 阅读全文
posted @ 2015-11-19 03:08 Tonix 阅读(318) 评论(0) 推荐(0)

摘要:* Non-intuitive state designclass Solution {public: /** * @param A an integer array * @param k an integer * @return an integer */ ... 阅读全文
posted @ 2015-11-17 14:25 Tonix 阅读(735) 评论(0) 推荐(0)

摘要:DFS + Memorized Search (DP)class Solution { int dfs(int i, int j, int row, int col, vector>& A, vector>& dp) { if(dp[i][j] != 0) retu... 阅读全文
posted @ 2015-11-16 03:45 Tonix 阅读(274) 评论(0) 推荐(0)

摘要:https://codesolutiony.wordpress.com/2015/05/24/lintcode-coins-in-a-line-iii/A very juicy one! Deserve more consideration.class Solution {public: /*... 阅读全文
posted @ 2015-11-15 13:25 Tonix 阅读(301) 评论(0) 推荐(0)

摘要:Yes the accu* is not necessary :)class NumMatrix { vector> dp;public: NumMatrix(vector> &matrix) { int h = matrix.size(); if(!h) ret... 阅读全文
posted @ 2015-11-14 10:19 Tonix 阅读(119) 评论(0) 推荐(0)

摘要:Here is the thought flow: we are trying 'find' the boundary - it is a search, so binary search.class Solution { bool isRowHit(vector>& image, int r) ... 阅读全文
posted @ 2015-11-14 08:08 Tonix 阅读(225) 评论(0) 推荐(0)

摘要:Nice one to learn: DP + Game Theoryhttps://lefttree.gitbooks.io/leetcode/content/dynamicProgramming2/coinsInLine2.htmlIn game theory, we assume the ot... 阅读全文
posted @ 2015-11-09 12:57 Tonix 阅读(213) 评论(0) 推荐(0)

摘要:1AC! Yes! Intuitive thought will be: we walk from up-left to down-right - but we should only walk along the 'lowest edge' in the sorted matrix - so it... 阅读全文
posted @ 2015-11-06 15:50 Tonix 阅读(266) 评论(0) 推荐(0)

摘要:DFS with pruning. The thought flow: for each char, we have 2 choices: pick or not - then DFS.class Solution { int len; unordered_set rec; vector ... 阅读全文
posted @ 2015-11-05 06:36 Tonix 阅读(329) 评论(0) 推荐(0)

摘要:Simply a variation to "Permutation Index". When calculating current digit index, we consider duplicated case.Again, similar as "Digit Counts", it is a... 阅读全文
posted @ 2015-11-04 08:56 Tonix 阅读(304) 评论(0) 推荐(0)

摘要:Lesson learnt: one effective solution for bit\digit counting problems: counting by digit\bithttp://www.hawstein.com/posts/20.4.htmlclass Solution {pub... 阅读全文
posted @ 2015-11-04 07:31 Tonix 阅读(226) 评论(0) 推荐(0)