奇点阅读



奇点阅读

莫的职业和生活可能让我们大部分人都会艳羡。从小到大的学霸,只要自己感兴趣的学科,通过读书就能一一化解;从微软到谷歌,事业好得一塌糊涂;生活更是如此,鼠标一点,两辆劳斯劳斯老爷车就开进了自家的车库。对了,有一点和我们好像是一样的哦!因为莫的妈妈从小就告诉他:努力学习,努力工作,拥有了财富,你就拥有了永远的快乐。莫是一个乖宝宝,当他按照妈妈的教诲都做到了之后,他问妈妈:快乐在哪儿呢?


Read full article from 奇点阅读


The Troubleshooters.Com xargs Guide



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



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 - 程序园



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



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



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


***D. Maximum Xor Secondary( find max and 2nd max in all possible sub array of an array in o(n)) | implementation



***D. Maximum Xor Secondary( find max and 2nd max in all possible sub array of an array in o(n)) | implementation

Bike loves looking for the second maximum element in the sequence. The second maximum element in the sequence of distinct numbers x1, x2, ..., xk (k > 1) is such maximum element xj, that the following inequality holds: .
The lucky number of the sequence of distinct positive integers x1, x2, ..., xk (k > 1) is the number that is equal to the bitwise excluding OR of the maximum element of the sequence and the second maximum element of the sequence.
You've got a sequence of distinct positive integers s1, s2, ..., sn (n > 1). Let's denote sequence sl, sl + 1, ..., sr as s[l..r] (1 ≤ l < r ≤ n). Your task is to find the maximum number among all lucky numbers of sequences s[l..r].
Note that as all numbers in sequence s are distinct, all the given definitions make sence.

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 Tutorial | Commonlounge



Tries Tutorial | Commonlounge

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 :)



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.

What does MVP really means?

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.

How to use MVP?

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 :)


java - Eclipse compilation error: The hierarchy of the type 'Class name' is inconsistent - Stack Overflow



java - Eclipse compilation error: The hierarchy of the type 'Class name' is inconsistent - Stack Overflow

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



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



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



在美国如何正确购买猪肉 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 - 博客园



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 - 博客园


幻魔皇——解题报告 - 风中的微尘的博客 - CSDN博客



幻魔皇——解题报告 - 风中的微尘的博客 - CSDN博客

题目大意:斐波那契树,根是一个白色节点,每个白色节点都有一个黑色节点儿子,而每个黑色节点则有一个白色和一个黑色节点儿子。神奇的节点对则是指白色节点对。对于深度为 n 的斐波那契树,其中距离为 i 的神奇节点对有多少个?需要你对于 1<=i<=2n 的所有 i 都求出答案。
题目分析
1.通过仔细观察我们可以发现,只要你话画的时候左右子树的画法不变,你画出的树,对于任意一个根为黑色节点的树,在等深度下,他们都是相同的。如图:

Read full article from 幻魔皇——解题报告 - 风中的微尘的博客 - CSDN博客


Release 1.0 of Marple, a Lucene index detective -



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 思否



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



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



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.

The default codec uses the BlockTree terms dictionary, which stores all terms for each field in sorted binary order, and assigns the terms into blocks sharing a common prefix. Each block contains between 25 and 48 terms by default. It uses an in-memory prefix-trie index structure (an FST) to quickly map each prefix to the corresponding on-disk block, and on lookup it first checks the index based on the requested term's prefix, and then seeks to the appropriate on-disk block and scans to find the term.

Read full article from Changing Bits: Choosing a fast unique identifier (UUID) for Lucene


剑指offer 11 数值的整数次方 | 碎碎念



剑指offer 11 数值的整数次方 | 碎碎念

时间复杂度是O(n)。当然这种思路并不高效,做了很多重复工作。比如a^32完全可以由a^16平方得到,a^16可以由a^8平方得到,以此类推直到a^1;而奇数情况下则只需要再乘一次a即可。而由这个思路则可以得到如下打码:


Read full article from 剑指offer 11 数值的整数次方 | 碎碎念


Minimum XOR Value Pair - GeeksforGeeks



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



