• 博客园logo
  • 会员
  • 众包
  • 新闻
  • 博问
  • 闪存
  • 赞助商
  • HarmonyOS
  • Chat2DB
    • 搜索
      所有博客
    • 搜索
      当前博客
  • 写随笔 我的博客 短消息 简洁模式
    用户头像
    我的博客 我的园子 账号设置 会员中心 简洁模式 ... 退出登录
    注册 登录
neverlandly
博客园    首页    新随笔    联系   管理    订阅  订阅
上一页 1 2 3 4 5 6 7 8 9 ··· 21 下一页
2019年10月7日
Leetcode: Capacity To Ship Packages Within D Days
摘要: Exactly the same with Split Array Largest Sum. Binary search or DP Binary Search 阅读全文
posted @ 2019-10-07 03:30 neverlandly 阅读(285) 评论(0) 推荐(0)
2019年10月6日
Leetcode: Stream of Characters
摘要: Store the words in the trie with reverse order, and check the query string from the end 阅读全文
posted @ 2019-10-06 16:38 neverlandly 阅读(359) 评论(0) 推荐(0)
Leetcode: Backspace String Compare
摘要: Complexity Analysis Time Complexity: O(M + N)O(M+N), where M, NM,N are the lengths of S and T respectively. Space Complexity: O(1)O(1). Time Complexit 阅读全文
posted @ 2019-10-06 09:58 neverlandly 阅读(131) 评论(0) 推荐(0)
2019年10月3日
Leetcode: Compare Strings by Frequency of the Smallest Character
只有注册用户登录后才能阅读该文。 阅读全文
posted @ 2019-10-03 15:28 neverlandly 阅读(2) 评论(0) 推荐(0)
Leetcode: Shortest Way to Form String
摘要: Greedy Use two pointers, one for source: i, one for target: j. While j scan through target, try to match each char of j in source by moving i. Count h 阅读全文
posted @ 2019-10-03 14:16 neverlandly 阅读(1227) 评论(0) 推荐(1)
Leetcode: License Key Formatting
只有注册用户登录后才能阅读该文。 阅读全文
posted @ 2019-10-03 12:54 neverlandly 阅读(4) 评论(0) 推荐(0)
2019年10月2日
Leetcode: Campus Bikes II
摘要: Basic: Backtracking + pruning DP: refer to https://leetcode.com/problems/campus-bikes-ii/discuss/305218/DFS-%2B-Pruning-And-DP-Solution state : dp[i][ 阅读全文
posted @ 2019-10-02 16:13 neverlandly 阅读(1537) 评论(0) 推荐(0)
2019年10月1日
Leetcode: Minimum Domino Rotations For Equal Row
摘要: 1. The final uniform character should be either A[0] or B[0] 2. A[0] could be at the top, or the bottom. Same applies to B[0] 3. If A[0] works, no nee 阅读全文
posted @ 2019-10-01 13:27 neverlandly 阅读(473) 评论(0) 推荐(0)
2019年9月30日
Leetcode: Palindromic Substrings
摘要: DP: Extend palindrome: (better) 阅读全文
posted @ 2019-09-30 13:59 neverlandly 阅读(171) 评论(0) 推荐(0)
2019年9月22日
Summary: curated List of Top 75 LeetCode Questions to Save Your Time
摘要: Facebook / Eng tech lead Dec 30, 2018 68 Comments Facebook / Eng tech lead Facebook / Eng tech lead Dec 30, 2018 68 Comments New Year Gift to every fe 阅读全文
posted @ 2019-09-22 07:50 neverlandly 阅读(462) 评论(0) 推荐(0)
2019年9月20日
Leetcode: Subtree of Another Tree
摘要: Recursion: 阅读全文
posted @ 2019-09-20 15:17 neverlandly 阅读(154) 评论(0) 推荐(0)
2019年9月17日
Leetcode: Longest Common Subsequence
摘要: DP with a 2D array Time & space: O(m * n) (Skim through) memory optimization, referencing: https://leetcode.com/problems/longest-common-subsequence/di 阅读全文
posted @ 2019-09-17 13:56 neverlandly 阅读(210) 评论(0) 推荐(0)
2017年3月18日
FB面经Prepare: Email User
摘要: 账号之间如果有公共email就连边,我觉得要用hashMap, 存(email, user) pair 如果当前user的某个email在hashMap里出现过,当时是user1, 就看user和user1是否connected,否的话就要union,根据Union Find Union Find 阅读全文
posted @ 2017-03-18 02:30 neverlandly 阅读(851) 评论(1) 推荐(0)
2017年3月17日
Lintcode: Nuts & Bolts Problem
摘要: Quick Sort Way: We can use quick sort technique to solve this. We represent nuts and bolts in character array for understanding the logic. Nuts repres 阅读全文
posted @ 2017-03-17 06:12 neverlandly 阅读(745) 评论(0) 推荐(0)
FB面经Prepare: Merge K sorted Array
摘要: 跟Merge K sorted lists不同在于,从PQ里poll出来以后不知道下一个需要被加入PQ的是哪一个 所以需要写一个wrapper class 阅读全文
posted @ 2017-03-17 04:45 neverlandly 阅读(683) 评论(0) 推荐(0)
FB面经 Prepare: Count Unique Island
摘要: 方法可以是记录每次新的岛屿搜索的路径,left,right,up,down, 作为标志是否相同的key,存hashset 阅读全文
posted @ 2017-03-17 02:46 neverlandly 阅读(641) 评论(0) 推荐(0)
2017年3月16日
FB面经 Prepare: Make Parentheses valid
摘要: 从左从右各scan一次 阅读全文
posted @ 2017-03-16 22:59 neverlandly 阅读(561) 评论(0) 推荐(0)
2017年3月15日
FB面经Prepare: Bipartite a graph
摘要: 这道题应该是how to bipartite a graph Taken from GeeksforGeeks Following is a simple algorithm to find out whether a given graph is Birpartite or not using B 阅读全文
posted @ 2017-03-15 06:51 neverlandly 阅读(753) 评论(0) 推荐(0)
FB面经 Prepare: LCA of Deepest Nodes in Binary Tree
摘要: Recursion: 返回的时候返回lca和depth,每个node如果有大于一个子节点的depth相同就返回这个node,如果有一个子节点depth更深就返回个子节点lca,这个o(n)就可以了 Iteration: tree的recursion换成iteration处理,一般用stack都能解决 阅读全文
posted @ 2017-03-15 00:38 neverlandly 阅读(1576) 评论(0) 推荐(0)
2017年3月14日
FB面经 Prepare: K closest point to the origin
摘要: Based on bucket sort: Based on Quick Select 当然,还有的方法是维护一个size为k的最大堆 阅读全文
posted @ 2017-03-14 09:58 neverlandly 阅读(2108) 评论(0) 推荐(0)
FB面经prepare: 3 Window Max Sum
摘要: Follow Up: 这个其实可以优化到O(n)时间。建从左端到每个下标的最大window数组,再建从右端到每个下标的最大window数组。再从左往右走一遍所有的size k window,将其和与上一步建的两个数组一起加起来。遍历一遍取最大值即可。 阅读全文
posted @ 2017-03-14 05:39 neverlandly 阅读(630) 评论(0) 推荐(0)
Lintcode: Knight Shortest Path
摘要: BFS solution: 阅读全文
posted @ 2017-03-14 03:31 neverlandly 阅读(1437) 评论(0) 推荐(0)
2017年3月11日
Leetcode: Encode and Decode TinyURL
摘要: 1. 根据系统设计的Estimation of the amount of data we need to store for the next couple of years, 我们应需要6位Base62的char来encode 2. assume 避免地址爆炸,相同的longUrl得到相同的sh 阅读全文
posted @ 2017-03-11 04:30 neverlandly 阅读(4086) 评论(1) 推荐(0)
2017年2月21日
Pocket Gems面经prepare: Diamond and Ruby
摘要: 类似Ones and Zeroes Dp[i][j][k] = Max(dp[i-5][j][k] + 5*10, dp[i][j-5][k] + 5*5, dp[i][j][k-1] + 1*25) reduce了dimension,其实还有一个维度是前k个格子,直接用倒序省掉了这个维度 阅读全文
posted @ 2017-02-21 14:11 neverlandly 阅读(924) 评论(0) 推荐(0)
2017年2月16日
FB面经Prepare: Find Longest Path in a Multi-Tree
摘要: 解法就是在子树里面找最大的两个(或一个,如果只有一个子树的话)高度加起来。 对于每一个treenode, 维护它的最高的高度和第二高的高度,经过该点的最大路径就是: 最高高度+第二高高度,然后return 最高高度 阅读全文
posted @ 2017-02-16 05:02 neverlandly 阅读(446) 评论(0) 推荐(0)
2017年2月15日
FB面经Prepare: Friends Recommendation
摘要: 有个getFriend() API, 让你推荐你的朋友的朋友做你的朋友,当然这个新朋友不能是你原来的老朋友 1 package fb; 2 3 import java.util.*; 4 5 public class ReferFriends { 6 public List recommendation(String name) { 7 List... 阅读全文
posted @ 2017-02-15 08:02 neverlandly 阅读(1274) 评论(0) 推荐(0)
FB面经Prepare: Dot Product
摘要: 1. two pointers 2. hashmap 3. 如果没有额外空间,如果一个很大,一个很小,适合scan小的,并且在大的里面做binary search 阅读全文
posted @ 2017-02-15 06:13 neverlandly 阅读(1624) 评论(0) 推荐(0)
FB面经prepare: Count the number of Vector
摘要: 分析: 如果是binary search找每个char的上下界,worst case要找n次,时间复杂度O(nlogn) 所以考虑每次比较start point和start point + 2^n位置上的数,假如一样就continue,不一样就在区间里面binary search找上界,这样wors 阅读全文
posted @ 2017-02-15 03:29 neverlandly 阅读(444) 评论(0) 推荐(0)
2017年2月14日
Leetcode: The Maze III(Unsolved Lock Problem)
摘要: Each time, first add the direction to the path, and then go with that direction, checking for hole along the way. When hit a wall, try to turn, and go 阅读全文
posted @ 2017-02-14 02:45 neverlandly 阅读(841) 评论(0) 推荐(0)
Leetcode: The Maze II
摘要: Solution of The Maze: https://discuss.leetcode.com/topic/77471/easy-understanding-java-bfs-solutionSolution of The Maze III: https://discuss.leetcode. 阅读全文
posted @ 2017-02-14 02:43 neverlandly 阅读(1305) 评论(0) 推荐(0)
Leetcode: The Maze(Unsolved locked problem)
摘要: Search in the four possible directions when coming to a stopping point (i.e. a new starting point). Keep track of places that you already started at i 阅读全文
posted @ 2017-02-14 02:36 neverlandly 阅读(611) 评论(0) 推荐(0)
Leetcode: Max Consecutive Ones II(unsolved locked problem)
摘要: 未研究: The idea is to keep a window [l, h] that contains at most k zero The following solution does not handle follow-up, because nums[l] will need to a 阅读全文
posted @ 2017-02-14 01:40 neverlandly 阅读(411) 评论(0) 推荐(0)
Leetcode: Find Permutation(Unsolve lock problem)
摘要: 还没研究: For example, given IDIIDD we start with sorted sequence 1234567Then for each k continuous D starting at index i we need to reverse [i, i+k] port 阅读全文
posted @ 2017-02-14 01:36 neverlandly 阅读(488) 评论(0) 推荐(0)
2017年2月6日
G面经: Design Stock Price Display System
摘要: 简单说来PriceUpdate就是添加新的(timestamp, price), Correction是改之前的(timestamp, price), 求实现当前high(), low(), last() LZ是用的Heap + HashMap, 特别问了时间复杂度(我猜到他想考heap的remov 阅读全文
posted @ 2017-02-06 08:06 neverlandly 阅读(607) 评论(0) 推荐(0)
2017年2月5日
U面经Prepare: Print Binary Tree With No Two Nodes Share The Same Column
摘要: 这道题若能发现inorder traversal each node的顺序其实就是column number递增的顺序,那么就成功了一大半 维护一个global variable,colNum, 做inorder traversal 然后level order 一层一层打印出来 阅读全文
posted @ 2017-02-05 12:20 neverlandly 阅读(413) 评论(0) 推荐(0)
2017年2月4日
U面经Prepare: Web Address
摘要: 虽然我觉得这道题用set倒着来就可以解决,但是看到一个Trie的做法也很不错 这里TrieNode.val不再是char, 而是String. children array也变成了Map<String, TrieNode> 我的做法: 阅读全文
posted @ 2017-02-04 12:48 neverlandly 阅读(442) 评论(0) 推荐(0)
2017年2月1日
FG面经Prepare: BST to Double LinkedList
摘要: Follow up: 第一步完成基础上,把这个new value插入BST中,一边插入一边记录沿途的大于value的root node(即走了该root node的left child),作为inorder successor. 找到inorder successor之后,通过其prev指针找到in 阅读全文
posted @ 2017-02-01 12:46 neverlandly 阅读(487) 评论(0) 推荐(0)
G面经Prepare: Longest All One Substring
摘要: 这是一个简单版本of LC 424 Longest Repeating Character Replacement 又是Window, 又是Two Pointers Window还是采用每次都try to update left使得window valid, 每次都检查最大window 阅读全文
posted @ 2017-02-01 08:20 neverlandly 阅读(358) 评论(0) 推荐(0)
G面经Prepare: Print Zigzag Matrix
摘要: For instance, give row = 4, col = 5, print matrix in zigzag order like: [1, 8, 9, 16, 17] [2, 7, 10, 15, 18] [3, 6, 11, 14, 19] [4, 5, 12, 13, 20] 1 package GooglePhone; 2 3 import java.util... 阅读全文
posted @ 2017-02-01 01:09 neverlandly 阅读(374) 评论(0) 推荐(0)
2017年1月31日
FG面经: Interval问题合集
摘要: O(N) solution: 两个interval overlap条件: interval1.end >= interval2.start && interval1.start <= interval2.end 问:一个query数在不在已经加入的区间? 如果interval是sorted, 就可以 阅读全文
posted @ 2017-01-31 07:34 neverlandly 阅读(604) 评论(0) 推荐(0)
上一页 1 2 3 4 5 6 7 8 9 ··· 21 下一页
博客园  ©  2004-2025
浙公网安备 33010602011771号 浙ICP备2021040463号-3