-
LeetCode 871: Minimum Number of Refueling Stops
link Dynamic Programming The optimal refueling would look like a subsequence of (start, stations, target). For each station, we can find how far we can go with different number of refuelings. Then the minimum number of refuelings that gets us to the target is the answer. Time: , space: . Greedy We refuel only if…
-
LeetCode 134: Gas Station
link Time: , space: . For a gas station, the net (gas-cost) >= 0 means we can make it to the next station. Since sum does not depend on the order of the numbers being summed up (commutativity), this also holds for a sequence of gas stations. Therefore, the sum of the nets of a…
-
LeetCode 881: Boats to Save People
link Blind alleys The min and max required boat count must be in . Given a boat count, if in a single scan we could tell if all people can be packed we could use a binary search in that range. But, due to the weight and 2-person per boat restrictions a single sequential scan…
-
LeetCode 55: Jump Game
link As long as all indices (possibly except last index) have positive jumps, we can reach the end. Therefore, only way we may fail to reach the end is: Some index (before the end index) has 0 jump There isn’t an earlier index from which we could jump and skip over this zero-jump index. Like…
-
LeetCode 81: Search in Rotated Sorted Array II
link Time: , space: . If all numbers were distinct, we could find which side of pivot is on by comparing with as below. Here, with duplicates allowed, we reduce the problem to the all-distinct case by making sure .
-
LeetCode 410: Split Array Largest Sum
link Time: , space: Observations: Given a split’s max allowed sum, as we increase max_allowed sum from max(nums) to sum(nums), can_split(max_allowed_sum) evaluates like: False, False, False, True, True, … We want the max_allowed_sum for the left-most True. Given a split’s max_allowed_sum, if we can split nums into 3 subarrays, we can also split nums into…
-
Pushing changes to github repo
ssh-keygen -t ed25519 -C “tanvirdotzaman@gmail.com” cat ~/.ssh/id_ed25519.pub It’s under profile/settings git remote set-url origin git@github.com:mtanviru/ai.git git push -u origin main
-
Why simple questions in number theory feel inscrutable?
Systematic methods in Calculus help solve huge swath of problems. On the other hand, reading through a book on Number Theory feels like every problem has been solved ad hoc, with ingenious insight, why? Guess: Something to do with how numbers are represented in human brain. Why the human brain perceives small numbers better?
-
মিসিরালি
Case studies in abnormal psychology The man who mistook his wife for a hat An anthropologist on mars Sybil The center cannot hold Abnormal psychology An unquiet mind The three faces of eve The boy who was raised as a dog