Medium level Intuition: We can buy and sell any time without penalty, so it's intuitive to just loop and if the price difference is positive between two consecutive days, we assume we'll hold the stock ( or buy the stock the day before ), and sell the day before otherwise. The question also only asks for the total profit, not the date when the stocks are bought and sold. So a simple greedy algor..
Programming/Algorithm
Medium level Intuition: It seems like a trivial question. I can just slice the array into two subarrays, and reference the input list to point to a combination of the two subarrays. My solution: class Solution: def rotate(self, nums: List[int], k: int) -> None: """ Do not return anything, modify nums in-place instead. """ n = len(nums) k = k % n nums[..
Medium level Intuition: Seems like a straight forward question (leaning to an easy level). Since in Python you can't alter the legth of the array, we are going to iterate the given array while tracking the duplicate numbers, the position to insert, and the compared number. My Solution: class Solution: def removeDuplicates(self, nums: List[int]) -> int: tmp = 0 idx = 1 dup = False for i, num in e..
Medium Intuition: The problem might seem like a search problem at first because you are looking for a possible leap paths to the final index. But really, you just have to return the boolean value, so by thinking about maximum possible jumps, one can do this in linear time easily. Feels like some kind of greedy algorithm will work here. My solution: class Solution: def canJump(self, nums: List[in..