Master the macOS Open and Save Dialogs | The Mac Security Blog

  • Command-up-arrow: This moves you up one level. So, in my example, in a folder on the Desktop, pressing these keys moves me to the Desktop itself.
  • Command-down-arrow: This moves you into a folder. If I were on the Desktop, and selected a folder, pressing these keys would open that folder. And if you've found the file you want to open, pressing Command-down-arrow opens the file; it's the same as double-clicking it.
  • Command-right-arrow and Command-left-arrow: When in List view, this opens or closes a folder without switching to a new level. Select a folder and press Command-right-arrow and the folder expands to show its contents; press Command-left-arrow to hide the folder's contents.
  • Right-arrow and left-arrow: In Column view, these keys alone, with no modifier keys, move you up and down the file system, from column to column. Visually, you're moving horizontally, but figuratively, you're moving up and down.
  • Back button and Forward button: At the top left of each dialog, you see back and forward buttons. These work like in a web browser, taking you back through folders you've viewed, or moving you forward if you've already moved back.
  • Command-F: This activates the Search field. You can search for files to open, or for folders to store your documents in. To exit the Search field, press the Esc key.


Read full article from Master the macOS Open and Save Dialogs | The Mac Security Blog


[HackerRank] Roads and Libraries



[HackerRank] Roads and Libraries

The Ruler of HackerLand believes that every citizen of the country should have access to a library. Unfortunately, HackerLand was hit by a tornado that destroyed all of its libraries and obstructed its roads! As you are the greatest programmer of HackerLand, the ruler wants your help to repair the roads and build some new libraries efficiently.

Read full article from [HackerRank] Roads and Libraries


[LeetCode] 78. Subsets



[LeetCode] 78. Subsets

Given a set of distinct integers, nums, return all possible subsets.
Note: The solution set must not contain duplicate subsets.
For example,
If nums = [1,2,3], a solution is:
[    [3],    [1],    [2],    [1,2,3],    [1,3],    [2,3],    [1,2],    []  ]

Thought process:
Iterate through the list. For each number, iterate through the list again starting from that element. As I iterate, add elements to the current list. Delete the last added element after the recurrence.

Read full article from [LeetCode] 78. Subsets


Capital Loss Carryover



Capital Loss Carryover

Tax-Loss Harvesting

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



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



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



10 Things You Must Know About Facebook Interview Process » My Tech Interviews

  • In the first round, you'll go through up to five different types Facebook interviews. These are meant to gauge your ability and talent.
  • It will also help the interviewer analyze if you are fit for the organizational culture.
  • After the first round of interview where the candidate will be asked about professional experience and passion for work.
  • Then, the second interview will examine your technical prowess. For example, if you've applied for a software engineer, you'll be interviewed by a senior software engineer who knows about each and every software bit of Facebook.
  • In the third interview, you'll be required to come to the office. Here, you'll get a tour to Oculus VR headset that'll relax you by taking you to the virtual tour and reduce the pressure of an interview.
  • Interestingly, the interviewer and the interviewee will both find a lot about themselves and the company.
  • The remaining interviews will pertain about the department and role you are deemed to fit. Again, you'll be interviewed about the technicalities of the field you've applied for; an engineer will be asked to write the code accurately in a given situation. You will be given hypothetical scenarios and asked to come up with the best possible solutions.
  • Once you did, you will answer questions about how you came to that conclusion. This will in turn test whether or not you are good enough for Facebook.
  • Unlike other organizations, you will come across some tough and even odd questions during the interviews. For example, you will be asked about ways to bring more people to Facebook and tap their relationships to existing Facebook members. Another question would be what kind of animal you would want to be and why? Tell the difference between Google Ads and Facebook? Should Facebook enter China? If you find these questions difficult, here is another one; what will be the biggest challenge you see for Facebook in coming five years?
  • Have you ever signed a non-disclosure agreement? If not, you should know that it's nothing to be scared off. Still, you should go through the terms and conditions before signing the NDA just to be on the safe side. Such agreements are often meant to protect the company more than anything, and you will not be under any pressure during your time on


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题解 | Calvin's Marbles

Google Kickstart 2017 Round F,当时做了两条就睡觉了,早上把剩下两条也过了。感觉不算是很难,可能也和这场限时24h有关吧。不过提交的时候倒是手忙脚乱,第一条交了三发,第一发是从VS迁移到DevC上是DevC由于之前配了个C++14所以崩了,第二发输出里面是Unicode BOM,WA了,蛋疼。

