摘要:
Great learning for me:https://www.hackerrank.com/rest/contests/master/challenges/lucky-numbers/hackers/turuthok/download_solution Basically it is memo 阅读全文
摘要:
Nothing special. Just take care of corner cases. class Solution { public: /** * @param head a ListNode * @oaram v1 an integer * @param v2 an integer * 阅读全文
摘要:
Neat DP problem to go. If you don't like log(), you can use lookup table. And, this is an amazing solution: https://leetcode.com/discuss/93501/simple- 阅读全文
摘要:
Nice one. Try to learn the way of thinking, with the help of the below image: https://leetcode.com/discuss/89336/best-submission-searching-for-the-cro 阅读全文
摘要:
Recursion of course. But please make sure you cover all the cases. class Solution(object): # return: max value with node picked, max val w\o node pick 阅读全文
摘要:
Backtrace idea is straightforward. But there are always smarter solutions - like this: https://leetcode.com/discuss/87314/non-recursive-time-space-sol 阅读全文
摘要:
My first reaction was to use Manacher - which is O(n*k*k) - n is the no. of words, and k is the average length of words. Code of Manacher based soluti 阅读全文
摘要:
First problem to learn Max Flow. Ford-Fulkerson is a group of algorithms - Dinic is one of it.It is an iterative process: we use BFS to check augament 阅读全文
摘要:
Here is the mind flow: My intuition was to use Fenwick tree - that works but that's O(nlgn). That's too generalized and the magic number is 3 - that m 阅读全文
摘要:
A typical recursion use: class Solution(object): max_size = 0 # return: isValid, minVal, maxVal, nodeCnt def go(self, root): if root.left is None and 阅读全文
摘要:
Intuitive one to learn about Grundy basic :) Now every pile becomes a game, so we need to use Sprague-Grundy Theory. Calculation is quite intuitive - 阅读全文
摘要:
Please note: VROOK cannot go back-ward - that leads to a simple variation to Game of Nim: just XOR. t = int(input()) for _ in range(t): n = int(input( 阅读全文
摘要:
A variation to 0-1 Knapsack. (No Python code got fully AC. Python is too slow for this problem) #include <cmath> #include <cstdio> #include <vector> # 阅读全文
摘要:
Yes a typical stack based problem. Please take care of corner cases. class Solution { public: bool isValidSerialization(string preorder) { // Get toke 阅读全文
摘要:
I got lost totally - it is a whole range of numbers! Actually, we can check each number within the range and pick it greedily. https://leetcode.com/di 阅读全文
摘要:
This is 'Difficult' - I worked out it within 45mins, and unlocked HackerRank Algorithm Level 80 yeah! So the idea is straight forward: 1. sort the inp 阅读全文