楼主: Lingzhi..0614
跳转到指定楼层
上一主题 下一主题
收起左侧

2020秋招- 刷题-项目-OOD-System Design

🔗
 楼主| Lingzhi..0614 2020-3-24 22:54:07 | 只看该作者
全局:
vivalaviiida 发表于 2020-3-23 04:22
关注。楼主对做项目有什么规划吗?

我之前做过一些项目准备复习下之前的项目, 你有什么想法吗?
回复

使用道具 举报

🔗
 楼主| Lingzhi..0614 2020-3-26 14:37:27 | 只看该作者
全局:
3-25
reviewed :
1392. Longest Happy Prefix
1391. Check if There is a Valid Path in a Grid
17. Letter Combinations of a Phone Number
39. Combination Sum
40. Combination Sum II
77. Combinations
78. Subsets
90. Subsets II
216. Combination Sum III
46. Permutations
47. Permutations II
307. Range Sum Query - Mutable
739. Daily Temperatures
901. Online Stock Span
907. Sum of Subarray Minimums

Today finished questions:
37. Sudoku Solver
      use dfs method, every time we need to check whether curren position is valid with O(1) time complexity
       use rows, cols, boxs to record current used values for cur cecll. remember for boxs index = 3*(i/3)+j/3;
51. N-Queens
       use dfs method, need to check whether current position is valid with O(1), use rows, cols, p1, p-1 to help check valid or not.
52. N-Queens II
79. Word Search
       need to be carefull, dfs is much eaiser.(because only when we use that position we marked it, if only visited we should not mark it) example
          a,b                  acdb
          c, d
         n level, each level 4 branch, if match, we mark it, and then 吐出来
回复

使用道具 举报

🔗
 楼主| Lingzhi..0614 2020-3-27 14:52:07 | 只看该作者
全局:
3-26
reviewed:
37. Sudoku Solver
51. N-Queens
52. N-Queens II
79. Word Search
1019. Next Greater Node In Linked List
239. Sliding Window Maximum
1018. Binary Prefix Divisible By 5

Today new questions:
212. Word Search II
        step 1: use trie to construct the word dictionary
        step 2: for each point in matrix, we start search it in trie.
                   if is null, not found.
                   if is word, add to res, and mark not word(add only once) then go to four directions.
127. Word Ladder
        calculate the shortest path --> BFS
         need to deplicate the visited node and use level by level.
126. Word Ladder II
         need to calculate all path. Thoughts: if we use bfs with word ladder1 to calculate each string's previous possible string, then we can construct the path by going backwords
         Step 1: use bfs to calculate the premap. And also need use level to calculate the min steps token to reach this string.
                      if we don't use level, we will miss a string with two parents.
          Step2 : use dfs to construct the path.
                  how many level, we we don't have parents
                    bow many branches: based on how many pparents in premap.
                     store the path, only when we reach at the beginning.
回复

使用道具 举报

🔗
 楼主| Lingzhi..0614 2020-3-29 02:37:03 | 只看该作者
全局:
3-27
reviewed:
784. Letter Case Permutation
943. Find the Shortest Superstring
996. Number of Squareful Arrays
22. Generate Parentheses
301. Remove Invalid Parentheses
212. Word Search II
127. Word Ladder
126. Word Ladder II

finished Questions:
752. Open the Lock
         solution: traditional BFS, use level order, minimum steps and cost is 1 ----> BFS
          expand: visited the element in the same level
          generate:  generate the next possible val,  if not visited and not deadend we push to queue and mark
          deduplicate: use visited to mark
818. Race Car
        minimum step -----> BFS
        method 1:
          use queue to store the (pos. speed)
         expand:  visited the elements in this level
         generate: generate next possibble elements based on speed and pos
         deduplicate: use hashset to deduplicate, and make sure  generated pos is in [0, 2*target]

         method 2: dp
         dp[i] : the minimum instructions to make from 0 to i pos, initial speed is i, directions to i.
          base case dp[0] =0;
           induction rule:
               n = (int)(Math.log(target)/Math.log(2)) +1
            case 1: if target == 2^n -1; we take accerate n times(A^n) reached target, dp[target] =n;
            case 2: it (2^n -1 )> target. we needt to rever and then subproble
                    dp[target] = n+1 + dp[2^n-1-target]
            case 3: if we take n-1 , reach the nearest pos to target, and then reverse and then go back k step and then reverse
                     dp[target]= n-1 + 1 + k + 1 + dp[target+2^k-2^(n-1)]              0<=k<n-1
                                          A(n-1)+ R + A(k) + R
