12
返回列表 发新帖
楼主: marlonlee
跳转到指定楼层
上一主题 下一主题
收起左侧

战拖!为了心中的梦想

🔗
 楼主| marlonlee 2018-6-6 23:25:30 | 只看该作者
全局:
        1. Sort In Specified Order, 这道题用comparator会很简单,要好好看一下这部分的内容,如果自己去部署的话涉及到的情况会有一点多
        Time: O(n)
        Space: O(n)   主要的花费就是在建map的过程中
       
        The elements is about to implements the comparable (compareTo)
        And the comparator class to implements the new comparator (compare)
       
        2. MaxPath in Binary Tree, a用一个int[]的data structure来传递global的max值,注意因为是从leaf到leaf,所以只有当两边的max都有传值上来的时候,方才能更新这个global的max值
        Space: O(level) stack
        Time: O(level)
       
        3. Palindrome Min Cut, DP的问题写成代码都很简单,但是里面的很多取值必须对memo的这个表自己在心中要很有数。即inclusive or exclusive的关系
        这道题sample中另用了一个二维DP来做剪枝处理,如果用的我的方法做一个check是过不了里口德的,因为这样会有很多的重复检查
        (piazza question)
       
        4. Insert in Binary Search Tree, using iterative way
        Space: O(1)
Time: O(level)
回复

使用道具 举报

🔗
 楼主| marlonlee 2018-6-6 23:26:09 | 只看该作者
全局:
        1. Sort In Specified Order, 这道题用comparator会很简单,要好好看一下这部分的内容,如果自己去部署的话涉及到的情况会有一点多
        Time: O(n)
        Space: O(n)   主要的花费就是在建map的过程中
       
        The elements is about to implements the comparable (compareTo)
        And the comparator class to implements the new comparator (compare)
       
        2. MaxPath in Binary Tree, a用一个int[]的data structure来传递global的max值,注意因为是从leaf到leaf,所以只有当两边的max都有传值上来的时候,方才能更新这个global的max值
        Space: O(level) stack
        Time: O(level)
       
        3. Palindrome Min Cut, DP的问题写成代码都很简单,但是里面的很多取值必须对memo的这个表自己在心中要很有数。即inclusive or exclusive的关系
        这道题sample中另用了一个二维DP来做剪枝处理,如果用的我的方法做一个check是过不了里口的,因为这样会有很多的重复检查
       
        4. Insert in Binary Search Tree, using iterative way
        Space: O(1)
Time: O(level)
回复

使用道具 举报

🔗
 楼主| marlonlee 2018-6-12 13:51:13 | 只看该作者
全局:
        1. K Way Merge List, easier than int[], because we have no need to create a new class Entry to check where is our current pointer, we can simply use ListNode.next to find next.
       
        Time: O(nlogn) at every step there will be offer in the heap
        Space: O(kn * logk)

        2. Closet Number in BST
        Time: O(level)
        Space: O(1)
       
        3. Largest Smaller number, I use recursion, but the logic is smaller in the sample question
       
       
        为什么这里用iteration更好,因为从root开始,以后的方向一定是固定的
        Time: O(level)
        Space: O(1) (if use iteration)
       
        4. Maximum Path Sum Binary Tree III, 这道题是一条path,是二向path的简化版本,向上传值的时候 there's a tricky part to pass 0 when the root is null;

        5. Maximum Path Sum Binary Tree II, s唯一要注意的就是传值和改变max[0] 的时刻不一样
        Time: O(n) just traverse the tree
        Space: O(Height)

        6. Binary Tree Path Sum to target III subpath target
        https://piazza.com/class/j0eqhhdregb3i?cid=721
        为什么这里要加入needtoremove这个boolean的原因是为了避免此处有0的出现,只应该在第一个插入这个值的位置将其从set中删去
        脑海中一定要把这个树给画出来,怎么个走势,对于hashset增减的时刻一定要非常的清晰
        Time: O(n) DFS
Space: O(n) HashSet
回复

使用道具 举报

🔗
 楼主| marlonlee 2018-6-12 13:51:47 | 只看该作者
