摘要:
Fun one.. the punch line of this problem is quite common in Bit related problems on HackerRank - visualize it in your mind, and you will find: all bit 阅读全文
摘要:
My first reaction is to have an unlimited length of bit-array, to mark existence. But if no extra mem is allowed, we can simply use 'sign' on each ind 阅读全文
摘要:
The follow-up question is fun: "Could you do it in one-pass, using only O(1) extra memory and without modifying the value of the board?" When we meet 阅读全文
摘要:
There are 3 possible approaches: DP, divide&conquer and greedy. And apparently, DP has O(n^2) complexity (TLE), DivideConquer can only be worse. Greed 阅读全文
摘要:
Another interesting DP. Lesson learnt: how you define state is crucial.. 1. if DP[i] is defined as, longest wiggle(up\down) subseq AT number i, you wi 阅读全文
摘要:
DP or Greedy - they are all in O(n) In editorial, a beautiful Greedy solution is given: "To reach the last cloud in a minimum number of steps, always 阅读全文
摘要:
Another fun Greedy problem to work on: we simply go from first to second last person, as long someone is odd, we distribute bread to her and her next. 阅读全文
摘要:
I use a stack. Of course you can simply trace nodes with 9s - https://leetcode.com/discuss/111127/iterative-two-pointers-with-dummy-node-java-o-n-time 阅读全文
摘要:
A mix of hashmap, list and heap. struct Tw { Tw(long long pts, int tid) { ts = pts; tweetid = tid; } long long ts; int tweetid; }; struct Cmp { bool o 阅读全文
摘要:
Very nice DP problem. The key fact of a mutual-divisible subset: if a new number n, is divisible with the largest number m within a mutual-divisible s 阅读全文