Clubhouse需要你解决的算法题之二

书接前文,the coding guy delivered the feature of finding the closest friend in a timely manner. PM got new task from the leads team. They want to improve clubhouse users’ engagement. PM proposed the immediate idea that it would benefit the engagement if we can improve the joining rate of the rooms recommended to users. Dev said, I would prefer to join rooms with my closest friends in. That’s said, we can recommend rooms based on the closeness between the room and the user. ...

February 5, 2021 · 1 min · 367 words

Clubhouse需要你解决的算法题之一

Clubhouse大火,平台迅速聚集了大量用户,每个用户都有自己的profile,profile里除了自己的id,还会标注推荐人。现在产品经理提出一个要求,希望能研究任意两个用户的最近的共同好友在哪。程序员也不知道pm为什么要提这么个要求,但这个功能不算费事,所以程序员决定不与pm多做讨论,因为一般情况下,所谓讨论都沦为给pm扩充知识理清思路的过程。简化起见,profile定义如下,完成TODO,注意,这个API可能会被多次调用。 ...

February 5, 2021 · 1 min · 264 words

俱乐部会所火了

Clubhouse(ch)几乎是一夜爆火,窃以为多少与Elon Musk推荐有关。社交产品几乎已成定居的今天,ch是切中了什么用户痛点,能病毒式传播开来是个有趣且值得研究的对象。 ...

February 4, 2021 · 2 min · 966 words

动态规划系列(1)

01背包问题(01 backpack problem) Problem Given N items and a bag of weight capacity W. Each item has weight w[i] and value v[i]. What’s the most value this bag can hold? E.g., N = 5, W = 10. w = [1 2 3 4 5], v = [5 4 3 2 1] Output: 14. Explanation: Choose item 1 2 3 4 whose total weight is 10 and total value is 14. Solution dp[i][j] := the most value to get if taken from item [1:i] and weight <= j. Then dp[N][W] is the answer to the problem. dp[0][j] = 0 // given 0 items, the value you can get is always 0 dp[i][j] = dp[i-1][j] // if j < w[i], item i cannot be put into the bag = max(dp[i-1][j] // don't take item i dp[i-1][j-w[i]] + v[i]) // take item i, // Time: O(NW), Space: O(NW) public int backpack(int N, int W, int[] w, int[] v) { int[][] dp = new int[N + 1][W + 1]; for (int i = 1; i <= N; i++) { for (int j = 0; j <= W; j++) { // Depends on if there is item of weight 0. // If yes, j starts from 0. Otherwise, j starts from 1. if (w[i - 1] > j) { dp[i][j] = dp[i - 1][j]; } else { dp[i][j] = max(dp[i - 1][j], dp[i - 1][j - w[i - 1]] + v[i - 1]); } } } return dp[N][V]; } // Time: O(NW), Space: O(W) // Since dp[i][j] only depends on dp[i - 1][k], where k <= j, // we can use one dimension array dp[j] public int backpack(int N, int W, int[] w, int[] v) { int[] dp = new int[W + 1]; for (int i = 0; i < N; i++) { for (int j = W; j >= w[i]; j--) { dp[j] = max(dp[j], dp[j - w[i]] + v[i]); } } return dp[W]; }

February 4, 2021 · 1 min · 336 words

无聊的词句有人叫诗

Bothell静夜思 序 某晚理发归,于广袤黑夜驾白色宝驹,风冷气清, 天空无垠,弦月朗照,有云相伴,是有此诗。 夜冷风瑟星光浅,月揽云带欲遮颜. 秋色定染故乡叶,银钩亦悬家中檐。 ...

February 3, 2021 · 1 min · 245 words

无与伦比的绿

于2019/8 微软最后一天,即将奔赴新公司,心情舒畅,原谅一切,发现很多美 我车出车库 速度0迈 5.9秒 速度60迈 天蓝白云飘 树绿鸟儿叫 拂面微风 热闹阳光 路宽两米 我却似奔驰草原 柏油水泥 我却闻到绿草芬芳 每一个人脸上都有笑 我甚至与一切和解 给Nikhal一个微笑 把讨厌的人写进诗 哪怕其人面目可憎 原谅他 原谅啦 谁叫他有辆绿色的车

February 3, 2021 · 1 min · 155 words

杂记

信雅达 不爱红装爱武装”一般翻译成:to be battle-dressed and not rosy-gowned 许渊冲先生则翻译成:to face the powder,not powder the face。 ​​​ 麻将 The concept of Mahjong is to create order out of chaos based on random drawing of tiles (麻将的内核是通过随机抓牌在混乱中建立秩序) ...

February 3, 2021 · 1 min · 464 words

大白传

有葱省大白者,少聪慧。弱冠及第乡试,旋会试,后求学于美利坚,研习变脸术。经六年乃成,称深假也。时乔氏苹果欲变脸术于手机,大白得势,骄宠一时。然其性猥,喜倚红偎翠,偷香窃玉,终日声色犬马。初喜东京卡哇伊,后慕欧美大胸波,朝秦暮楚,终无所获。几近不惑,恍觉立世不过白云苍狗。遂弃抛尼哈博,终日饮酒垂钓慨叹世情。及暮年,日上三竿尤不起,皆因年少不知精珍贵。 ...

February 3, 2021 · 1 min · 175 words

别微软

于2019/8 时维九月,序属三秋。乘高铁自金陵入京,转三万尺鹏鸟,穿万里长云,赴未眠西雅图。及雨拍弦窗,知身已入他乡。 起始于视觉工作室组(VS),坐息尚乱,懵懵懂学C#,昏昏然习.NET。两年有余,经项目些许,造开发工具若干。及阿尔法狗横空出世,人工智能风云骤起。蠢蠢欲动之际,得入多伦多组。与造项目101诸公论知识驱动引擎,探聊天基础服务,受教对话门户设计, 管窥深度学习, 概览自然语言理解,略通数据分析。所获颇丰,受益良多,难以一一言表,惟感念于心。及至重组,掩袖工谗者当道,开疆拓土者去国。藉此别微软,前路问谷歌。 ...

February 3, 2021 · 1 min · 365 words

关于我

文如其人,看文章就够了。 皆为原创,虽非精品,也是心血。如需转载,注明出处。

February 2, 2021 · 1 min · 37 words