回复

使用道具 举报

全局:
马克,同开始刷题
回复

使用道具 举报

🔗
 楼主| Lingzhi..0614 2020-3-29 14:33:20 | 只看该作者
全局:
本帖最后由 Lingzhi..0614 于 2020-3-29 14:39 编辑

3-28
reviewed :
726. Number of Atoms
736. Parse Lisp Expression
394. Decode String
856. Score of Parentheses
1392. Longest Happy Prefix
1391. Check if There is a Valid Path in a Grid
17. Letter Combinations of a Phone Number
39. Combination Sum
40. Combination Sum II
77. Combinations
78. Subsets
90. Subsets II
216. Combination Sum III
46. Permutations
47. Permutations II
37. Sudoku Solver
51. N-Queens
52. N-Queens II
79. Word Search

Today contest and problems
542. 01 Matrix
            method 1: starts from all 0,  do BFS level by level, if we reached 1 we mark it and then goes on             method 2 :
                    dp[i][j] : the minimum step to reach nearest 0,
                         case1 : matrix[i][j] ==0 dp[i][j] = 0
                          case 2 : matrix[i][j] == 1 , dp[i][j] = Math.min(dp[i-1][j],dp[i+1][j], dp[i][j+1],dp[i][j-1]) +1;
934. Shortest Bridge

              step 1: if we first meet 1, we mark all its connected islands as two, and offer all position in 2 island to queue
              step 2: use bfs , to calculte the step to 1 island.









更多图片 小图 大图
组图打开中,请稍候......
回复

使用道具 举报

🔗
 楼主| Lingzhi..0614 2020-3-30 13:58:47 | 只看该作者
全局:
3-29
reviewed
212. Word Search II
127. Word Ladder
126. Word Ladder II
542. 01 Matrix
934. Shortest Bridge

Today :
675. Cut Off Trees for Golf Event
      solutions: first get the all trees height and their index,  and use priorityqueue sort them, and then calculate the steps for (x,y) [height n] ---> (r,c) [height n+1], and add to sum.
698. Partition to K Equal Sum Subsets
     solutions:
           step 1: calculate the sum/k
           step 2:  how many levels : k,
                        how many branches: if idx not visited and cur_sum+ nums[idx] <= target , we can go down. worst case is O(n)
