莫的职业和生活可能让我们大部分人都会艳羡。从小到大的学霸,只要自己感兴趣的学科,通过读书就能一一化解;从微软到谷歌,事业好得一塌糊涂;生活更是如此,鼠标一点,两辆劳斯劳斯老爷车就开进了自家的车库。对了,有一点和我们好像是一样的哦!因为莫的妈妈从小就告诉他:努力学习,努力工作,拥有了财富,你就拥有了永远的快乐。莫是一个乖宝宝,当他按照妈妈的教诲都做到了之后,他问妈妈:快乐在哪儿呢?
Read full article from 奇点阅读
The Troubleshooters.Com xargs Guide
xargs is a black box. You seldom know what it's going to do, and given the kinds of things it's used for, this can be very dangerous. Personally, I never put rm at the end of an xargs equipped command line. I'm not that brave: I'd rather pipe to a file, and manually convert that file to a bunch of deletions while making sure I'm not doing anything stupid.
Read full article from The Troubleshooters.Com xargs Guide
Keenhenry and his Web residence
Finding the longest common substring or common prefix or suffix of a group of strings is a common text processing problem. And it is a special case of edit distance problem.
This problem has a wide range of applications in different areas, i.e. computation biology and information retrieval from texts, and so on. I encountered this problem at work and I would like to give an extensive survey to this problem.
Read full article from Keenhenry and his Web residence
CodeForces 451D Count Good Substrings - 程序园
一个只包含a和b的字符串 问 它有几个长度为偶数和长度为奇数的"压缩回文串" 压缩的概念是 相邻的相同字符压缩成一个字符
思路:
串经过压缩一定满足如下形式 ……ababab…… 那么这样只要两端的字符相同则中间一定是回文的 因此对于一个a它作为左端点形成的回文串个数就等于它右边的a的个数 那么长度是奇数还是偶数呢 可以这么判断 如果a在奇数位置上和它匹配的a也在奇数位置上 那么形成的回文串就是奇数长度的 要不然就是偶数长度的 b同理 因此得到做法 统计一个字符的右边和它相同的字符在奇数位置和偶数位置的有几个 然后通过计算就可以得到结果
Read full article from CodeForces 451D Count Good Substrings - 程序园
Suffix Arrays – A simple Tutorial – Outlooking life
It is the data structure to look out for when you are going for string Searching and want to reduce the time complexity greatly. So, Let us examine and start from basics.
What are Suffix Arrays ?
As simple as it can get , suffix arrays represent the rank of all possible suffixes of a given string .For example ,
Read full article from Suffix Arrays – A simple Tutorial – Outlooking life
Gossip protocol : Machines at water cooler – Outlooking life
Close resemblance to how epidemics spread. But in our case it is a communication protocol.
– Involves pair wise inter process interaction
– After interaction, state of one of two interacting agent changes.
– It may so happen that the interaction fails between the processes.
– Cost of interaction is deemed negligible.
– Peers for inter process communication are selected randomly.
– There may be duplication in the message being gossiped, i.e. Both the agents were already aware of the messages being gossiped.
Read full article from Gossip protocol : Machines at water cooler – Outlooking life
Read full article from ***D. Maximum Xor Secondary( find max and 2nd max in all possible sub array of an array in o(n)) | implementation
Tries are some kind of rooted trees in which each edge has a character on it. For a bunch of strings, their trie is the smallest rooted tree with a character on each edge and each of these strings can be build by writing down the characters in the path from the root to some node.
Read full article from Tries Tutorial | Commonlounge
Deep Dive into MVP(0x01) – JP Wang – Code with fun :)
MVP(Model-View-Presenter) pattern is a derivative from the well known MVC
(Model-View-Controller) which for a while now is gaining importance in the development of Android applications.
The MVP allows seprate the presentation layer from the logic, so that the things about how the interface works are separate from how we represent it on screen.
Keep in mind: MVP is not an architecture pattern, it's only responsible for the presentation layer.
As it's talked above, MVP is just a design pattern to decoupling the presentation layer. So there are a lot of ways to implement it. In this topic, we will show one implementation by combining the real project.
Read full article from Deep Dive into MVP(0x01) – JP Wang – Code with fun :)
It means you are trying to implement a non-existing interface or you're extending an non-existing class.
Try to refresh your Eclipse.
If it doesn't work, it may mean that you have a reference to a JAR that is not in the build path. Check your project's classpath and verify that the jar containing the interface or the class is in it.
Read full article from java - Eclipse compilation error: The hierarchy of the type 'Class name' is inconsistent - Stack Overflow
java - The hierarchy of the type Classe is inconsistent - Stack Overflow
This means you have made an incompatible change in a super class but haven't recompiled it.
I suggest you use a build system like Maven or Ant and/or use an IDE to build all your code.
Read full article from java - The hierarchy of the type Classe is inconsistent - Stack Overflow
How to Use Your Roth IRA as an Emergency Fund
There is an often-overlooked feature of the Roth IRA: emergency fund. Subject to income limits, you can contribute as much as $5,500 annually into a Roth IRA. If you're married, you and your spouse can each contribute $5,500, for a total of $11,000.
The reason that Roth IRA can be your emergency fund is because you can withdraw contributions anytime; it's only a Roth's investment earnings that must remain in your account until you're 59.5 if you want to avoid paying a 10% penalty. Roth IRAs offer this flexibility since you've already paid tax on your contributions, unlike traditional IRA contributions, on which you haven't paid taxes yet.
The advantage to putting emergency savings into a Roth IRA is that you don't miss the limited opportunity to make that year's retirement contribution. You can only contribute a few thousand dollars to a Roth IRA each year, and once a year passes without you contributing, you lose the opportunity to make that contribution forever. Since the Roth has a relatively low annual contribution limit, you don't want to miss out on making the full contribution for any year. The maximum you can contribute for the year, as of tax year 2016, is the lesser of $5,500, or your taxable compensation for the year. If you're 50 or older, you can contribute the lesser of $6,500 or your taxable compensation for the year.
Read full article from How to Use Your Roth IRA as an Emergency Fund
在美国如何正确购买猪肉 Every Cut of Pork Explained
本文详述了美国常见的猪肉的部分,以及各部分对应的中文名称。
English | 中文 | 部位 |
---|---|---|
Leaf lard | 板油 | 猪肚子上的成条状的肥肉 |
Tenderloin | 里脊肉 | 脊椎骨内侧的条状嫩肉 |
Trotter | 猪手 | 脚部 |
Hock | 蹄髈 | 踝关节和小腿 |
Picnic | 上肩肉、叉烧肉 | 后背靠头的肩膀肉 |
Butt | 梅花肉 | 肩前端的腿肉 |
Scapula/shoulder blade | 肩胛骨 | 脊椎到前蹄的骨头 |
Spare rib | 小排 | 肋骨中腹部两侧的部分 |
Brisket | 胸部 | 排骨外侧表皮部分 |
Pork denver (presa) | 猪颈肉 | 肩膀肉的一部分 |
Coppa | 肩颈肉 | 肩膀肉的一部分 |
Belly | 肋条肉 | 腹部的肉 |
Chop | 大排 | 背部脊椎骨两侧外部的肌肉,另一侧为里脊 |
Loin | 猪腰肉 | 背部脊椎骨两侧的肉的总称,包括大排和周围的脂肪和肌肉组织 |
Baby back rib | 仔排 | 肋骨中与背脊相连的部分 |
Sirloin | 后腰脊肉 | 腰背部的肉 |
Aitch bone | 臀骨 | 脊椎和腿骨连接的骨头 |
Femur bone | 大腿骨 | 大腿骨,用于取得骨髓 |
Top round | 后腿的上部 | |
Top cap | Top round 的一部分 | |
Bottom round | 后腿的下部 | |
Sirloin tip | 后腿的下部 | |
Eye round | 后腿的下部 |
Read full article from 在美国如何正确购买猪肉 Every Cut of Pork Explained
有人说《穷查理宝典》是一本投资圣经,而在我眼里,它是一本"学习圣经"。在捧卷阅读的那一刻,我也万万没想到,《穷查理宝典》竟然取代了《人类简史》成为我看过的年度最好的书,并且,这是除小说外唯一一本让我通宵达旦停不下来的书。
在此,我想先谈谈我为什么要读《穷查理宝典》这本书。为什么要读这本书,这其实也是一个"选择",而我做出这个"选择"只添加了一个必要条件:有用。因为,对我而言,向聪明人学习是最有效的学习方式。查理.芒格是沃伦.巴菲特的合伙人,而巴菲特又是神一般的存在,所以我相信他的合伙人——查理也是非常聪明的人。而且,在我最近阅读的资料里,《穷查理宝典》曾被多次提及,好奇心驱使我迫不及待地想要知道,这本书里到底传授了什么样的智慧?
通过阅读,整本书给我印象最深的只有五个关键词:问题、大量阅读、逆向思考、检查清单、经常使用。正所谓,水滴石穿,重复的力量无比巨大,全书都只在不断重复这五个关键词,这就是大道至简。
Read full article from 《穷查理宝典》 读书笔记 | 媛媛的小窝
hihocoder [Offer收割]编程练习赛12 [1495] ---- 矩形分割 - HorseShoe2016 - 博客园
记 int total=N*M,这里会有 total 个方块,因为一道对角线(''或者'/')会把一块方块分割为左右两部分,所以,我们把任意一块方块看做左右两个部分。对于左部分,从左到右从上到下依次编号为 0~total-1;对于右部分,从做到右从上到下依次编号为 total~2*total-1;用一个 int parent[20000] (因为1<=N,M<=100; 所有最多有10000个方块,也就是最多有20000个半部分) 的数组来记录一个部分所属于的集合编号。初始化 parent[i]=i;
Read full article from hihocoder [Offer收割]编程练习赛12 [1495] ---- 矩形分割 - HorseShoe2016 - 博客园
Read full article from 幻魔皇——解题报告 - 风中的微尘的博客 - CSDN博客
Release 1.0 of Marple, a Lucene index detective -
Marple was envisaged as an alternative to Luke, a GUI tool for introspecting Lucene indexes. Luke is a powerful tool but its Java GUI has not aged well, and development is not as active as it once was. Whereas Luke uses Java widgets, Marple achieves platform independence by using the browser as the UI platform. It has been developed as two loosely-coupled components: a Java and Dropwizard web service with a REST/JSON API, and a UI implemented in React.js. This approach should make development simpler and faster, especially as there are (arguably) many more React experts around these days than native Java UI developers, and will also allow Marple's index inspection functionality to be easily added to other applications.
Read full article from Release 1.0 of Marple, a Lucene index detective -
Hadoop小文件解决方案-Hadoop小文件的前因后果 - 个人文章 - SegmentFault 思否
拥有大量小文件会降低MapReduce处理的性能,无论是Hive,Pig,Cascading,Pentaho MapReduce还是Java MapReduce。第一个原因是大量的小文件意味着大量的随机磁盘IO。磁盘IO通常是MapReduce性能的最大限制因素之一。一次大的顺序读取总是胜过通过几次随机读取相同数量的数据。如果您可以将数据存储在更少,更大的块中,则可以减轻磁盘IO的性能影响。
性能下降的第二个原因有点复杂,需要了解MapReduce如何处理文件和调度资源。我将在此解释中使用MapReduce版本1术语,因为它比使用Yarn更容易解释,但相同的概念适用于Yarn。当MapReduce作业启动时,它会为每个正在处理的数据块计划一个映射任务。存储在Hadoop中的每个文件至少有一个块。如果您有10,000个文件,每个文件包含10 MB的数据,则MapReduce作业将安排10,000个map任务。通常配置Hadoop,以便每个map任务在其自己的JVM中运行。
您的Hadoop集群只有这么多资源。在MapReduce v1中,为避免节点过载,请指定节点可以处理的最大并发map数。通常,map的最大数量在5到20范围内。因此,要同时运行10,000个map,您必须拥有500到2000个节点。大多数Hadoop集群都小于此,导致JobTracker在等待打开的插槽时对map任务进行排队。如果您有一个包含总共100个插槽的20个节点群集,则您的队列将变得非常大,并且您的过程将花费很长时间。不要忘记,您的工作可能不是竞争集群资源的唯一工作。
如果您拥有800个128 MB的文件而不是10,000个10MB文件,那么您只需要800个map任务。这将需要一个数量级减少JVM维护时间,并将导致更好的磁盘IO。即使处理128 MB的单个map任务将花费比处理10 MB的map任务处理更长的时间,但是当处理800个更大的文件时,所有处理时间的总和几乎总是要快几个数量级。
Read full article from Hadoop小文件解决方案-Hadoop小文件的前因后果 - 个人文章 - SegmentFault 思否
Don't use TextField for your unique key in Solr · Los Techies
This seems immediately obvious when you think about it, but TextField is what you use for fuzzy searches in Solr, and why would a person want a fuzzy search on a unique value? While I can come up with some oddball use cases, making use of copy fields would seem to be the more valid approach and fitting with the typical use of Solr IE you filter on strings and query on text.
Read full article from Don't use TextField for your unique key in Solr · Los Techies
Changing Bits: Choosing a fast unique identifier (UUID) for Lucene
The purpose of the terms dictionary is to store all unique terms seen during indexing, and map each term to its metadata (docFreq
, totalTermFreq
, etc.), as well as the postings (documents, offsets, postings and payloads). When a term is requested, the terms dictionary must locate it in the on-disk index and return its metadata. Read full article from Changing Bits: Choosing a fast unique identifier (UUID) for Lucene
时间复杂度是O(n)
。当然这种思路并不高效,做了很多重复工作。比如a^32
完全可以由a^16
平方得到,a^16
可以由a^8
平方得到,以此类推直到a^1
;而奇数情况下则只需要再乘一次a
即可。而由这个思路则可以得到如下打码:
Read full article from 剑指offer 11 数值的整数次方 | 碎碎念
Minimum XOR Value Pair - GeeksforGeeks
Given an array of integers. Find the pair in an array which has minimum XOR value.
Examples :
Input : arr[] = {9, 5, 3} Output : 6 All pair with xor value (9 ^ 5) => 12, (5 ^ 3) => 6, (9 ^ 3) => 10. Minimum XOR value is 6 Input : arr[] = {1, 2, 3, 4, 5} Output : 1
Read full article from Minimum XOR Value Pair - GeeksforGeeks
Master the macOS Open and Save Dialogs | The Mac Security Blog
Read full article from Master the macOS Open and Save Dialogs | The Mac Security Blog
[HackerRank] Roads and Libraries
Read full article from [HackerRank] Roads and Libraries
[1,2,3]
, a solution is:[ [3], [1], [2], [1,2,3], [1,3], [2,3], [1,2], [] ]
Read full article from [LeetCode] 78. Subsets
Tax-loss harvesting provides a mean of improving the after-tax return on taxable investments. It is the practice of selling securities at a loss and using those losses to offset taxes from gains from other investments and income. Depending on how much loss is harvested, losses can be carried over to offset gains in future years. Tax-loss harvesting often occurs in December, with December 31 being the last day to realize a capital loss. Taxable investment accounts identify realized gains incurred for the year and find losses to offset those gains. Doing so allows the investor to avoid paying capital gains tax. If the investor wants to repurchase the same investment, they must wait 31 days to avoid a wash sale. For example, suppose a taxable account currently has $10,000 of realized gains that were incurred during the calendar year, yet, within its portfolio is Apple stock with an unrealized loss of $9,000. If the Apple stock was sold on or prior to December 31, the investor would realize $1,000 ($10,000 gains - $9,000 Apple loss) in capital gains.
Abiding by the wash-sale rule, if the stock was sold on December 31, the investor would need to wait until January 31 to repurchase it.
Read full article from Capital Loss Carryover
Are you still paying for unused memory when your Java app is idle? - Java SDK
This is precisely what Eclipse OpenJ9 brings to the table. The OpenJ9 JVM has the ability to identify when an application is idle and reduce the reserved heap size down to its actual usage. This feature is enabled by specifying the –XX:+IdleTuningGcOnIdleoption option. OpenJ9 determines if an application is idle based on CPU utilization and other internal heuristics. When an idle state is established, a GC cycle runs if there is significant garbage in the heap and releases unused memory back to the operating system.
So, there is no need to worry about memory consumption and charges during idle periods. OpenJ9 is there to do the right thing, at the right time, in the right way!
Read full article from Are you still paying for unused memory when your Java app is idle? - Java SDK
Are you still paying for unused memory when your Java app is idle? - Java SDK
The Hotspot™ JVM has an option called –XX:-ShrinkHeapInSteps, which shrinks the heap to its actual usage after every full garbage collection (GC) cycle. But this has a drawback; the onus is on the application developer to figure out when the application is idle and then call System.gc()
.
There are some Java agents on the market that make use of the Hotspot option to automatically maintain the heap at the optimal size. But there is a drawback to these external agents too. They are not completely aware of the internal characteristics or state of the heap in order to make an informed decision about triggering a GC cycle. The agent makes decisions based on some heuristics, which might negatively impact application performance if the GC cycle is not timed correctly.
Wouldn't it be better if your JVM, which does knows the exact state of the Java heap and the application, could recognize when your application is idle and take the opportunity to reduce the memory footprint?
Read full article from Are you still paying for unused memory when your Java app is idle? - Java SDK
10 Things You Must Know About Facebook Interview Process » My Tech Interviews
Read full article from 10 Things You Must Know About Facebook Interview Process » My Tech Interviews
Google Kickstart 2017 Round F题解 | Calvin's Marbles
Google Kickstart 2017 Round F,当时做了两条就睡觉了,早上把剩下两条也过了。感觉不算是很难,可能也和这场限时24h有关吧。不过提交的时候倒是手忙脚乱,第一条交了三发,第一发是从VS迁移到DevC上是DevC由于之前配了个C++14所以崩了,第二发输出里面是Unicode BOM,WA了,蛋疼。
找规律发现每次找的pivot的位置是从原数组的中心点(奇)或中心线靠左(偶)开始,如果小于原数组的中位数,则下一个位置是其轴对称,否则是其左边一个位置。这样从数组的中部交替往外移动,结束条件是pivot到达原数组的最后一个元素。由于这个过程中所有选为的pivot都是最大/小值才返回YES,否则直接返回NO,所以只要迭代继续,我们去掉的就一直是最大/小值。因此使用l和r记录此时所有还没被作为pivot去掉的数中的最大/小值,判断新的pivot是否等于l或r。
Read full article from Google Kickstart 2017 Round F题解 | Calvin's Marbles
Leetcode解题报告 | Calvin's Marbles
寒假没事情,在家里刷Leetcode。这里放的是LeetCode解题报告【更新中】,代码在GitHub上,有些被坑的题目会专门写一篇post。
必须先对Leetcode吐个槽,这复杂度卡的真是魔幻,同样的复杂度C++能过,Python就不能过,而且都是卡在最后两三个样例上(不会就最后两三个大数据吧?)
Leetcode上面有题解,不过有时候很奇怪他们算复杂度的时候会强行令某些操作,比如判断字符串是否相等(Problem 14),std::map
查找元素(Problem 1)的复杂度为1,感觉这并不是很严谨的,后来在Google Codejam/Kickstart的官方题解上也看到类似的算法,只能说这是一种计算方式吧。
在刷Leetcode的时候,取得Accepted通常是容易的,但是如果能够翻翻Submissions里面速度靠前的答案,看看人家是怎么在同复杂度下进行常数优化也是很有必要的。
Read full article from Leetcode解题报告 | Calvin's Marbles
Read full article from Julia's coding blog - Practice makes perfect: Leetcode 689. Maximum Sum of 3 Non-Overlapping Subarrays (II)
Read full article from 如何进入 Google 工作
[uva 591] Box of Bricks – hwchang0417
輸入n和n個高度的堆疊,試問最少需要多少移動次數,可以將所有堆疊堆成一樣高?
Programming Language: C
Execution time: 0 ms
Solution:
統計所有堆疊的高度,求得平均後,計算所有堆疊的高度減去平均高度的和,表示每個堆疊要堆到平均高度所需的次數,由於題目是把高的堆疊堆到低的堆疊,所以移動次數等於和的1/2。
Read full article from [uva 591] Box of Bricks – hwchang0417
[uva 10642] Can You Solve It? – hwchang0417
給定source和destination的座標,試計算中間必須經過多少次邊界,座標走訪必須試沿+x, +y座標上的Z字形走訪。
Programming Language: C
Solution:
列出(0, 0)到(4, 0)的所有邊界次數
(0, 0) => 0
(0, 1) => 1
(1, 0) => 2
(0, 2) => 3
(1, 1) => 4
(2, 0) => 5
(0, 3) => 6
(1, 2) => 7
(2, 1) => 8
(3, 0) => 9
(0, 4) => 10
發現當y等於3時,3 * 2 = 6,當y等於4,4 * 2.5=10,其距離間距呈現下列關係:
(倍率 = 1 + 0.5f * (y – 1)),爾後x每增加一個座標,邊界次數加一,故公式改為:
steps(n, x) = (1 + 0.5f * (n – 1)) * n + x,其中n為x+y
於是可以用下列方式求得source到destination的邊界走訪次數
n1 = x1 + y1; n2 = x2 + y2;
ans = steps(n2, x2) – steps(n1, x1);
steps(n, x) = (1 + 0.5f * (n – 1)) * n + x
Read full article from [uva 10642] Can You Solve It? – hwchang0417
You are given a square grid of size dxd. It contains each |
Read full article from Googel Mock Interview记录
Given n processes, each process has a unique PID (process id) and its PPID (parent process id).
Each process only has one parent process, but may have one or more children processes. This is just like a tree structure. Only one process has PPID that is 0, which means this process has no parent process. All the PIDs will be distinct positive integers.
We use two list of integers to represent a list of processes, where the first list contains PID for each process and the second list contains the corresponding PPID.
Now given the two lists, and a PID representing a process you want to kill, return a list of PIDs of processes that will be killed in the end. You should assume that when a process is killed, all its children processes will be killed. No order is required for the final answer.
Example 1:
Input: pid = [1, 3, 10, 5] ppid = [3, 0, 5, 3] kill = 5 Output: [5,10] Explanation: 3 / \ 1 5 / 10 Kill 5 will also kill 10.
Note:
把进程结构看成一棵树,要杀死某个进程,必定也要杀死他的所有子进程。
3 / \ 1 5 <-- 如果目标是5,则删除以5为根的整棵子树 / 10
因为题目给出了所有进程对应的父进程,所以很容易找出任意进程的所有子进程。所以BFS一层一层顺藤摸瓜很简单。
Read full article from Hello SHEN
I interviewed at five top companies in Silicon Valley in five days, and luckily got five job offers
In the five days from July 24th to 28th 2017, I interviewed at LinkedIn, Salesforce Einstein, Google, Airbnb, and Facebook, and got all five job offers.
It was a great experience, and I feel fortunate that my efforts paid off, so I decided to write something about it. I will discuss how I prepared, review the interview process, and share my impressions about the five companies.
Read full article from I interviewed at five top companies in Silicon Valley in five days, and luckily got five job offers
I interviewed at six top companies in Silicon Valley in six days, and stumbled into six job offers
Edit: wow, this got a lot more popular than I anticipated. Based on that, I plan on doing more write-ups about other parts of the process, including negotiation. Follow my new Twitter for updates :)
All of the below is heavily inspired by this post from last year that originally pushed me to consider the possibility of moving companies, posted one year ago today. I didn't want to fly across the country repeatedly to find my perfect job, so I knew I had to schedule them alongside each other and gut it out.
Read full article from I interviewed at six top companies in Silicon Valley in six days, and stumbled into six job offers
Google Interview Questions Deconstructed: The Knight's Dialer
This is the second in a series of posts in which I share my advice for candidates interviewing for tech companies, drawing on my experience as an engineer and interviewer at Google. If you haven't already, take a look at the introduction to this series.
Before I start, a disclaimer: while interviewing candidates is one of my professional responsibilities, this blog represents my personal observations, my personal anecdotes, and my personal opinions. Please don't mistake this for any sort of official statement by or about Google, Alphabet, or any other person or organization.
This was the first problem I used during my interviewing career, and it was also the first to leak and get banned. I like it because it hits number of sweet spots:
Read full article from Google Interview Questions Deconstructed: The Knight's Dialer
Longest subarray with elements divisible by k - GeeksforGeeks
Suppose you a given an array. You have to find the length of the longest subarray such that each and every element of it is divisible by k.
Examples:
Input : arr[] = { 1, 7, 2, 6, 8, 100, 3, 6, 16}, k=2 Output : 4 Input : arr[] = { 3, 11, 22, 32, 55, 100, 1, 5}, k=5 Output : 2
Read full article from Longest subarray with elements divisible by k - GeeksforGeeks
Given an array of integers. Find the maximum number of consecutive integers present in the array. For example, if the array is:
int arr[] = { 2, 24, 22, 60, 56, 23, 25};
Then the answer should be 4, because there are 4 consecutive integers present in the array (22, 23, 24, 25).
Solution:
The brute-force way is to traverse the array, and for each element find the maximum length of consecutive integers present in the array if this element (current element) is the starting point.
int maxConsecutiveLength(int*arr, int n) { int max = 1; // MAX CONSECUTIVE INTEGERS for(int i=0; i<n; i++) { int val = arr[i]; // SEARCH NEXT INTEGER IN THE ARRAY while(findInArray(arr, n, val+1)) val++; if(max < (val+1 - arr[i]) ) max = val+1 - arr[i]; } return max; }
Read full article from Maximum consecutive integers present in an array – Ritambhara Technologies – Coding Interview Preparations
Finding and fixing software bugs automatically with SapFix and Sapienz - Facebook Code
Debugging code is drudgery. But SapFix, a new AI hybrid tool created by Facebook engineers, can significantly reduce the amount of time engineers spend on debugging, while also speeding up the process of rolling out new software. SapFix can automatically generate fixes for specific bugs, and then propose them to engineers for approval and deployment to production.
SapFix has been used to accelerate the process of shipping robust, stable code updates to millions of devices using the Facebook Android app — the first such use of AI-powered testing and debugging tools in production at this scale. We intend to share SapFix with the engineering community, as it is the next step in the evolution of automating debugging, with the potential to boost the production and stability of new code for a wide range of companies and research organizations.
Read full article from Finding and fixing software bugs automatically with SapFix and Sapienz - Facebook Code
Read full article from 为什么说算法工程师的面试是一门玄学? - 知乎
【新提醒】马克2016找工季总结,拿到g和f,从了facebook【一亩三分地论坛求职版】 -
很多身边的朋友问我算法怎么准备,我只能回答一个字:"直接刷题"。楼主之前听过xx算法的高级算法课,感觉课还不如附送的ladder管用,(ladder是真好用)。然后又听了各种各样的算法课,(13年夏天啃掉了算法导论,听了mit的算法,算是打了比较扎实的基础),还是推荐算法挺princeton大爷在coursera的公开课,这门课深入浅出,基本lz答的80%的follow up都是从这学到的。Read full article from 【新提醒】马克2016找工季总结,拿到g和f,从了facebook【一亩三分地论坛求职版】 -
Codeforces 873D. Merge Sort 分治 + 构造 - WA是一笔财富 - CSDN博客
题意:给出一种特殊的归并排序,分治的方法同普通的归并排序一样,只是如果当前待排序的区间已经是有序的,就不会再继续递归了,让你构造一个会调用k次mergesort函数的序列。
思路:因为我们上来就会调用一次mergesort函数,并且只要当前待排序区间不是有序的,那么在该层递归里就会调用两次mergesort,因此可以推出总调用次数一定是个奇数。然后我们递归的构造答案序列(令答案序列初始有序),若k > 2, 我们就将当前区间的a[mid]和a[mid - 1]交换一下,这样可以保证下一层递归传进去的区间一定是个有序区间,这不会样影响k==1时候的退出(按照题给定义,必须当前区间有序才能退出)。交换后k就少了2,一直这样递归构造,出口就是l + 1 == r或者k == 1.
Read full article from Codeforces 873D. Merge Sort 分治 + 构造 - WA是一笔财富 - CSDN博客
当爹妈情绪失控时,孩子难免会伤心难过、不知所措。这时父母应该赶紧补救。
我们往往控制不住冲孩子发牌气,或者将坏情绪转嫁给孩子。孩子看似 "哭一哭就过去了", 但其内心的伤害,需要我们去修复。
周末,妈妈边加班边照顾丫丫。丫丫找不到洋姓姓,开始闹牌气,妈妈只好帮找洋娃娃。
不一会,丫丫因为洋洋娃娃掉水盆里而哭闲,她又要去哄丫丫,就在她晾晒洋娃姓的时候,丫丫将水盆端到客厅,水撒了一地……
" 闹够没有! 再不乖就不带你去公园了!" 妈妈吼起来。
丫丫委屈伤心地哭了,妈妈一时有种说不清的愧疚和难过。
Read full article from 吼完就后悔?这样跟孩子修好 - 简书
Count pairs in an array that hold i+j= arr[i]+arr[j] - GeeksforGeeks
Given an array of integers arr[], the task is to count all the pairs (arr[i], arr[j]) such that i + j = arr[i] + arr[j] for all 0 ≤ i < j < n.
Note: Pairs (x, y) and (y, x) are considered a single pair.
Read full article from Count pairs in an array that hold i+j= arr[i]+arr[j] - GeeksforGeeks
(99+) Key to nailing the interviews - LeetCode Discuss
For the longest time, I thought that passing an interview requires you to successfully solve a problem. The solution you provide should be optimal and you need to code it.O(log(n))
solution. The second was a Single Runway Airport problem. It was a complicated problem, so I won't go into details. The interviewer was happy with my solutions and he scheduled me for another round. Mind you that I was a novice at LeetCode that time, and had hardly done like 3-4 problems. Later during the day, I googled the solution for the Peak Value problem and found the solution in LeetCode and that's when I realized how important it is to practice different kinds of problems.Read full article from (99+) Key to nailing the interviews - LeetCode Discuss
LeetCode : Count of Range Sum – Stokastik
This one looks like a very simple problem at first glance but I found it to be quite tricky during implementation. The straightforward solution is to pre-compute the prefix sums S(i), i.e. the sum of all integers from 0 to i-th index for all possible i, and then compute all possible range sums S(i, j), which is the sum of all integers from index i to index j. This can be computed by the simple formula S(i, j) = S(j) - S(i-1). After we have obtained the sums S(i, j) for all pairs i, j (i <= j), we simply check whether S(i, j) lies within the [lower, upper] range. Since there are O(N2) number of pairs i, j and for each pair, the operation of computing the sum S(i, j) and checking if the sum lies within [lower, upper] is O(1), the run-time complexity of this approach is O(N2).
Read full article from LeetCode : Count of Range Sum – Stokastik
counts[i]
is the number of smaller elements to the right of nums[i]
.Given nums = [5, 2, 6, 1] To the right of 5 there are 2 smaller elements (2 and 1). To the right of 2 there is only 1 smaller element (1). To the right of 6 there is 1 smaller element (1). To the right of 1 there is 0 smaller element.
[2, 1, 1, 0]
.Read full article from Count of Smaller Numbers After Self [LeetCode] | Training dragons the hard way - Programming Every Day!
因为春招的失败,于是从暑假就开始准备秋招,从各个方面开始全面的复习。
暑假参加了网易的内推,结果以失败告终,详情可看:网易内推 Java 开发工程师(一面 + 二面 + HR 面)
其他的内推均没有回复。
于是 9 月开始参加正式的校招。一共投了 24 家互联网公司,都是一些比较常见的公司。其中参加了 5 次面试,剩下的直接放弃,下面就大概写一下经历。时间顺序有点不太记得了。
Read full article from 校招经历 – xuan's blog
ACM计算几何题目推荐(第二期) - open source - 博客园
这次的题目不再局限于POJ了,因为自己去年周游了各个OJ,反而很少在POJ切题了。而且这次推荐的题目比上次难了,也复杂多了。现在看回自己第一次写的计算几何题目推荐,实在感到当时自己写得有点肤浅。其实对于一些大牛来说,这些题目也算不了什么。Read full article from ACM计算几何题目推荐(第二期) - open source - 博客园
问由N个不同字符组成的长度为M的密码串有多少个? 其中对每个密码串所有的N个不同字符都必须出现过.
下面方程的每一组解作全排列之后的所有计数累加,就是答案。假设有一组解为X1,…,Xn,那么该组解的排列之后有 M!/(X1! * X2! * … * Xn!),所有解累加即答案。
Read full article from Google2015校招笔试 Round B
经典问题:数飞机问题
给一些飞机飞行的时间区间。求天上最多有多少个飞机同时在飞。
例如给
|
|
Read full article from 算法-扫描线 | jiayi797
LintCode线段树/扫描线/查询题总结 - Logan's - CSDN博客
线段树(Segment Tree)又叫区间树(Interval Tree),它实际上是一颗二叉树,树种的每一个节点表示一个区间[a, b],左儿子的区间是[a, (a+b)/2],右儿子的区间是[(a+b)/2+1, b]。
线段树常用于区间统计/查询相关的问题:比如某些数据可以按区间进行划分,按区间动态进行修改,而且还需要按区间多次进行查询,那么使用线段树可以达到较快查询速度。动态的求/更新区间和、区间最值就适用于用线段树来求解。
Read full article from LintCode线段树/扫描线/查询题总结 - Logan's - CSDN博客
One of the most common tasks you will find in geometry problems is line intersection. Despite the fact that it is so common, a lot of coders still have trouble with it. The first question is, what form are we given our lines in, and what form would we like them in? Ideally, each of our lines will be in the form Ax+By=C, where A, B and C are the numbers which define the line. However, we are rarely given lines in this format, but we can easily generate such an equation from two points. Say we are given two different points, (x1, y1) and (x2, y2), and want to find A, B and C for the equation above. We can do so by setting
Read full article from Community - Competitive Programming - Competitive Programming Tutorials - Geometry Concepts: Line Intersection and its Applications
Check if a point lies inside a convex polygon | Algorithm Tutor
There are many problems where one needs to check if a point lies completely inside a convex polygon. Before moving into the solution of this problem, let us first check if a point lies left or right of a line segment. A polygon consists of more than two line segments ordered in a clockwise or anti-clockwise fashion. If a point lies left (or right) of all the edges of a polygon whose edges are in anticlockwise (or clockwise) direction then we can say that the point is completely inside the polygon.
Read full article from Check if a point lies inside a convex polygon | Algorithm Tutor
TYUT计算几何与几何题汇
白书2《挑战程序设计竞赛2(算法和数据结构)》 第16章 计算几何学
Read full article from TYUT计算几何与几何题汇 - Virtual Judge
[leetcode] 题型整理之图论 - Gryffin - 博客园
图论的常见题目有两类,一类是求两点间最短距离,另一类是拓扑排序,两种写起来都很烦。
求最短路径:
127. Word Ladder
Given two words (beginWord and endWord), and a dictionary's word list, find the length of shortest transformation sequence from beginWord to endWord, such that:
For example,
Given:
beginWord = "hit"
endWord = "cog"
wordList = ["hot","dot","dog","lot","log"]
As one shortest transformation is "hit" -> "hot" -> "dot" -> "dog" -> "cog"
,
return its length 5
.
Note:
All words contain only lowercase alphabetic characters.
从起点开始向外更新,因为每条路径的权值都不是负数,所以先更新的总比后更新的小。
已经被更新过的之后就不用考虑了
133. Clone Graph
Clone an undirected graph. Each node in the graph contains a label
and a list of its neighbors
.
Nodes are labeled uniquely.
We use#
as a separator for each node, and ,
as a separator for node label and each neighbor of the node.
As an example, consider the serialized graph {0,1,2#1,2#2,2}
.
The graph has a total of three nodes, and therefore contains three parts as separated by #
.
0
. Connect node 0
to both nodes 1
and 2
.1
. Connect node 1
to node 2
.2
. Connect node 2
to node 2
(itself), thus forming a self-cycle.Read full article from [leetcode] 题型整理之图论 - Gryffin - 博客园
Determine if N given rectangles are an exact cover of a rectangle
Given N rectangles with integer coordinates, check whether they are an exact cover of a rectangular region
If you don't know already, Google's on-site interview process involves 5 independent interviews in one day. In each one a Google Software Engineer poses a problem that should be solved in 45 min to 1 hr. The interviewee can code on a white board or in Google Docs (check with your recruiter for details) in a language of their choice, but not pseudo-code.
By itself, the question is not all that intimidating, but the time-limit can make it quite challenging. That's why I'm practising!
As usual, there is a fairly straightforward "brute force" solution, and some better solutions. I'll give hints and solutions immediately after the jump so avoid spoilers by not looking past the example inputs yet.
Read full article from Determine if N given rectangles are an exact cover of a rectangle
Dynamic problem (algorithms) - Wikipedia
Dynamic problems in computational complexity theory are problems stated in terms of the changing input data. In the most general form a problem in this category is usually stated as follows:
Read full article from Dynamic problem (algorithms) - Wikipedia
Algorithms books Reviews | Blog blog("Baptiste Wicht");
To be sure to be well prepared for an interview, I decided to read several Algorithms book. I also chosen books in order to have information about data structures. I chose these books to read:
Read full article from Algorithms books Reviews | Blog blog("Baptiste Wicht");
I got rid of Vivaldi browser for Google Chrome | Blog blog("Baptiste Wicht");
About a year ago, I switched from Firefox to Vivaldi. This week, I decided to get rid of Vivaldi and replaced with Google Chrome. In this post, I'm going to outline the reasons why I got rid of it.
Before, I switched to Vivaldi because Firefox was dropping support for XUL/XPCOM extensions and I was using Pentadactyl. In fact, Pentadactyl was the only reason I was using Firefox. It was slow and bloated and a bit unstable, but the extension was making it worth. Since they are dropping support for such extensions, I did not want to use Firefox anymore. So I switched to Vivaldi with Vimium. It's not as great as Firefox plus Pentadactyl. But it's a more customizable version of Google Chrome on which it's based.
But, in that year or so of using Vivaldi, I have had many issues. Some of them were not too bad and there was some workarounds. But they continued to pile up and they did not fix any of them so now, I decided it's too much.
Since the beginning, it always has been slow. It's not really bad, but still noticeable compared to Chrome. Especially opening Vivaldi is pretty bad. This is something I can live with, but they should really do something to make it faster.
The thing that I had the most issues with is multimedia. For instance Youtube (but all the other platforms have the same issues).
The first problem with media is to get a video in fullscreen. Most of the time, when I press the fullscreen button on Youtube, it grays out the screen and I have to press ESC. If I do that around five to ten times, it finally goes fullscreen. It may be because of my multi-monitor setup but Google Chrome has no issues whatsoever with that. It's pretty painful to do, but again I could live for since I don't use full screen a lot.
Read full article from I got rid of Vivaldi browser for Google Chrome | Blog blog("Baptiste Wicht");
Read full article from CSC378 Online Notes
(99+) Can anyone give an interval tree based solution? - LeetCode Discuss
Why do you want to use an interval tree for that? It's overkill. You don't need to support overlapping intervals. So you can just use for example a sorted set like @wddd did.
Read full article from (99+) Can anyone give an interval tree based solution? - LeetCode Discuss
Read full article from 一亩三分地Instant
How to Formulaically Solve Tree Interview Questions · Daily Coding Problem
Tree questions are very common at top tech company interviews. I had two tree questions in my Google onsite interviews and one during my Facebook onsite interviews. An awesome thing about them is that they can be formulaically solved every single time. It doesn't involve any genius insight. Let me show you how.
Instead of being too abstract, let's just dive right into an easy binary tree question. Then I'll walk through how to solve it and we can go into a harder problem after:
Given the root to a binary tree, count the total number of nodes there are.
Before we move on further, feel free take a moment to think about the answer!
Solving any binary tree question involves just two steps.
First is solving the base case. This usually means solving the leaf node case (a leaf node has no left or right children) or the null case. For the above problem, we can see that a null should represent 0 nodes while a leaf node should represent 1 node.
Second is the recursive step. Assuming you knew the solution to the left subtree and the right subtree, how could you combine the two results to give you the final solution? It's important to not get caught up on how this works and just have faith that it works. If you start tracing the recursion, you're going to needlessly use up time and energy during the interview. Intuitively though, it works for similar reasons as why regular induction works. P(0) or the base case works which causes P(1) or the leaf node to work which causes P(2) to work and so on. For this problem, it's easy to combine the results of the left and right subtrees. Just add the two numbers and then another 1 for the root. Here's the code:
Read full article from How to Formulaically Solve Tree Interview Questions · Daily Coding Problem
A Neat Bitwise Trick For Swapping Even and Odd Bits · Daily Coding Problem
Here's a problem that was asked by Cisco.
Given an unsigned 8-bit integer, swap its even and odd bits. The 1st and 2nd bit should be swapped, the 3rd and 4th bit should be swapped, and so on.
For example, 10101010
should be 01010101
.
Bonus: Can you do this in one line?
Read full article from A Neat Bitwise Trick For Swapping Even and Odd Bits · Daily Coding Problem
How to Solve the Staircase Problem · Daily Coding Problem
Let's work through the following problem.
There exists a staircase with N steps, and you can climb up either 1 or 2 steps at a time.
Given N, write a function that returns the number of unique ways you can climb the staircase.
The order of the steps matters.
For example, if N is 4, then there are 5 unique ways:
What if, instead of being able to climb 1 or 2 steps at a time, you could climb any number from a set of positive integers X? For example, if X = {1, 3, 5}, you could climb 1, 3, or 5 steps at a time.
Read full article from How to Solve the Staircase Problem · Daily Coding Problem
The Complete Guide To Getting A Full-Time Software Engineering Job · Daily Coding Problem
This post is targeted for people looking to get offers from large tech companies like Google, Facebook, Microsoft, Dropbox, Uber, Lyft, and Airbnb. This isn't to say other companies aren't interesting! It's just that these companies' interview processes are all straightforward (though not necessarily easy) and many people are interested in working for them.
Let's start off with an obvious point: make sure you can get phone screens from these companies. If you have a large network of friends who can refer you, awesome! You can simply skip to step 4. If you went to a competitive college, or have several years of full-time software engineering experience, you should be qualified to get interviews.
If you weren't lucky enough to go to a college with good career services and don't have experience yet, you're not out of luck. One option is to build personal projects. This is the best way to learn new technologies and tack them on your resume. This will also help you build software engineering skills and show that you're taking initiatives for your learning. The best project ideas are ones you are interested in as well; you will spend several factors more time working on them. But if you're absolutely stuck, I would recommend doing web projects. For example, a real-time chat room, an online chess game, or Instagram clone demonstrate practical knowledge. Web development is a skill that's sought after by almost every tech company, so this is a great way to not put all your eggs in one basket.
Read full article from The Complete Guide To Getting A Full-Time Software Engineering Job · Daily Coding Problem
How to Pick a Random Element from an Infinite Stream · Daily Coding Problem
Let's work through the problem of uniformly picking a random element from a gigantic stream. This is a common interview question at companies like Google and Facebook.
Naively, we could process the stream and store all the elements we encounter in a list, find its size, and pick a random element from [0, size - 1]
. The problem with this approach is that it would take O(N) space for a large N.
Instead, let's attempt to solve using loop invariants. On the ith iteration of our loop to pick a random element, let's assume we already picked an element uniformly from [0, i - 1]
. In order to maintain the loop invariant, we would need to pick the ith element as the new random element at 1 / (i + 1)
chance. For the base case where i = 0
, let's say the random element is the first one. Then we know it works because
i = 0
, we would've picked uniformly from [0, 0].i > 0
, before the loop began, any element K
in [0, i - 1]
had 1 / i
chanceK
to have 1 / (i + 1)
chanceith
element is1 / i * (1 - (1 / (i + 1)))
which is 1 / i * i / (i + 1)
or 1 / (i + 1)
Read full article from How to Pick a Random Element from an Infinite Stream · Daily Coding Problem