全局:
        1. K Way Merge List, easier than int[], because we have no need to create a new class Entry to check where is our current pointer, we can simply use ListNode.next to find next.
       
        Time: O(nlogn) at every step there will be offer in the heap
        Space: O(kn * logk)

        2. Closet Number in BST
        Time: O(level)
        Space: O(1)
       
        3. Largest Smaller number, I use recursion, but the logic is smaller in the sample question
       
       
        为什么这里用iteration更好,因为从root开始,以后的方向一定是固定的
        Time: O(level)
        Space: O(1) (if use iteration)
       
        4. Maximum Path Sum Binary Tree III, 这道题是一条path,是二向path的简化版本,向上传值的时候 there's a tricky part to pass 0 when the root is null;

        5. Maximum Path Sum Binary Tree II, s唯一要注意的就是传值和改变max[0] 的时刻不一样
        Time: O(n) just traverse the tree
        Space: O(Height)

        6. Binary Tree Path Sum to target III subpath target
        为什么这里要加入needtoremove这个boolean的原因是为了避免此处有0的出现,只应该在第一个插入这个值的位置将其从set中删去
        脑海中一定要把这个树给画出来,怎么个走势,对于hashset增减的时刻一定要非常的清晰
        Time: O(n) DFS
Space: O(n) HashSet
回复

使用道具 举报

🔗
 楼主| marlonlee 2018-6-15 14:55:41 | 只看该作者
全局:
        1. Reconstruct BST by Post Order, Reconstruct这个问题的要点在于把global的问题一分为二,每边返回一个root node
        难点,有点没掌握
       
        2. Common elements in three arrays, just to use three pointers and move the smallest one.
        Time: O(n)
        Space: O(1)
       
        3. Reverse Binary Tree Upside Down, always think about the graph, so the recursion rule can be found
        Time: O(n)
        Space: O(n)
        Since there're few right nodes, so the level is approximately n
       
        4. 2 Sum, Classic question, I use a HashSet to reccord elements that been traversed, and check the set if there's element in it that adds up can be the target
        Time: O(n)
        Space: O(n)
        It can also use 2 pointers to check do this, and the space can be O(1)(Sort at first)
       
        5. 2Sum Pair I, because sometimes it can be repeat, so we use a hashtable here
        Time: O()
Space: O
回复

使用道具 举报

🔗
 楼主| marlonlee 2018-6-21 00:03:57 | 只看该作者
全局:
        1. 3 Sum,  其实就是运行两个2sum,用pointer的方式能够比较节省空间
        最需要注意的是判断重复的条件,因为现在不像2sum一样是从头开始,所以需要把这个判断放在if条件中去
        Time: O(n^2)
        Space: O(1)
       
        2. 4 Sum, the same as 3 sum, just add another for loop
        Time: O(n^3)
        Space: O(1)
       
        3. Longest Common SubString, using two global va longest and start to reccord the length and starting point, and a DP memo to reccord it.
        Time: O(m * n)
        Space: O(m * n)
       
        4. Longest Common SubSequence, DP一定要把memo的含义理解的特别清楚再开始做题

Kth Smallest with only 3, 4, 5 as Factors, using 3 deques to store the elements, the key point to avoid duplicate is to 不要在5被取出的时候更新3,因为这些元素已经在前面被更新过了
回复

使用道具 举报

🔗
 楼主| marlonlee 2018-6-21 00:04:14 | 只看该作者
全局:
        1. Kth closest matrix point to (0, 0, 0), 这道题其实就解题来说不算难,但是设计到的知识面比较广,考察了heap的操作,set的操作,包括private class的内容
        BFS
        Time: O(nlongn) 在每步里都有heap的poll和offer操作
        Space: O(n)
       
        2. Max Water Trapped I, a这道题有两种解法,一种是2 pointers,一种是DP,其主要要素都是抓住木板效应,最小的那一个才是决定性因素
        所以DP就是keep两个array,记录leftMax和rightMax,然后再通过cur的来计算
        2 pointers的方法会更加巧妙,也把space从O(n)降到了O(1),具体如图
       
        Time: O(n)
        Space: O(n)
       
        3. Max value of size k window, 这个题,最巧妙的一点就是利用deque的一系列性质,如果最左边数,不是最大的最新的(意味着将来也不会有机会变成最大的了),那么就会被清除,所以只要每次添加最左边的就好了


        4. LRU Cache,
        泛型:
        匿名类:
       
        5. Majority Number I, 一开始的时候想了很久怎么用maxheap或者hashmap来做,但是最后发现真的理解题意非常重要,因为在这个题目的assumption里已经说了必定是会有一个majority number的,所以一开始就可以用一个count来计数,然后这个candidate如果其数目超越了二分之一,那么最后一定会被选出来
        Time: O(n)
        Space: O(1)

Interleave String, we can use a 2D array to keep it, and "or" symble
回复

使用道具 举报

🔗
Jani 2018-6-21 00:21:38 | 只看该作者
全局:
楼主有上某offer的项目班吗,不知道讲的如何
回复

使用道具 举报

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

本版积分规则

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