A. Kicksort

找规律发现每次找的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解题报告 | 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


Julia's coding blog - Practice makes perfect: Leetcode 689. Maximum Sum of 3 Non-Overlapping Subarrays (II)



Julia's coding blog - Practice makes perfect: Leetcode 689. Maximum Sum of 3 Non-Overlapping Subarrays (II)

I came cross the algorithm this evening while I attended word press meeting in Vancouver down town Microsoft office. I started to think about the algorithm. I like to write down how I analyze the algorithm systematically, look like an engineer.

The algorithm link is here in Chinese.

Brainstorm the ideas


Need to brainstorm the ideas. Write down a list of ideas to work on.

Overlap – constraint, how to handle it?
Need to find  3 * K distinct elements in the array, and also 3 subarrays in the array not overlap
3 subarrays, how about one subarray, two subarray, four subarrays
It seems like 2 sum, 3 sum, 4 sum, k sum problem.

How to find three sum of subarrays? Enumerate one of the subarray, and search other two with maximum sums.

Two subarrays
We can use O(N) time, we just enumerate all possible subarray for the first one with small start index, and then find maximum subarray on it right side.

One subarray
We can using O(1) time to solve it. Preprocess the array using O(N) time and also dynamic programming to get any index and its right side maximum subarray sum or left side maximum subarray sum.

How about thinking bottom up?
Work on 1 subarray, and then two subarrays, and then three subarrays? Instead of breaking down three subarrays to two subarrays to 1 subarray.

Top k sum of subarrays
Let us differentiate the problem with top three sum of subarrays or top k sum of subarrays problem. 
Try to avoid complicated math theory, we even cannot tell that top three sum of subarrays with non-overlapping can add to maximum sum of three subarrays. 

Preprocessing
Preprocess the array using dynamic programming, we can do the work using O(N) time. What is the common calculation we can do for the algorithm. 
What is the time complexity we can target to solve the problem?

What is most common problems on solving this problem? 

Read full article from Julia's coding blog - Practice makes perfect: Leetcode 689. Maximum Sum of 3 Non-Overlapping Subarrays (II)


如何进入 Google 工作



如何进入 Google 工作

如果你梦想进入Google,那么以下建议或许可以帮到你:

1.定个具体目标

你需要缩小你的目标范围,把目标落实到具体的工作岗位,也就是说,你需要通过对Google的深入了解,知道自己想从事具体哪个方面的工作。

比如,你需要在一开始就给自己定个小目标——"我想从事Google Android网络方面工作",而不是很笼统的"我想进入Google"。

2.确定所需技能

如果你想从事分布式基础架构的工作,你可能需要掌握C/C++和分布沟通式系统。

Read full article from 如何进入 Google 工作


[uva 591] Box of Bricks – hwchang0417



