查看: 10575| 回复: 43
跳转到指定楼层
上一主题 下一主题
收起左侧

转型刷Leetcode记录帖

全局:

注册一亩三分地论坛,查看更多干货!

您需要 登录 才可以下载或查看附件。没有帐号?注册账号

x
PhD梦估计凉凉了...大概7月才开始准备SDE/DS,大多数刷的是Leetcode

这是记录帖的链接 [url=https://hackmd.io/e1g24XDnR42JaLNv2xZjNA]https://hackmd.io/e1g24XDnR42JaLNv2xZjNA[/url]


争取日常更新,大家加油!

评分

参与人数 2大米 +8 收起 理由
zjunnju + 3 给你点个赞!
gppcbs + 5 祝你找工作成功!

查看全部评分


上一篇:在职战拖刷题日记,直到拿到满意的offer为止
下一篇:学习英语和刷题两不误
推荐
 楼主| Lyuan 2018-10-27 12:18:25 | 只看该作者
全局:
刷题刷题刷题

- 10/26
    - google:
        - 297H. Serialize and Deserialize Binary Tree
            - encoding
        - 31M. Next Permutation
            - imple
        - 139M. Word Break
            - Trie.
            - dp with hash.
        - 253M. Meeting Rooms II
            - heap.
        - 17M. Letter Combinations of a Phone Number
            - dfs
        - 23H. Merge k Sorted Lists
            - heap
        - 10H. {buggy} Regular Expression Matching
            - mem+dfs
            - bugs:
                - p_pos < m when s_pos >= n
                - s_pos>=n, cannot read s[s_pos]
                - check equality when *
                - check s_pos < n when star == False
        - 56M. Merge Intervals
            - greedy
        - 42H. Trapping Rain Water
            - prefix-sum. S(N)=O(N)
            - two pointers
        - 20E. Valid Parentheses
            - stack
        - 200M. Number of Islands
            - flood fill.
            - -followup: partition, union-find set
        - 4H. Median of Two Sorted Arrays
            - binsearch
        - 146H. LRU Cache
            - dbl link list+hash
        - 253M. Meeting Rooms II
            - heap
回复

使用道具 举报

推荐
 楼主| Lyuan 2018-10-29 16:06:18 | 只看该作者
全局:
27的周赛最后一题做过类似的,但是当时没有想出构造方法,可惜了。这种比较没有规律的构造题很考验脑洞。
28继续刷lc上google的list,打算先刷完这些然后刷面经。

- 10/28
    - google:
        - 341M. Flatten Nested List Iterator
            - recursion. prefetch.
        - 239H. Sliding Window Maximum
            - deque. only maintain necessary elements.
        - 535M. Encode and Decode TinyURL
            - relevant hash (compression) vs irrelevant hash (key gen). System Design
        - 155E. Min Stack
            - stack
        - 224H. Basic Calculator
            - {buggy} imple
        - 128H. Longest Consecutive Sequence
            - hashing
        - 50M. Pow(x, n)
            - imple
        - 173M. Binary Search Tree Iterator
            - generator
            - manual stack
        - 289M. Game of Life
            - mix information with different bits
        - 54M. Spiral Matrix
            - imple
            - oneline (recursive)
        - 22M. Generate Parentheses
            - dfs
- 10/27
    - Weekly contest
        - 932M. Beautiful Array
            - {DNF}. constructive answer
        - 931M. Minimum Falling Path Sum
            - DP.
        - 930M. Binary Subarrays With Sum
            - imple
            - three pointer solution with O(1) space
        - 929E. Unique Email Addresses
            - hash
回复

使用道具 举报

推荐
 楼主| Lyuan 2018-10-11 14:16:34 | 只看该作者
全局:
今天清理了一波DNF的题(Did not finish,相信有玩魔方的应该知道这个)
这些题是第一次刷看了discussion才做出最优解的题目,大部分都是脑洞构造答案的题目,基本上很难泛化到其他情况。

此外花30分钟刷了visa的OA....基本上就easy或者medium偏easy难度。

- 10/10 (DNF review day)
    - 406. Queue Reconstruction by Height
        - constructive. O(N^2)
        - has a shorter version with `insert`.
    - 496. Next Greater Element I
        - stack
    - 632. Smallest Range
        - heap.
    - 446. Arithmetic Slices II - Subsequence
        - DP with hash
    - 260. Single Number III
        - Get x1 ^ x2. Split into two conditions.
    - 448. Find All Numbers Disappeared in an Array
        - use negative/positive as hashing.
    - 667. Beautiful Arrangement II
        - constructive
    - 371. Sum of Two Integers
        - it can be solve with recursive code.
        - Use C++. Since python don't have complementary
    - 128. Longest Consecutive Sequence
        - hash.
    - 421. Maximum XOR of Two Numbers in an Array
        - Trie. Notice time complexity is O(N\*#bits) = O(N\*32) = O(N)
    - 898. Bitwise ORs of Subarrays
        - brutal force. But the time complexity is tricky.
    - 523. Continuous Subarray Sum
        - hash. Notice the range of K
        - O(N) with prefix_sum_hash. prefix_sum-prefix_sum = any range
    - 42. Trapping Rain Water
        - greedy+two pointer
    - 683. K Empty Slots
        - segtree. O(nlogn)
        - bucket. O(n)
    - 109. Convert Sorted List to Binary Search Tree
        - two pointers + recursive
    - 324. Wiggle Sort II
        - O(N) to locate Kth smallest number
回复

使用道具 举报

🔗
 楼主| Lyuan 2018-9-28 15:42:13 | 只看该作者
全局:
    - Shortest Palindrome
        - palindrome. manacher's alg
    - Max Consecutive Ones II (if we can flip at most one 0)
        - imple.
    - Max Consecutive Ones
        - simple imple
    - Intersection of Two Arrays
        - simple hash
    - Image Smoother
        - simple imple
    - Valid Parentheses
        - simple imple, stack
    - Valid Number
        - regexp
    - Valid Palindrome
        - simple imple
    - One Edit Distance
        - simple imple: item zip(x, y) in is tuple
    - Read N Characters Given Read4 II - Call multiple times
        - {buggy} pay attention to situation when the buffer remains
    - Read N Characters Given Read4
        - buffer: [""] * N  (assigned empty space)
    - Add Bold Tag in String
        - {buggy} KMP variation
    - Plus One
        - simple imple
    - Spiral Matrix
        - boundary imple
    - 270. Closest Binary Search Tree Value
        - simple imple

补充内容 (2018-9-28 15:48):
Add Bold Tag in String
应该是最难的了,考察了KMP、KMP匹配所有解、merge区间等操作
回复

使用道具 举报

🔗
 楼主| Lyuan 2018-9-30 07:43:21 | 只看该作者
全局:
Merge K sorted List 相信大家都刷过
Python里只有heapq的API,需要用tuple来把val和node绑定在一起(node.val, node)。
但是tuple比较大小的时候,如果前面的值相等,就会比较后面的值,但是node class本身没有定义大小关系,在Python2中不会报错,在Python3中会报错。
这时一个技巧就是用(node.val, id(node), node)作为tuple,比较到第二个值(id)的时候就一定会有个大小关系,不会比较到第三个值

- 09/28
    - Inorder Successor in BST
        - {buggy}. Morris traversal.
        - right children can be a backref-link or a normal link
            - sol1. judge every where when stepping right
            - sol2. handle differently when creating a backref-link
    - 864. Shortest Path to Get All Keys
        - BFS. states encoding
    - 262. Trips and Users
        - sqls. notice to use `u.banned` and `u2.banned` to join `user` table twice on different conditions
    - 286. Walls and Gates
        - BFS
    - Evaluate Division
        - build graph. notice the value of the reverse edge, same (s, t)
    - Insert into a Cyclic Sorted List
        - link. notice the boundary and equality
    - Merge k Sorted Lists
        - classic heap. Python3 RTE, use `id()` as secondary key
    - Remove Duplicates from Sorted Array
        - two pointer
    - Move Zeroes
        - simple twopointer
    - First Unique Character in a String
        - hash
    - First Missing Positive
        - hash using pos/neg. have to realize that the ans is in 1~n+1
回复

使用道具 举报

🔗
 楼主| Lyuan 2018-10-1 02:56:55 | 只看该作者
全局:
花了半天学习了boosting家族的东西,感觉还蛮engineering的
685推荐大家挑战一下,可以算是目前见到cases最难简单判断出来的题目了

- 09/29
    - Closest Binary Search Tree Value
        - recursive
    - Validate Binary Search Tree
        - Simple recursive
    - Course Schedule
        - Simple topological sort
    - 685. Redundant Connection II
        - {DNF}. Hard.
        - indeg with union find set
    -  Robot Room Cleaner
        - backtrack
        - dfs; keep track the direction, `move[(ind+k)%3]`
回复

使用道具 举报

🔗
 楼主| Lyuan 2018-10-1 12:10:40 | 只看该作者
全局:
Find K-th Smallest Pair 挺有意思,在一个数组中找出差值第k大的pair。
如果用heap做的话需要
   
- 09/30
    -   Sort Transformed Array
        - case by case search
    -   Find K Pairs with Smallest Sums
        - priority queue
    - Find K-th Smallest Pair Distance
        - heap: O(NlogK) = O(2NlogN) TLE
        - sort and binary search the answer: O(nlogn)
    - Shortest Distance from All Buildings
        - BFS. reverse thinking
    - Minimum Window Substring
        - two pointers search
    - Android Unlock Patterns
        - dfs. notice the visited flag for the first element
    - Word Search II
        - notice words with only one char
    - Strobogrammatic Number II
        - dfs
    - Word Squares
        - dfs implementation

补充内容 (2018-10-1 12:12):
如果用heap做的话需要O(NlogK)的时间,但是K是O(N^2)的,所以有可能不划算。
但是先排序再二分答案的话,只需要O(NlogN)的时间,能通过
回复

使用道具 举报

🔗
 楼主| Lyuan 2018-10-2 13:51:02 | 只看该作者
全局:
Insert Interval这题值得做,加点难度可以试一下Range Module。Python里没有BST还做不了最优。。。


- Diagonal Traverse
        - imple. generate digonal list first
    - Longest Palindromic Substring
        - manacher's alg. notice `'^#'+'#'.join(s)+'#$'`
    - Insert Interval
        - {buggy} imple
    - Range Module
        - {DNF}. Ultra-hard.
        - TLE with lazy-growing SegTree
        - Require BST to achieve O(logN) when querying
回复

使用道具 举报

🔗
 楼主| Lyuan 2018-10-3 16:42:17 | 只看该作者
全局:
LFU写了1+小时,不过1A而且没看discussion还是很开心的。
推荐大家刷完LRU可以刷下LFU,每个人的方法都可能不一样。

- 10/02
    - 460. LFU Cache
        - DoubleLinkedList inside DoubleLinkedList. One pass! :)
    - Sentence Screen Fitting
        - Greedy+DP.
    - Word Break
        - {buggy}. notice the boundaries
    - Decode Ways
        - dp.
    - Evaluate Reverse Polish Notation
        - stack. notice the definition of div
    - Pacific Atlantic Water Flow
        - BFS
    - Next Greater Element I
        - stack
    - Merge Intervals
        - {buggy}.
    - 785. Is Graph Bipartite?
        - dfs
    - 261. Graph Valid Tree
        - union-find set
回复

使用道具 举报

🔗
 楼主| Lyuan 2018-10-4 14:15:55 | 只看该作者
全局:
913minmax search蛮有趣的,大家可以试一下
308. Range Sum Query 2D - Mutable 需要写一个2d线段树,100+行也是醉了2333

- 10/03
    - 913. Cat and Mouse
        - {buggy} minmax search.
    - Range Sum Query 2D - Mutable
        - 2d segmental tree.
    - Zigzag Iterator
        - imple
    - Binary Search Tree Iterator
        - recursion to interation. Use stack to keep track every returns
    - Peeking Iterator
        - simple design
    - Moving Average from Data Stream
        - simple design
    - House Robber II
        - DP. handle the cycle restriction by search(0, n-1) and (1, n)
    - Minimum Path Sum
        - basic DP
    - Edit Distance
        - 2d DP. note the replacement operator
    - Maximum Vacation Days
        - 2d DP
回复

使用道具 举报

🔗
dizhufengzhi 2018-10-4 17:47:27 | 只看该作者
全局:
楼主是不读博,转找工了
回复

使用道具 举报

🔗
 楼主| Lyuan 2018-10-5 01:24:44 | 只看该作者
全局:
dizhufengzhi 发表于 2018-10-4 17:47
楼主是不读博,转找工了

恩恩是的  读博先放一放
回复

使用道具 举报

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

本版积分规则

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