93. Restore IP Addresses
                how many levels : 4 levels means 4 groups
                how many branches : in each level, we can get [idx, idx+1), [idx, idx+2), [idx, idx+3),
                                                  if( val starts with 0 and len > 1 like 01, 02, 05, 010, 015
                                                         or val >255, there are invalid , we should return.
131. Palindrome Partitioning
              we can combine isPalindrome with DFS.
              how many levels: we don't know , but if idx == length, we shoul strop
              how many branches; we don't know,but if [start, end] is palindrome we can continue.  start<= end< len.
             dp[i][j] is palindrome if s[i] == s[j ] AND i+1 >= j-1 true
                                                OR  s[i] == s[j ], dp[i+1][j-1] = true;
241. Different Ways to Add Parentheses
           it is a recursion problem, like how to split the string 2*3-4*5  ---> ways(2) 【*】ways(3-4*5)   ,  ways(2*3) 【-】ways(4*5),     ways(2*3-4) 【*】ways(5),
              base case : if ways(x), x is number no +,-,*, we add the x to res;
              recursive, for each +,-,* we get List<Integer> left, List<Integer> right, and combine them.

              deduplicate stroe HashMap<Stinrg, List<Integer>>, to avoid multi calculate e.g ways(4*5);
回复

使用道具 举报

🔗
 楼主| Lingzhi..0614 2020-3-31 14:47:27 | 只看该作者
全局:
3-30
reviewed:
208. Implement Trie (Prefix Tree)
648. Replace Words
676.Implement Magic Dictionary
677. Map Sum Pairs
784. Letter Case Permutation
943. Find the Shortest Superstring
996. Number of Squareful Arrays
22. Generate Parentheses
301. Remove Invalid Parentheses
675. Cut Off Trees for Golf Event
698. Partition to K Equal Sum Subsets
93. Restore IP Addresses
131. Palindrome Partitioning
241. Different Ways to Add Parentheses


Today:
282. Expression Add Operators
      solution: use dfs for each position we can add +,-,* or ' ', e.g 12 ---> 1+2, 1-2, 1*2, 1 2.
                            and also calculate the values based on the previous sum.
        how many level: n-1 levels
        how many branches for each level we have 4 operators, and we can get at  most n values, e.g 122 -> 1, 12, 122,
dfs(nums, target, exp, idx, prenode, cursum,res)
       prenode is used to deal with * e.g 1+2*3   (*4), we need to make prenode = 2*3
       case 1: 1+2 (+3) prenode 2, cur_sum = 3, nextprenode 3, nextsum = cursum+3
       case 2: 1+2 (-3) prenode 2, cur_sum = 3, nextprenode -3, nextsum = cursum+(-3)
       case 3: 1+2 (*3) prenode 2, cur_sum = 3, nextprenode = prenode*3, nextsum = cursum - prenode + prenode*3

special case : if meet values 0xxx....., ignore,
                      if we are dealing the head, we should not add operators
                      need to be able to optimize the time and space complexity use global char[] to represent exp( key is use L to record the oprator position)

回复

使用道具 举报

🔗
 楼主| Lingzhi..0614 2020-4-1 14:45:19 | 只看该作者
全局:
3-31
reviewed :
37. Sudoku Solver
51. N-Queens
52. N-Queens II
79. Word Search
542. 01 Matrix
934. Shortest Bridge
282. Expression Add Operators
842. Split Array into Fibonacci Sequence

Today:  reviewed DP problems
746. Min Cost Climbing Stairs
70. Climbing Stairs
1137. N-th Tribonacci Number
303. Range Sum Query - Immutable
121. Best Time to Buy and Sell Stock
53. Maximum Subarray
         solution: low[i] : the lowest buy price up to ith day low[i]=min( low[i-1], arr[i]);
                        profit[i]: we can sell on this day or not profit[i] = math.max(profit[i-1], arr[i] -low[i]);
1218. Longest Arithmetic Subsequence of Given Difference
                   dp[i] the length of arithemetic sequence that ends with arr[i]
                   dp[i] = dp[arr[i]- diff] +1 if arr[i]-diff exist
                             else 1.

For one dimentioanl DP problem
the smallest elements are same, cur rope.
                                           similar, cur words
  for subarray, subsequence, try to cover ith position.
sometime we need to redefine the physical meanning of DP[i]
回复

使用道具 举报

🔗
 楼主| Lingzhi..0614 2020-4-2 14:21:50 | 只看该作者
全局:
4-1
720. Longest Word in Dictionary
745. Prefix and Suffix Search
211. Add and Search Word - Data structure design
212. Word Search II
127. Word Ladder
126. Word Ladder II
675. Cut Off Trees for Golf Event
698. Partition to K Equal Sum Subsets
93. Restore IP Addresses
131. Palindrome Partitioning
241. Different Ways to Add Parentheses

Today 62. Unique Paths
63. Unique Paths II
64. Minimum Path Sum
120. Triangle
very straight forward dp problem, base on the problem definition we can define dp[i][j] or dp[i]
回复

使用道具 举报

您需要登录后才可以回帖 登录 | 注册账号
隐私提醒:
  • ☑ 禁止发布广告,拉群,贴个人联系方式:找人请去🔗同学同事飞友,拉群请去🔗拉群结伴,广告请去🔗跳蚤市场,和 🔗租房广告|找室友
  • ☑ 论坛内容在发帖 30 分钟内可以编辑,过后则不能删帖。为防止被骚扰甚至人肉,不要公开留微信等联系方式,如有需求请以论坛私信方式发送。
  • ☑ 干货版块可免费使用 🔗超级匿名:面经(美国面经、中国面经、数科面经、PM面经),抖包袱(美国、中国)和录取汇报、定位选校版
  • ☑ 查阅全站 🔗各种匿名方法

本版积分规则

>
快速回复 返回顶部 返回列表