[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



[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


Googel Mock Interview记录



Googel Mock Interview记录

You are given a square grid of size dxd. It contains each 
of the numbers 1..n, where n = d^2. The numbers each occur
once and only once, in arbitrary order, find the length of
the longest sequence of adjacent consecutive numbers in
the grid.


For example,

1 2 9
5 3 8
4 6 7

This contains three sequences of adjacent numbers [1, 2, 3]
, [4, 5], and [6, 7, 8, 9]. The longest is [6, 7, 8, 9],
which has length 4, and therefore the answer is 4.


Read full article from Googel Mock Interview记录


Hello SHEN



Hello SHEN

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:

  1. The given kill id is guaranteed to be one of the given PIDs.
  2. n >= 1.

BFS挖出整棵子树


把进程结构看成一棵树,要杀死某个进程,必定也要杀死他的所有子进程。

          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



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



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



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



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


码友的圈子



码友的圈子

看过哪些源代码?然后会根据你说的源码问一些细节的问题?(这里主要考察面试者是否对技术有钻研的精神,还是只停留在表面,还是背了几道面经,这个对于很多有强迫症的面试官,如果你连源码都没看过,基本上是会pass掉的,比如我也是这样的!)

项目中遇到了哪些比较有挑战性的问题,是如何解决的;(这个很有争议,一方面是你连一个复杂的问题都解决不了,要你过来干什么,还有就是我的能力牛逼啊,但是公司没有业务场景让我展示啊!这个就看你遇到的面试官了,祝你好运!)


Read full article from 码友的圈子


Maximum consecutive integers present in an array – Ritambhara Technologies – Coding Interview Preparations



Maximum consecutive integers present in an array – Ritambhara Technologies – Coding Interview Preparations

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.


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



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


为什么说算法工程师的面试是一门玄学? - 知乎



为什么说算法工程师的面试是一门玄学? - 知乎

  1. 面试过于被动,被面试官生硬的推着走。比如针对"微信抢红包"这个问题,有的面试者就一句话,"每次用一个随机数生成器生成一个红包金额不就行了"。如果是这样的话,你作为工程师的严谨性就荡然无存了。面试官为了让你继续下去,还要向你提问,比如你考虑过没有红包金额的总体分布问题?等等。而面试官期待的是这个问题被你推动着走下去。比如在问题不太清楚的前提下你应该反问面试官,每个红包的金额有没有上限和下限?需不需要考虑计算效率问题?我能否在红包产生时就预算好所有红包的金额等等。
  2. 思路受限,没有严谨性、开放性和创新性。在实际的工程问题中,解决一个问题不可能只有一个solution,解决一个问题的solution也不可能是一句话能说清楚的。比如我想跟你讨论一下如何设计一个电商主页商品类别排序模型。看到这个问题,很多人会直接说我想用DNN建一个CTR prediction模型来排序。这当然可以,但最好请你抛出这个解决方案的时候严谨地系统地想一想这个问题,顺着工程实现的思路去跟面试官讨论下去,比如1、都能得到哪些数据和feature;2、数据量有多大,数据延迟有多大;3、objective如何制定;4、结合具体业务,我能不能把商品类别当作一个item来对待,或者把类别内部的商品当作一个item来对待;5、我能否使用learning to rank /ctr prediction/多分类模型来解决这个问题;6、采用什么模型架构更适合这个问题。等等。。。在实际面试中,你可能无法想的这么细,但请体会这个意思,作为算法工程师,你应该足够严谨、开放、活跃、创新。


Read full article from 为什么说算法工程师的面试是一门玄学? - 知乎


【新提醒】马克2016找工季总结,拿到g和f,从了facebook【一亩三分地论坛求职版】 -



【新提醒】马克2016找工季总结,拿到g和f,从了facebook【一亩三分地论坛求职版】 -

很多身边的朋友问我算法怎么准备,我只能回答一个字:"直接刷题"。楼主之前听过xx算法的高级算法课,感觉课还不如附送的ladder管用,(ladder是真好用)。然后又听了各种各样的算法课,(13年夏天啃掉了算法导论,听了mit的算法,算是打了比较扎实的基础),还是推荐算法挺princeton大爷在coursera公开课,这门课深入浅出,基本lz答的80%的follow up都是从这学到的。
至于刷题,楼主刚毕业找工作的时候刷了100多道,以medium为主,工作半年后每天晚上刷2道hard作为思维训练,然后这次找工作刷了300道,一些典型的可以用多种解法的题用所有方法刷一遍,大概不到500次不一样的提交吧。我的经验就是,如果平时没事做,就去刷hard,对找问题解决问题,写更整洁的代码都有很大帮助,如果是着急面试,就多刷medium,把基本功练熟,面试基本不会考到hard的原题,就算考到了也未必能考到你准备的那些,还是要把基本功练扎实,比如写个bfs dfs unionfind或者sweep line可以不过大脑。然后就是不一定要会写,但是尽量多了解些高级的数据结构,这样follow up不至于没的说,比如segment tree,binary indexed tree, tenary search tree, Boyer-Moore, Manacher等等,可以上princeton大爷的课,也可以去geeksforgeeks或者topcoder看文章
(再次推荐下princeton大爷的课,不光是视频,他的书有电子版, 里面的专门各种数据结构和算法的源码(http://algs4.cs.princeton.edu/code),比如谷歌一道原题是如何设计迷宫,就可以直接从这里看到代码
总的说,hard题和高级算法结构需要总结,是一种长期收益;medium和模板是熟能生巧,想拿起来随时可以拿起来,是一种短期收益。面经是针对性很强的东西,是一种很有用的功利性的收益,如何取舍看大家各自处于什么阶段-baidu 1point3acres

Read full article from 【新提醒】马克2016找工季总结,拿到g和f,从了facebook【一亩三分地论坛求职版】 -


Codeforces 873D. Merge Sort 分治 + 构造 - WA是一笔财富 - CSDN博客



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



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



(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.
My University hosted a Job Fair for Summer Internships, where despite my seniors telling me that Job Fairs are a waste of time, I decided to to go anyways. I visisted the Oath booth, was greeted by an inquiring face which I liked. Unlike other companies, they person took their time to go through my Resume, asked questions about my projects. I made sure to email that person later during the day to thank him for his diligence. I was later contacted by the same person to schedule telephonic interview rounds. Much to my delight, I scheduled those rounds in the following week. I know I should I have reserved atleast 1 week to practice, but this was my first time. Anyhow, I was asked the Peak Value in an Array problem. I gave a linear time solution, then gave a 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



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


Count of Smaller Numbers After Self [LeetCode] | Training dragons the hard way - Programming Every Day!



Count of Smaller Numbers After Self [LeetCode] | Training dragons the hard way - Programming Every Day!

You are given an integer array nums and you have to return a new counts array. The counts array has the property where counts[i] is the number of smaller elements to the right of nums[i].
Example:
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.  
Return the array [2, 1, 1, 0].
Solution
In this post, I'm going to write a little bit about Binary Indexed Tree and its application to solve the above problem. The problem itself is not really hard. We can solve it using many ways, including Binary Search Tree, Segment Tree, Sorting, or language specific way such as using lower_bound in C++, TreeSet (or SortedSet) in Java with method lower  (see some at the end) .
Once we know how to use Binary Indexed Tree or shortly BIT, we can solve many other problems, especially in programming contests since BIT is very easy to implement.

I suggest that you spend some time to read this article from Topcoder: Binary Indexed Tree.
Basically, in this problem, we use BIT to count the number of integers that are less than a specific number.
Suppose that a number N = A1B > 0 in binary representation, where B contains all 0 . The array tree is a BIT where tree[N] count the number of integers that are from A0B and A1B - 1 .
So if we call f[N] is the number of integers that are less than N, how we calculate its value?
Yes, you are correct, f[N] = tree[N] + f[A0B] (where A0B is in binary representation).
We also know that A0B = N & (N-1) using bit manipulation. (NOTE: on the Topcoder, they use A0B= N - (N & -N) .  
Having this in mind, to solve the problem we run from the back of the array, try each element. At the position i , we can simply calculate f[nums[i]] and put it into the result. However, we need to update the BIT here, because we have found another integer. So the natural question is which element we need to update in the BIT? Obviously, we need to update tree[N+1] by increasing its value by 1. But we do not stop there. Let N+1 = C1D where D has all 0 . As you can see, let  g[N+1] = C1D + 1D , we need to update g[N+1] also. And in turn, we need to update g[g[N+1]],so on...

Read full article from Count of Smaller Numbers After Self [LeetCode] | Training dragons the hard way - Programming Every Day!


校招经历 – xuan's blog



校招经历 – xuan's blog

因为春招的失败,于是从暑假就开始准备秋招,从各个方面开始全面的复习。

暑假参加了网易的内推,结果以失败告终,详情可看:网易内推 Java 开发工程师(一面 + 二面 + HR 面)

其他的内推均没有回复。

于是 9 月开始参加正式的校招。一共投了 24 家互联网公司,都是一些比较常见的公司。其中参加了 5 次面试,剩下的直接放弃,下面就大概写一下经历。时间顺序有点不太记得了。


Read full article from 校招经历 – xuan's blog


POJ题目分类推荐 (很好很有层次感) - Virtual Judge



POJ题目分类推荐 (很好很有层次感) - Virtual Judge

著名题单,最初来源不详。直接来源:http://blog.csdn.net/a1dark/article/details/11714009


Read full article from POJ题目分类推荐 (很好很有层次感) - Virtual Judge


ACM计算几何题目推荐(第二期) - open source - 博客园



ACM计算几何题目推荐(第二期) - open source - 博客园

这次的题目不再局限于POJ了,因为自己去年周游了各个OJ,反而很少在POJ切题了。而且这次推荐的题目比上次难了,也复杂多了。现在看回自己第一次写的计算几何题目推荐,实在感到当时自己写得有点肤浅。其实对于一些大牛来说,这些题目也算不了什么。

下面的OJ之中,CII是指ACM-ICPC Live Archive ,网址是:
http://cii-judge.baylor.edu/

其他OJ的地址大家都熟知了,因此不再提供。

希望各位转载的同志注明本文的出处。

一。基础题目
1.1 有固定算法的题目

A, 最近点对问题
最近点对问题的算法基于扫描线算法。
ZOJ    2107    Quoit Design    典型最近点对问题
POJ    3714    Raid    变种最近点对问题

B,最小包围圆
最小包围圆的算法是一种增量算法,期望是O(n)。
ZOJ    1450    Minimal Circle  
HDU    3007    Buried memory  

Read full article from ACM计算几何题目推荐(第二期) - open source - 博客园


Google2015校招笔试 Round B



Google2015校招笔试 Round B

问由N个不同字符组成的长度为M的密码串有多少个? 其中对每个密码串所有的N个不同字符都必须出现过.

  • 答案1 Brute Force

下面方程的每一组解作全排列之后的所有计数累加,就是答案。假设有一组解为X1,…,Xn,那么该组解的排列之后有 M!/(X1! * X2! * … * Xn!),所有解累加即答案。


Read full article from Google2015校招笔试 Round B


算法-扫描线 | jiayi797



算法-扫描线 | jiayi797

经典问题:数飞机问题

给一些飞机飞行的时间区间。求天上最多有多少个飞机同时在飞。

例如给

1
2
3
4
5
[1,3]
[2,4]
[5,6]
求天上同时有多少架飞机


Read full article from 算法-扫描线 | jiayi797


LintCode线段树/扫描线/查询题总结 - Logan's - CSDN博客



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博客


Community - Competitive Programming - Competitive Programming Tutorials - Geometry Concepts: Line Intersection and its Applications



Community - Competitive Programming - Competitive Programming Tutorials - Geometry Concepts: Line Intersection and its Applications

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



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计算几何与几何题汇 - Virtual Judge



TYUT计算几何与几何题汇 - Virtual Judge

TYUT计算几何与几何题汇

白书2《挑战程序设计竞赛2(算法和数据结构)》 第16章 计算几何学


Read full article from TYUT计算几何与几何题汇 - Virtual Judge


[leetcode] 题型整理之图论 - Gryffin - 博客园



[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:

  1. Only one letter can be changed at a time
  2. Each intermediate word must exist in the word list

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:

    • Return 0 if there is no such transformation sequence.
    • All words have the same length.

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.


OJ's undirected graph serialization:

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 #.

  1. First node is labeled as 0. Connect node 0 to both nodes 1 and 2.
  2. Second node is labeled as 1. Connect node 1 to node 2.
  3. Third node is labeled as 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



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 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:

  • Given a class of input objects, find efficient algorithms and data structures to answer a certain query about a set of input objects each time the input data is modified, i.e., objects are inserted or deleted.


Read full article from Dynamic problem (algorithms) - Wikipedia


Algorithms books Reviews | Blog blog("Baptiste Wicht");



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:

  1. Data Structures & Algorithm Analysis in C++, Third Edition, by Clifford A. Shaffer
  2. Algorithms in a Nutshell, by George T. Heineman, Gary Pollice and Stanley Selkow
  3. Algorithms, Fourth Edition, by Robert Sedgewick and Kevin Wayne
  4. Introduction to Algorithms, by Thomas H. Cormen, Charles E. Leiserson, Ronald L. Rivest and Clifford Stein. I have to say that I have only read most of it, not completely, because some chapters were not interesting for me at the current time, but I will certainly read them later.


Read full article from Algorithms books Reviews | Blog blog("Baptiste Wicht");


I got rid of Vivaldi browser for Google Chrome | 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");


CSC378 Online Notes



CSC378 Online Notes

  • CLR means the course text by Cormen, Leiserson, and Rivest,
  • L&D means ``Data Structures and their Algorithms'' by Lewis and Denenberg, and
  • Weiss means ``Data Structures and Algorithm Analysis in C'' by Weiss.

Read full article from CSC378 Online Notes


(99+) Can anyone give an interval tree based solution? - LeetCode Discuss



(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


一亩三分地Instant



一亩三分地Instant

这轮面试官还带了一个shadow小哥,让我很惊讶的是面试官一进来就跟我说他去看过我简历上写的用MEAN stack做的个人网站,觉得设计得挺棒的,一下我就high起来了,大概跟他聊了聊当初自学MEAN stack写这个网站的感想。然后面试官又出了道面经里出现过的题。。让你设计个matrix class,提供两个方法:update(x, y) & query(x1, y1, x2, y2),update方法是update matrix上一个cell的值,query方法是查询matrix上用(x1, y1)和(x2, y2)确定的矩形内所有值的总和。有三种scenario,第一种是update方法调用的次数远大于query方法的调用次数,第二种是query方法的调用次数远大于update方法的调用次数,第三种是两种方法调用次数一样多。我很快给他讲清楚三种scenario下两个方法的最优实现,然后他让我写了最后一种实现的代码。面完这题还有20分钟,面试官说这就是我的main question了,咱们可以再来研究道难题,你做不出来没关系,来一起想想,然后给的题是一道和4 sum类似的题,但是是求所有和小于一个给定target值的组合个数,有个条件是给的数组size相当大。他跟我说这个问题有复杂度小于n^3的解法,但是他忘了怎么解了。。最后当然是想破脑袋也没想出来。。还剩5分钟的时候就进入提问环节了。总的来说这轮给了我相当大的信心。

Read full article from 一亩三分地Instant


How to Formulaically Solve Tree Interview Questions · Daily Coding Problem



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



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



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:

  • 1, 1, 1, 1
  • 2, 1, 1
  • 1, 2, 1
  • 1, 1, 2
  • 2, 2

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



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.

  1. 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.

  2. 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



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

  • For i = 0, we would've picked uniformly from [0, 0].
  • For i > 0, before the loop began, any element K in [0, i - 1] had 1 / i chance
    of being chosen as the random element. We want K to have 1 / (i + 1) chance
    of being chosen after the iteration. This is the case since the chance of having
    being chosen already but not getting swapped with the ith element is
    1 / 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


Labels

Algorithm (219) Lucene (130) LeetCode (97) Database (36) Data Structure (33) text mining (28) Solr (27) java (27) Mathematical Algorithm (26) Difficult Algorithm (25) Logic Thinking (23) Puzzles (23) Bit Algorithms (22) Math (21) List (20) Dynamic Programming (19) Linux (19) Tree (18) Machine Learning (15) EPI (11) Queue (11) Smart Algorithm (11) Operating System (9) Java Basic (8) Recursive Algorithm (8) Stack (8) Eclipse (7) Scala (7) Tika (7) J2EE (6) Monitoring (6) Trie (6) Concurrency (5) Geometry Algorithm (5) Greedy Algorithm (5) Mahout (5) MySQL (5) xpost (5) C (4) Interview (4) Vi (4) regular expression (4) to-do (4) C++ (3) Chrome (3) Divide and Conquer (3) Graph Algorithm (3) Permutation (3) Powershell (3) Random (3) Segment Tree (3) UIMA (3) Union-Find (3) Video (3) Virtualization (3) Windows (3) XML (3) Advanced Data Structure (2) Android (2) Bash (2) Classic Algorithm (2) Debugging (2) Design Pattern (2) Google (2) Hadoop (2) Java Collections (2) Markov Chains (2) Probabilities (2) Shell (2) Site (2) Web Development (2) Workplace (2) angularjs (2) .Net (1) Amazon Interview (1) Android Studio (1) Array (1) Boilerpipe (1) Book Notes (1) ChromeOS (1) Chromebook (1) Codility (1) Desgin (1) Design (1) Divide and Conqure (1) GAE (1) Google Interview (1) Great Stuff (1) Hash (1) High Tech Companies (1) Improving (1) LifeTips (1) Maven (1) Network (1) Performance (1) Programming (1) Resources (1) Sampling (1) Sed (1) Smart Thinking (1) Sort (1) Spark (1) Stanford NLP (1) System Design (1) Trove (1) VIP (1) tools (1)

Popular Posts