骨骼清奇Other

LC 849 Maximize Distance to Closest Person
LC 334 Increasing Triplet Subsequence
LC 215 Kth Largest Element in an Array
LC 769 Max Chunks To Make Sorted
LC 31 Next Permutation

[Uber]求n的阶层.F(n) = n(n-1)(n-2)....1; 但是n很大,所以不能整数相乘。我提出写一个helper function, 转换成两个string 相乘(Multiplication LC原题),但是他说一个可以不用转换, 直接用int.
[骨骼清奇]给定一个数组,将其分成两个subgroup使得二者的和相等。follow up: 如果是分成k个group怎么做?

remove ‘a' from char array (move zero 变形)
remove 'a' and replace 'b' with 'bee' from char array 用stringbuilder写完让我inplace O1 写. 扫两遍就行了 第一遍去a不变b,第二遍反着扫加bee. 可以两个pointer,一个start,一个end, start遇到b, end可以move backward with 'eeb' 然后reverse.第一题先从头向后移除‘a', 同时算 'b'的个数
然后根据b的个数来算一个offset。
再从后向前扩展原子串吧.
利口把伞伞 + helllloooo那道面经
找到一个string的list里Kth most frequent element。bucket sort? 要求平均时间复杂度O(n),注意是平均。follow up了一个平衡二叉树的查询平均时间复杂度是多少.

LC324

Q: Rearrange a linked list containing a single character per node so that each word is reversed but the overall word order is preserved thus
['h']->['i']->[' ']->['y']->['o']->['u']->null becomes
['i']->['h']->[' ']->['u']->['o']->['y']->null

第一轮题目是给定坐标系中的一堆点,然后求最小的横平竖直的矩形的面积。我只想到了n^3的暴力解法,还因为紧张一开始把复杂度说错了,写代码的时候还卡住了。这一轮表现很差。
第二轮是给定一堆LC标准Tree Node,然后要求判定这些node是否构成唯一合法的二叉树。题比较简单,没有费太大功夫。
第三轮比较奇怪,大概算是OOD题,要求设计一个能够支持模拟魔方的数据结构和后端API。花了很长时间才确定到底怎么做,而且代码量非常大,最后没写完。应该是没戏了。
第四轮是给定一个存有整数的iterator,这个iterator里每两个数字一组,每组的第一个数字表示要重复的次数,第二个数字表示要重复的数字,比如拿到[2, 3]就意味着3这个数字要重复两次。要求实现一个新的iterator,返回进行过重复后的数字(比如前例需要返回的是[3, 3, 3])。比较简单,但是没能够bug-free,出现了数个bug在test过程中才改正。这一轮表现也不行。

Catalog:
LC 853 Car Fleet
LC 659 Split Array into Consecutive Subsequences

LC八五三(高速路车分cluster)
频率:5
Input: target = 12, position = [10,8,0,5,3], speed = [2,4,1,1,3]
Output: 3
Explanation:
The cars starting at 10 and 8 become a fleet, meeting each other at 12.
The car starting at 0 doesn't catch up to any other car, so it is a fleet by itself.
The cars starting at 5 and 3 become a fleet, meeting each other at 6.
Note that no other cars meet these fleets before the destination, so the answer is 3.
N cars are going to the same destination along a one lane road. The destination is target miles away.
Each car i has a constant speed speed[i] (in miles per hour).
A car can never pass another car ahead of it, but it can catch up to it, and drive bumper to bumper at the same speed.
If a car catches up to a car fleet right at the destination point, it will still be considered as one car fleet.

How many car fleets will arrive at the destination?
0 <= position[i] < target
All initial positions are different.

分析:如何判断车A会不会汇入它前面的车队?A到达终点的时间计算出来比车队长,就分别到达!因此我们按照出发地点排序,如果能追上前车,就merge,不能就continue.

class Solution:
    def carFleet(self, target, position, speed):
        """
        :type target: int
        :type position: List[int]
        :type speed: List[int]
        :rtype: int
        """
        time = [float(target - p) / s for p, s in sorted(zip(position, speed))]
        #hour required for car at each position from left to right
        res = cur = 0
        for t in time[::-1]:
            if t > cur: #can not catch the car fleet upfront
                res += 1
                cur = t
        return res

LC 659 Split Array into Consecutive Subsequences [Freq:5]顺子
You are given an integer array sorted in ascending order (may contain duplicates), you need to split them into several subsequences, where each subsequences consist of at least 3 consecutive integers. Return whether you can make such a split.

