随笔分类 - 面经
G面经prepare: Jump Game Return to Original Place
摘要:第二题 算法 给你一个arr 返回 T 或者 Farr的每个数代表从这个点开始跳几部,返回T的情况:从这个arr中任意一个数开始跳,可以在每个元素都跳到且只跳到一次的情况下返回到开始跳的元素比如[1,1,1,1,1,1] => T[0,1,1,1,1,1]=> F[7, 5, 2, 3] => F[...
阅读全文
G面经prepare: Reorder String to make duplicates not consecutive
摘要:字符串重新排列,让里面不能有相同字母在一起。比如aaabbb非法的,要让它变成ababab。给一种即可Greedy:跟FB面经Prepare task Schedule II很像,记录每个char出现次数,然后用最大堆,把剩下char里面出现次数多的优先Poll出来组建新的string如果poll出...
阅读全文
G面经prepare: Sort String Based On Another
摘要:Given a sorting order string, sort the input string based on the given sorting order string. Ex sorting order string -> dfbcae Input string -> abcdeea...
阅读全文
G面经Prepare: Valid Preorder traversal serialized String
摘要:1 求问下各位大神,怎么判断一个按照Preorder traversal serialized的binary tree的序列是否正确呢?不能deserialize成树比如2 A) 9 3 4 # # 1 # # 2 # 6 # #是对的,因为表示3 94 / ...
阅读全文
G面经prepare: Chucked Palindrome
摘要:给定一个字符串,找出最多有多少个chunked palindrome,正常的palindrome是abccba, chunked palindrome的定义是:比如volvo, 可以把vo划分在一起,(vo) (l) (vo),那么它是个palindrome。求实现返回最大的chunk 数量。比如...
阅读全文
G面经prepare: BuyGoods
摘要:给你一部分钱和一些不同价钱的商品,如何在最多买K件商品的情况下尽可能多的花掉手里的钱。举例:口袋里的钱数: 10; K=2 产品价格: [3, 6, 8, 7, 9] 输出 3, 7Backtracking: 1 package BuyGoods; 2 import java.uti...
阅读全文
G面经prepare: X-Straight
摘要:Define “X-Straight” as X cards with consecutive numbers (X >= 3). Determine if the deck can be fully divided into sets of “X-Straight”.Example: 1, 2, ...
阅读全文
G面经prepare: Friends Recommendation
摘要:想想如果你用linkedin或者facebook, 给你一个人和他的朋友关系网,你会怎么给一个人推荐朋友一个例子就是A-B, A-C, B - D, B - E, C - D,这个时候问我应该推荐谁给A,我说D,因为他是BC的共同好友,而E只是B的好友,到这我才明白干啥,就是给一个图和里面的一个节点...
阅读全文
G面经prepare: set difference
摘要:给你A{1,2,3,4,4,5}, B{2,4},求A-B={1,3,4,5},很简单. visit 1只用一个HashMap 1 package TwoSets; 2 import java.util.*; 3 4 public class Solution { 5 public Arr...
阅读全文
G面经prepare: Straight Partition of A Deck of Cards
摘要:Define “Straight” as 5 cards with consecutive numbers. Determine if the deck can be fully divided into sets of “Straight”.Example: 1, 2, 3, 4, 4, 5, 5...
阅读全文
Summary: Merge Sort of Array && 求逆序对
摘要:常用算法(后面有inplace版本): 1 package ArrayMergeSort; 2 3 import java.util.Arrays; 4 5 public class Solution { 6 public int[] mergeSort(int[] arr) { 7 if (arr
阅读全文
G面经Prepare: Search word delete sequence in dictionary
摘要:给一个单词一个字典,每次删除单词里任一个字母直到剩下一个字母,形成一个序列,比如office->offce->ofce->ofc->oc->c。问是否字典里存在一个这种序列 1 package checkDictExistSequence; 2 import java.util.*; 3 4 pu...
阅读全文
F面经prepare:strstr变种
摘要:* Given an integer k>=1 and two strings A and B (length ~n each); * Figure out if there is any common substring of length at least k. * (i.e. any str...
阅读全文
FB面经prepare: task schedule II
摘要:followup是tasks是无序的.一开始是有序的,比如说1, 1, 2, 1,一定要先执行第一个task1,然后等task1恢复,再执行第2个task1,再执行task2..... followup是无序的,就是不用按给的顺序执行,也就是可以先执行task1,然后task1还没恢复时,先执行ta...
阅读全文
FB面经prepare: Task Schedule
摘要:每种task都有冷却时间,比如task1执行后,要经过interval时间后才能再次执行,求总共所需时间。用HashMap保存每一个task的下一次可以开始执行的最早时间 1 package TaskSchedule; 2 import java.util.*; 3 4 public class ...
阅读全文
转载:如何在面试中写出好的代码
摘要:一下都是我面试的经验和教训,欢迎各位大牛指正或者补充 1. 写代码之前,大脑里面要有个whole picture,不能想到哪儿写到哪儿。是你的大脑在写代码,而不是白板上你的手在代码。你的手只是一个printer里面的喷头而已,是它把你大脑里面的代码print到白板上,你的大脑才是控制那个喷头的芯片。
阅读全文
F面经:painting house
摘要:There are a row of houses, each house can be painted with three colors red, blue and green. The cost of painting each house with a certain color is di...
阅读全文
Climbing Stairs - Print Path
摘要:stair climbing, print out all of possible solutions of the methods to climb a stars, you are allowed climb one or two steps for each time; what is tim...
阅读全文