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

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

🔗
 楼主| Lingzhi..0614 2020-4-3 14:48:57 | 只看该作者
全局:
4-2
307. Range Sum Query - Mutable
739. Daily Temperatures
901. Online Stock Span
907. Sum of Subarray Minimums
752. Open the Lock
818. Race Car
282. Expression Add Operators
842. Split Array into Fibonacci Sequence

Today:
174. Dungeon Game from bottom to top.
931. Minimum Falling Path Sum(like triangle)
1210. Minimum Moves to Reach Target with Rotations (this is bad problem for me)
回复

使用道具 举报

🔗
 楼主| Lingzhi..0614 2020-4-6 15:26:42 | 只看该作者
全局:
4-6
reviewed:
174. Dungeon Game
931. Minimum Falling Path Sum
1210. Minimum Moves to Reach Target with Rotations
62. Unique Paths
63. Unique Paths II
64. Minimum Path Sum
120. Triangle
282. Expression Add Operators
842. Split Array into Fibonacci Sequence
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
1019. Next Greater Node In Linked List
239. Sliding Window Maximum
1018. Binary Prefix Divisible By 5

要在这里批评检讨自己这两天没有学习, 态度不认真, 希望自己端正态度, 继续努力学习, 并且开始准备项目和OOD
回复

使用道具 举报

🔗
 楼主| Lingzhi..0614 2020-4-7 14:17:27 | 只看该作者
全局:
4-6
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
746. Min Cost Climbing Stairs
70. Climbing Stairs
1137. N-th Tribonacci Number
303. Range Sum Query - Immutable
1218. Longest Arithmetic Subsequence of Given Difference
121. Best Time to Buy and Sell Stock
53. Maximum Subarray

Today
49. Group Anagrams
        solution: we can use 1. character count to identify anagram 2. sort the word, if two word are equals after sort, then they are anagram.
          then we use hashmap to store <String, List<String>> to store the anagram
438. Find All Anagrams in a String
          n is short string len, we use sliding windows, with hashmap to store character count, and use count to dicate how many characters we need to compare.
           for each i, we add match with hashmap, if  it is in map, we minus character count by 1, if mao.get() ==0 , we do count--, it mean we matched one character with number
                for(i-n>=0),  we add back s[i-n], if map.get() == 1, we need count++, indidate we have a new character to match.