Input: [1,2,3,3,4,4,5,5]
Output: True
Explanation:
You can split them into two consecutive subsequences :
1, 2, 3, 4, 5
3, 4, 5

Input: [1,2,3,4,4,5]
Output: False

最后编辑于
©著作权归作者所有,转载或内容合作请联系作者
  • 序言:七十年代末,一起剥皮案震惊了整个滨河市,随后出现的几起案子,更是在滨河造成了极大的恐慌,老刑警刘岩,带你破解...
    沈念sama阅读 194,761评论 5 460
  • 序言:滨河连续发生了三起死亡事件,死亡现场离奇诡异,居然都是意外死亡,警方通过查阅死者的电脑和手机,发现死者居然都...
    沈念sama阅读 81,953评论 2 371
  • 文/潘晓璐 我一进店门,熙熙楼的掌柜王于贵愁眉苦脸地迎上来,“玉大人,你说我怎么就摊上这事。” “怎么了?”我有些...
    开封第一讲书人阅读 141,998评论 0 320
  • 文/不坏的土叔 我叫张陵,是天一观的道长。 经常有香客问我,道长,这世上最难降的妖魔是什么? 我笑而不...
    开封第一讲书人阅读 52,248评论 1 263
  • 正文 为了忘掉前任,我火速办了婚礼,结果婚礼上,老公的妹妹穿的比我还像新娘。我一直安慰自己,他们只是感情好,可当我...
    茶点故事阅读 61,130评论 4 356
  • 文/花漫 我一把揭开白布。 她就那样静静地躺着,像睡着了一般。 火红的嫁衣衬着肌肤如雪。 梳的纹丝不乱的头发上,一...
    开封第一讲书人阅读 46,145评论 1 272
  • 那天,我揣着相机与录音,去河边找鬼。 笑死,一个胖子当着我的面吹牛,可吹牛的内容都是我干的。 我是一名探鬼主播,决...
    沈念sama阅读 36,550评论 3 381
  • 文/苍兰香墨 我猛地睁开眼,长吁一口气:“原来是场噩梦啊……” “哼!你这毒妇竟也来了?” 一声冷哼从身侧响起,我...
    开封第一讲书人阅读 35,236评论 0 253
  • 序言:老挝万荣一对情侣失踪,失踪者是张志新(化名)和其女友刘颖,没想到半个月后,有当地人在树林里发现了一具尸体,经...
    沈念sama阅读 39,510评论 1 291
  • 正文 独居荒郊野岭守林人离奇死亡,尸身上长有42处带血的脓包…… 初始之章·张勋 以下内容为张勋视角 年9月15日...
    茶点故事阅读 34,601评论 2 310
  • 正文 我和宋清朗相恋三年,在试婚纱的时候发现自己被绿了。 大学时的朋友给我发了我未婚夫和他白月光在一起吃饭的照片。...
    茶点故事阅读 36,376评论 1 326
  • 序言:一个原本活蹦乱跳的男人离奇死亡,死状恐怖,灵堂内的尸体忽然破棺而出,到底是诈尸还是另有隐情,我是刑警宁泽,带...
    沈念sama阅读 32,247评论 3 313
  • 正文 年R本政府宣布,位于F岛的核电站,受9级特大地震影响,放射性物质发生泄漏。R本人自食恶果不足惜,却给世界环境...
    茶点故事阅读 37,613评论 3 299
  • 文/蒙蒙 一、第九天 我趴在偏房一处隐蔽的房顶上张望。 院中可真热闹,春花似锦、人声如沸。这庄子的主人今日做“春日...
    开封第一讲书人阅读 28,911评论 0 17
  • 文/苍兰香墨 我抬头看了看天上的太阳。三九已至,却和暖如春,着一层夹袄步出监牢的瞬间,已是汗流浃背。 一阵脚步声响...
    开封第一讲书人阅读 30,191评论 1 250
  • 我被黑心中介骗来泰国打工, 没想到刚下飞机就差点儿被人妖公主榨干…… 1. 我叫王不留,地道东北人。 一个月前我还...
    沈念sama阅读 41,532评论 2 342
  • 正文 我出身青楼,却偏偏与公主长得像,于是被迫代替她去往敌国和亲。 传闻我的和亲对象是个残疾皇子,可洞房花烛夜当晚...
    茶点故事阅读 40,739评论 2 335

推荐阅读更多精彩内容