[Leetcode]188. Best Time to Buy and Sell Stock IV

LeetCode_logo

This series of Buy and Sell Stock I~VI on Leetcode is a great practice for Dynamic Programming – State Machine. Therefore I prepared blogs for each of them and hopefully it would help you to understand them better. You can find the relations of them at the bottom and feel free to leave any comments. 

Continue reading “[Leetcode]188. Best Time to Buy and Sell Stock IV”

[Leetcode]123. Best Time to Buy and Sell Stock III

LeetCode_logo

This series of Buy and Sell Stock I~VI on Leetcode is a great practice for Dynamic Programming – State Machine. Therefore I prepared blogs for each of them and hopefully it would help you to understand them better. You can find the relations of them at the bottom and feel free to leave any comments. 

Continue reading “[Leetcode]123. Best Time to Buy and Sell Stock III”

[Leetcode]1537. Get the Maximum Score

LeetCode_logo
You are given two sorted arrays of distinct integers nums1 and nums2.valid path is defined as follows:
Choose array nums1 or nums2 to traverse (from index-0).
Traverse the current array from left to right.
If you are reading any value that is present in nums1 and nums2 you are allowed to change your path to the other array. (Only one repeated value is considered in the valid path).
Score is defined as the sum of uniques values in a valid path.
Return the maximum score you can obtain of all possible valid paths.
Since the answer may be too large, return it modulo 10^9 + 7.
Continue reading “[Leetcode]1537. Get the Maximum Score”

[Leetcode]1510. Stone Game IV

LeetCode_logo
Alice and Bob take turns playing a game, with Alice starting first.
Initially, there are n stones in a pile.  On each player's turn, that player makes a move consisting of removing any non-zero square numberof stones in the pile.
Also, if a player cannot make a move, he/she loses the game.
Given a positive integer n. Return True if and only if Alice wins the game otherwise return False, assuming both players play optimally.
Continue reading “[Leetcode]1510. Stone Game IV”

[Leetcode]212. Word Search II

Given a 2D board and a list of words from the dictionary, find all words in the board.
Each word must be constructed from letters of sequentially adjacent cell, where "adjacent" cells are those horizontally or vertically neighboring. The same letter cell may not be used more than once in a word.
Example:
Input: board = 
[ ['o','a','a','n'], 
  ['e','t','a','e'], 
  ['i','h','k','r'], 
  ['i','f','l','v'] ] 
words = ["oath","pea","eat","rain"] 
Output: ["eat","oath"]
Continue reading “[Leetcode]212. Word Search II”