122. Best Time to Buy and Sell Stock II
        think of 2D graph, we need to sum all peak-valley which maxminum the profit. So while(a[i] >= a[i+1) i++. and then we reach valley, while(a[i]<= a[i+1]) i++, tehn we reach teh peak;
300. Longest Increasing Subsequence
         step 1: we use refine[i] : for length i+1, the minimun ending element
          if a[i] > refine[size() -1], we add refine[size+1]=a[i]
           else
             int idx = findLargestSmaller(refine, a[i])
             update(refine[idx+1])
  refine size is our result.
回复

使用道具 举报

🔗
 楼主| Lingzhi..0614 2020-4-8 14:08:09 | 只看该作者
全局:
4-8
reviewed:
784. Letter Case Permutation
943. Find the Shortest Superstring
996. Number of Squareful Arrays
22. Generate Parentheses
301. Remove Invalid Parentheses
62. Unique Paths
63. Unique Paths II
64. Minimum Path Sum
120. Triangle
49. Group Anagrams
438. Find All Anagrams in a String
122. Best Time to Buy and Sell Stock II
300. Longest Increasing Subsequence

Done:
85. Maximal Rectangle
     we first flatten the i,j to be a array, and then check the longest lenght eaquls to j-i+1.
221. Maximal Square
      dp[j] the longest length of square the use i, j as bottom right corner.
      dp[i][j] = Math.min(dp[i-1][j], dp[i][j-1],dp[i-1][j-1])+1;
304. Range Sum Query 2D - Immutable
       we can use flatten the row1, row2, and then claculate the sum from col1 , col2
        or we can use dp[i][j] : the sum of (0,0) to (i,j)
        sbmatrix(i,j,k,t) = dp[k][t] -dp[i-1][t] -dp[k][j-1] +dp[i-1][j-1]
1277. Count Square Submatrices with All Ones
same as 211.
[/i][/i][/i]
回复

使用道具 举报

🔗
 楼主| Lingzhi..0614 2020-4-9 14:57:59 | 只看该作者
全局:
4-8
reviewed:
37. Sudoku Solver
51. N-Queens
52. N-Queens II
79. Word Search
174. Dungeon Game
931. Minimum Falling Path Sum
1210. Minimum Moves to Reach Target with Rotations
85. Maximal Rectangle
221. Maximal Square
304. Range Sum Query 2D - Immutable
1277. Count Square Submatrices with All Ones

Done:
198. House Robber
    exclude[i]  = max(exclude[i-1], include[i-1])
    include[i] = exclude[i-1= +a[i]

213. House Robber II
   beacause it is a circle, so we can divide it into two list
               not rob first Max money for (1, n-1)   
                rob first max Money for(0, n-2)              
                                          ----------------> max of case 1 and case 2
309. Best Time to Buy and Sell Stock with Cooldown
            need to under stand three statuse
               hold[i] = Math.max(hold[i-1], rest[i-1] -price[i])
               sell[i] = hold[i-1] + prices[i]
               rest[i] = Math.max(rest[i-1], sell[i-1])
740. Delete and Earn
          1. if we rob 3 then we can rob all 3's
           2. if we rob 3, we can not rob 2's and 4's
         it is like house robber,
          step1 : we get values for array, if [2,2,3,3,3,4,4] ---> [1*0, 2*2, 3*3, 4*2]
          step 2: house robber
790. Domino and Tromino Tiling
       bigger question can be composed by smaller question
      dp[i][0] 没有突出一块 dp[i][1] 上面突出一块, dp[i][2]  下面突出一块
    dp[i][0] = dp[i-1][0]+dp[i-2][0] + dp[i-1][1] + dp[i-1][2]
    dp[i][1] = dp[i-2][0]+dp[i-1][2]
    dp[i][2] = d[i-2][0] + dp[i-1][1]
回复

使用道具 举报

🔗
 楼主| Lingzhi..0614 2020-4-11 00:27:05 | 只看该作者
全局:
4-9
reviewed: 212. Word Search II
127. Word Ladder
126. Word Ladder II
49. Group Anagrams
438. Find All Anagrams in a String
122. Best Time to Buy and Sell Stock II
300. Longest Increasing Subsequence
198. House Robber
213. House Robber II
309. Best Time to Buy and Sell Stock with Cooldown
740. Delete and Earn
790. Domino and Tromino Tiling

Done:
801. Minimum Swaps To Make Sequences Increasing
279. Perfect Squares
139. Word Break
140. Word Break II

Reviewed projects.
回复

使用道具 举报

🔗
 楼主| Lingzhi..0614 2020-4-14 14:54:02 | 只看该作者
全局:
4-13
reviewed:
282. Expression Add Operators
842. Split Array into Fibonacci Sequence
85. Maximal Rectangle
221. Maximal Square
304. Range Sum Query 2D - Immutable
1277. Count Square Submatrices with All Ones
673. Number of Longest Increasing Subsequence

Done:
1048. Longest String Chain
       step 1: sort the strings based on its lenth
       step 2: dp --> HashMap<String, Integer>
                    for (0<= j<=i) we delete the jth position character,  dp[cur] = Math.max(dp[cur], dp[removed]+1);
96. Unique Binary Search Trees
            dp[i] the number of BST with given i
            dp[1] = 1;
            dp[i] += ( 0<=j< i )dp[j-1] * dp[i-j-1]   j means the left length.
1105. Filling Bookcase Shelves
          it is same as cut ropes, 左大段右小段
          dp[i]  the minumum height for put [0, i] books
          dp[i] = dp[j-1] + Math.max(j,....i);      0<=j<=i, width [j, i] need to be smaller than shelf-width.
89. Gray Code
          we can build ith problem base on previous one
           if n =2  00, 01, 11, 10
              n =3 (000, 001, 011, 010), (110, 111, 101, 100)
               inorder to generate n+1, we can choose result from n and add the value for changing the highest pos to 1;
72. Edit Distance
10. Regular Expression Matching
         we can use recursion or dp.
          method 1: base case s.isempty && p.isempty()
                            recursive rule: 1. check whether first is match
                                                     2. check p.charAt(1) =='*' if true, we can match o, or match 1
                                                                                               if not , we need to check firstmatch && ismatch(s.sub(1), p.sub(1));


           method 2:
             dp[i][j] = whether substring s[0,i-1] math p[0,j-1]
             base case  : dp[0][0] = true;
                                 dp[i][0] = false;
                                 dp[0][j] = if(p.charAt(j) =='*' && dp[0][j-2]) true : false
                          dp[i][j]                 1. s[i-1] == p[j-1] || p[j-1] =='.' , dp[i-1][j-1]
                                                         p[j-1] == '*'    if p[j-2] == s[i-1] || p[j-2] == '.'     dp[i][j] = dp[i][j-2] || dp[i-1][j]
                                                                                                       else                          dp[i][j] = dp[i][j-2]
回复

使用道具 举报

🔗
 楼主| Lingzhi..0614 2020-4-15 15:28:07 | 只看该作者
全局:
4-14
reviewed:
746. Min Cost Climbing Stairs
70. Climbing Stairs
1137. N-th Tribonacci Number
303. Range Sum Query - Immutable
1218. Longest Arithmetic Subsequence of Given Difference
121. Best Time to Buy and Sell Stock
53. Maximum Subarray
198. House Robber
213. House Robber II
309. Best Time to Buy and Sell Stock with Cooldown
740. Delete and Earn
790. Domino and Tromino Tiling
1048. Longest String Chain
96. Unique Binary Search Trees
1105. Filling Bookcase Shelves
89. Gray Code
72. Edit Distance
10. Regular Expression Matching

Today:
712. Minimum ASCII Delete Sum for Two Strings
          dp[i][j] minimum cost for making s1[0,i-1] equals to s2[0,j-1]
          base case dp[0][0] = true;
                           dp[0][i] = s2[i] + dp[0][j];
                           dp[i][0] = s1[i] +dp[i-1][0];
           induction rule
                            if s1[i] == s2[j],  dp[i][j] = dp[i-1][j-1]
                                else              dp[i][j] = Math.min(dp[i-1][j] +s1[i-1], dp[i][j-1]+s2[j-1]);
44. Wildcard Matching
                  dp[i][j] whether for s1[0,i-1] match s2[0,j-1]
                dp[0][0] = true;
                dp[i][0] = false;
               dp[0][j] = if it is all *, then true, if meet not * false;
       induction rule:
                dp[i][j] = if( s2[j] != *) dp[i][j] = (s1[i-1] ==s2[j-1] || s2[j-1] =='?') && dp[i-1][j-1];
                                   else           dp[i][j] = dp[i-1][j] || dp[i][j-1];

            method 2 : use two pointer
           if s1[i] == s2[j] ; i++; j++
           if s2[j] =='*' , record start(start of *), and match(start of position where s2[j] ==*), j++;
           if not match, if start exists,  (start match one or more) match++; i = match; j = start+1;
                                if not start exists(no * exists) return false
           

97. Interleaving String
            dp[i][j] whether s1[0,i-1] s2[0,j-1] can form s3[0,i+j-1];
            base case dp[0][0] = true;
                             dp[0][i] = s2[i-1] == s3[i+0-1] ? dp[0][i-1] : false;
                             dp[i][0] = s1[i-1] == s3[i+0-1] ? dp[i-1][0] : false;

              induction rule:
                             dp[i][j] = if i>0 && s1[i-1] == s3[i+j-1]  dp[i][j] |= dp[i-1][j]
                                            if j>0 && s2[j-1] == s3[i+j-1] dp[i][j] |= dp[i][j-1];


            
1187. Make Array Strictly Increasing
         step 1: sort b, and deduplicate
          step2 : swap[i][j] the minimum steos to make a[0,i] increasing by replacing a[i] = b[j]
                        keep[i] the minumum steps to make a[0,i] increasing by keep a[i]
            base case: swap[0][*] =1;
                                keep[0] = 0;
           induction rule:
                      if(a[i] >a[i-1]) keep[i] = keep[i-1]
                      if(b[j] > a[i-1]) swap[i][j] = keep[i-1] +1;
                      if(a[i] > b[j])  keep[i] = Math.min(swap[i-1][k]) for  k<=j;
                      if(change a[i] and a[i-1]) swap[i][j] = min(swap[i-1][k]) +1; for k <j

res = keep[n-1] , min(swap[n-1][*]);
res>= Integer.MAX -1 : res;
回复

使用道具 举报

🔗
 楼主| Lingzhi..0614 2020-4-16 14:00:37 | 只看该作者
全局:
4-15
reviewed:
62. Unique Paths
63. Unique Paths II
64. Minimum Path Sum
120. Triangle
801. Minimum Swaps To Make Sequences Increasing
279. Perfect Squares
139. Word Break
140. Word Break II
712. Minimum ASCII Delete Sum for Two Strings
44. Wildcard Matching
97. Interleaving String
1187. Make Array Strictly Increasing

Today
1143. Longest Common Subsequence
          dp[i][j] the longest common subsequence for s1[0,i-1], s2[[0,j-1]
          base case dp[0][0] = ; dp[0][*] =dp[*][0] = 0
          induction rule: if s1[i-1] == s2[j-1]       dp[i][j] = 1+dp[i-1][j-1]
                                           else                       dp[i][j] = max(dp[i-1][j], dp[i][j-1])
115. Distinct Subsequences
            dp[i][j] : number of distinct subsequence for s1[0, i-1], s2[0,j-1]
            base case : dp[i][0] = 1; dp[0][j] = 0;
            induction rule:   ifs1[i-1] == s2[j-1]   dp[i][j] = dp[i-1][j-1] + dp[i-1][j];
                                                     else             dp[i][j] =  dp[i-1][j];  
1092. Shortest Common Supersequence
           solution : 1.first get longest common subsequence
                           according to 1143
                           2. construct the supersequence
                               method 1: start from end
                                            if( i ==0 ) add s2[j-1] j--;
                                            if(j ==0) add s1[i-1] i--
                                            if(s1[i-1] == s2[j-1] ) i--; j--; add s1[i]
                                           if(dp[i][j] = dp[i-1] [j]) add s1[i-1] , i--;
                                            if(dp[i][j] = d[i][j-1] ) add s2[j-1] , j--;
                                        then reverse
                             method 2: use longest common subsequence
                               and then iterative with s1, s2
                                if s1[i] != lcs[k], add s1[i], i++
                                 else if s2[j] != lcs[k], add se[j], j++
                                 else add s1[i], i++, j++, k++

583. Delete Operation for Two Strings

dp[i][j] the minimum step to make s1[0,i-1] equal s2[0,j-1]
base case do[0][0] = 0, dp[0][i] = i; dp[i][0] = i;
induction rule if s1[i-1] == s2[j-1]   dp[i][j] =  dp[i-1][j-1]
                                          else  dp[i][j] = min( dp[i-1][j] ,  dp[i][j-1]  ) +1;
回复

使用道具 举报

🔗
 楼主| Lingzhi..0614 2020-4-21 14:37:07 | 只看该作者
全局:
4-20
reviewed:
49. Group Anagrams
438. Find All Anagrams in a String
122. Best Time to Buy and Sell Stock II
300. Longest Increasing Subsequence
712. Minimum ASCII Delete Sum for Two Strings
44. Wildcard Matching
97. Interleaving String
1187. Make Array Strictly Increasing
1143. Longest Common Subsequence
115. Distinct Subsequences
1092. Shortest Common Supersequence
583. Delete Operation for Two Strings
1139. Largest 1-Bordered Square
718. Maximum Length of Repeated Subarray

Today
688. Knight Probability in Chessboard
dp[i][j][k] : the properties of reaching to (i,j) after k moves.
base case: dp[r][c][0] =1; dp[i][j][0] = 0;
                  induction rule dp[i][j][k] = sum(dp[r][c][k-1]) /8; where (r,c) can reach (i,j) in one move.

return sum(dp[i][j][k])
回复

使用道具 举报

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

本版积分规则

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