[LeetCode] Range Addition 范围相加 - 博客吧



[LeetCode] Range Addition 范围相加 - 博客吧

Assume you have an array of length n initialized with all 0's and are given k update operations.

Each operation is represented as a triplet: [startIndex, endIndex, inc] which increments each element of subarray A[startIndex ... endIndex] (startIndex and endIndex inclusive) with inc.

Return the modified array after all k operations were executed.

Example:

Given:      length = 5,     updates = [         [1,  3,  2],         [2,  4,  3],         [0,  2, -2]     ]  Output:      [-2, 0, 3, 5, 3] 

Explanation:

Initial state: [ 0, 0, 0, 0, 0 ]  After applying operation [1, 3, 2]: [ 0, 2, 2, 2, 0 ]  After applying operation [2, 4, 3]: [ 0, 2, 5, 5, 3 ]  After applying operation [0, 2, -2]: [-2, 0, 3, 5, 3 ] 

Hint:

  1. Thinking of using advanced data structures? You are thinking it too complicated.
  2. For each update operation, do you really need to update all elements between i and j?
  3. Update only the first and end element is sufficient.
  4. The optimal time complexity is O(k + n) and uses O(1) extra space.

Credits:
Special thanks to @vinod23 for adding this problem and creating all test cases.

 

这道题刚添加的时候我就看到了,当时只有1个提交,0个接受,于是我赶紧做,提交成功后发现我是第一个提交成功的,哈哈,头一次做沙发啊,有点小激动~这道题的提示说了我们肯定不能把范围内的所有数字都更新,而是只更新开头结尾两个数字就行了,那么我们的做法就是在开头坐标startIndex位置加上inc,而在结束位置加1的地方加上-inc,那么根据题目中的例子,我们可以得到一个数组,nums = {-2, 2, 3, 2, -2, -3},然后我们发现对其做累加和就是我们要求的结果result = {-2, 0, 3, 5, 3},参见代码如下:


Read full article from [LeetCode] Range Addition 范围相加 - 博客吧


移动大数据时代最IN编程语言必读书单 - 博客吧



移动大数据时代最IN编程语言必读书单 - 博客吧

  这是一个快速更迭,快鱼吃慢鱼的时代。从IT 时代演变成 DT 时代,再到现在的智能时代。急速革新的各种新技术、新工具、新平台,需要程序员掌握良好的编程思想和学习方法,不断学习新技术、补充新知识,才能努力跟上时代的步伐,找到自我实现的际遇。读书依然是我们获取知识的最方便和有效的途径之一。既要读经典,也要读新书,前者让你沉淀,发现正确的方法,后者让你紧跟前沿,掌握最新的技术。可你是不是担心,不能找到真正值得读的新书而浪费时间?在此,我们汇总了当下最In的编程语言以及最优秀的学习指南,希望你在可见的未来成为更好的自己。


Read full article from 移动大数据时代最IN编程语言必读书单 - 博客吧


Spark2.0,重要更新与改进 - 简书



Spark2.0,重要更新与改进 - 简书

作为数据科学人员,如果一生只能学一个框架,那就先Spark! In addition, this release includes over 2500 patches from over 300 contributors. 此版本超过2500个补丁,超过300位贡献者! 02 环境支持 The default build is now using Scala 2.11 rather than Scala 2.10 编译Spark版本的环境从Scala 2.10变成了2.11。标志着以后写Scala程序,也最好使用2.11来编译了。 不建议使用的版本,java7和Python2.6。 另外,Spark对Python3的支持已经不错了,如果使用PySpark,建议直接使用Python3,要少些麻烦。 Spark 2.0 no longer requires a fat assembly jar for production deployment. 部署到生产环境中,不再需要那个臃肿的assembly文件了(貌似是对Scala开发的福利)。 03 Spark-Core Unifying DataFrame and Dataset: In Scala and Java, DataFrame and Dataset have been unified, i.e. DataFrame is just a type alias for Dataset of Row. In Python and R, given the lack of type safety, DataFrame is the main programming interface. 在Scala语言与Java语言中,统一了DataFrame与Dataset数据结构。Python和R中,因为语言本身缺少类型安全机制,因此DataFrame还是主要的编程接口。 SparkSession: new entry point that replaces the old SQLContext and HiveContext for DataFrame and Dataset APIs. SQLContext and HiveContext are kept for backward compatibility.

Read full article from Spark2.0,重要更新与改进 - 简书


努橙刷题编: [笔记整理] 九章算法第二章 Binary Search & Sorted Array Part2



努橙刷题编: [笔记整理] 九章算法第二章 Binary Search & Sorted Array Part2

1. Search for a Range
<=> How many times did a number appear?  range[x1, x2] => x2-x1+1

* The insertion position may not be in current array
* Find the insertion position, 3 positions to check: x<start, start<x<end, x>end


* No duplicate
* 2 possible position for mid: [mid] >= [0], [mid] < [0]
* 4 possible position for target: [0]<T<[mid], [0]<[mid]<T, T<[mid]<[0], [mid]<T<[0]

* Duplicate

* Worst case for binary search - O(n) e.g. If in every iteration, [mid]==[0]/[mid]==[length-1] =>O(n)

* Any element in row1 < Any element in row 2
* Use binary search for 2 times, 1st time find the row of target, 2nd time find the column of target

[1 0 2 4]
[1 2 6 9]
[3 5 7 10]
[7 8 9 11]
* Quadrate search O(n)
* Search from left bottom to right top, exclude 1 row/column each iteration, O(m + n)



* peak <=> A[p] > A[p - 1] && A[p] >A[p + 1]

9. Remove Duplicate from Sorted Array

10. Remove Duplicate from Sorted Array II

11. Merge Sorted Array

* Merge + Find O(m + n)
* Find kth largest O(logn)
when (m+n) is odd=>k=(m+n)/2+1
when (m+n) is even=>k1=(m+n)/2, k2=(m+n)/2+1
* How to find kth largest?

Throw away each k/2 elements in each iteration

* Sort, O(1) space O(nlogn) time
* 3 times reverse, O(1) space O(n) time

* abcdefg, offset=3 => efgabcd

* reverse each word, then reverse the entire string

Read full article from 努橙刷题编: [笔记整理] 九章算法第二章 Binary Search & Sorted Array Part2


WAP to print all words possible with a combination of digits in T9 keypad! | My CPP Experiments!



WAP to print all words possible with a combination of digits in T9 keypad! | My CPP Experiments!

Problem:

Program to print all the possible words for a combination of digits in T9 keypad. E.g., if the digit combination is 23 - 2 refers to character set (a,b,c) and 3 refers to character set (d,e,f). So the result should be  { ad, ae, af, bd, be, bf, cd, ce, cf }. There would be a maximum of 4^n words possible for a number with n digits.

Solution:

We are not using a trie here but a simplified way of storing the sequence in a character string. Will write details later.

Code:

// T9Dictionary.cpp : Program to print all the words possible with a combination of
// numbers in T9 dictionary!
#include <iostream>
using namespace std;


Read full article from WAP to print all words possible with a combination of digits in T9 keypad! | My CPP Experiments!


Programming: Check if graph is semiconnected



Programming: Check if graph is semiconnected

A directed graph G=(V,E) is semiconnected if, for all pairs of vertices (u,v)
we have u to v or v to u. Give an efficient algorithm to determine whether
or not G is semiconnected. Prove that your algorithm is correct, and analyze its
running time.


Call STRONGLY-CONNECTED-COMPONENTS.

Form the component graph.

Topologically sort the component graph. It is possible to topologically sort the component graph, because component graph is always a DAG (Directed Acyclic Graph)


 Verify that the sequence of vertices (v1,v2,...vk) given by topological sort forms a linear chain in the component graph. That is, verify that the edges (v1,v2),(v2,v3) ,(v (k-1),vk)  exist in the component graph. If the vertices form a linear chain, then the original graph is semiconnected; otherwise it is not.

Because we know that all vertices in each SCC are mutually reachable from each other, it suffices to show that the component graph is semiconnected if and only if it contains a linear chain.
Total running time is O(V+E).

Read full article from Programming: Check if graph is semiconnected


Removing all NonLeader nodes from a singly Linked List. | gyanendraweblog



Removing all NonLeader nodes from a singly Linked List. | gyanendraweblog

Non leader Node means any node to its right is larger than this node.

suppose initial list was: 1->7->3->5->4

Here 1 and 3 are non leader node since node right to it is larger than this.

So resultant list would be: 7->5->4

Steps to be followed

Since we have to traverse the list in reverse direction that is from last

so through recursion we can achieve the same.

1.) if this is the last node set max as data of this node and return this node

2.) Call the recursive function for next node.

3.) If value of this node it smaller than max, delete this node.

4.) Else if value of this is larger than max, update max as data of this node.


Read full article from Removing all NonLeader nodes from a singly Linked List. | gyanendraweblog


Design a stack with operations on middle element - 程序园



Design a stack with operations on middle element - 程序园

How to implement a stack which will support following operations in O(1) time complexity?
1) push() which adds an element to the top of stack.
2) pop() which removes an element from top of stack.
3) findMiddle() which will return middle element of the stack.
4) deleteMiddle() which will delete the middle element.
Push and pop are standard stack operations.

The important question is, whether to use a linked list or array for implementation of stack?

Please note that, we need to find and delete middle element. Deleting an element from middle is not O(1) for array. Also, we may need to move the middle pointer up when we push an element and move down when we pop(). In singly linked list, moving middle pointer in both directions is not possible.

The idea is to use Doubly Linked List (DLL). We can delete middle element in O(1) time by maintaining mid pointer. We can move mid pointer in both directions using previous and next pointers.

Following is C implementation of push(), pop() and findMiddle() operations. Implementation of deleteMiddle() is left as an exercise. If there are even elements in stack, findMiddle() returns the first middle element. For example, if stack contains {1, 2, 3, 4}, then findMiddle() would return 2.


Read full article from Design a stack with operations on middle element - 程序园


Donald Trump Criticizes Muslim Family of Slain U.S. Soldier, Drawing Ire - The New York Times



Donald Trump Criticizes Muslim Family of Slain U.S. Soldier, Drawing Ire - The New York Times

Donald J. Trump belittled the parents of a slain Muslim soldier who had strongly denounced Mr. Trump during the Democratic National Convention, saying that the soldier's father had delivered the entire speech because his mother was not "allowed" to speak.

Mr. Trump's comments, in an interview with George Stephanopoulos of ABC News that will air on Sunday, were his most extensive remarks since Khizr Khan delivered on Thursday one of the most powerful speeches of the convention in Philadelphia. In it, Mr. Khan spoke about how his 27-year-old son, Humayun Khan, an Army captain, sacrificed his life in a car bombing in 2004 in Iraq as he tried to save other troops.

He criticized Mr. Trump, saying he "consistently smears the character of Muslims," and pointedly challenged what sacrifices Mr. Trump himself had made. Mr. Khan's wife, Ghazala, stood silently by his side.

Mr. Trump, the Republican presidential nominee, told Mr. Stephanopoulos that Mr. Khan seemed like a "nice guy" and that he wished him "the best of luck." But, he added, "If you look at his wife, she was standing there, she had nothing to say, she probably — maybe she wasn't allowed to have anything to say, you tell me."


Read full article from Donald Trump Criticizes Muslim Family of Slain U.S. Soldier, Drawing Ire - The New York Times


Amazon Assessment Tests and Interview Preparation - JobTestPrep



Amazon Assessment Tests and Interview Preparation - JobTestPrep

Amazon Recruitment Process

Being a leading force in the world of online retailers, Amazon is one of the best places to start your career. Unfortunately, getting into Amazon is not an easy task. The company is well-known for its high standards and extremely difficult and thorough selection process.

The typical Amazon recruitment process consists of three key stages: the online application, the telephone interview, and the onsite assessment day. Many applicants also need to take one or more online assessment tests.

Since there is a wide range of jobs available at Amazon, each requiring a different set of skills, the recruitment process may differ from one applicant to another in the types of assessments and their order. Below we will go through the most common assessments in the Amazon selection process. The order of the stages follows that of the Amazon non-tech grad schemes.

Read full article from Amazon Assessment Tests and Interview Preparation - JobTestPrep


The AWS Tech Challenge! | Marco Moyano | Pulse | LinkedIn



The AWS Tech Challenge! | Marco Moyano | Pulse | LinkedIn

Do you have what it takes to work at AWS?

Take and pass one of our Tech Challenges (Powered by Hacker Rank) for a direct invitation to interview onsite with our engineering team!

The Process

If you are interested in pursuing this position, the steps are simple.

Step 1: Take one of the tech challenges below.

http://hr.gs/windowshackerrankchallenge

Windows

http://hr.gs/linuxhackerrankchallenge

Linux

http://hr.gs/deploymenthackerrankchallenge

Deployment

http://hr.gs/bigdatahackerrankchallenge

Big-Data

http://hr.gs/databasehackerrankchallenge

Database

http://hr.gs/networkinghackerrankchallenge

Networking

Step 2: Somebody from our recruiting team will follow up with you within 5 business days with an update.

Step 3: If you pass, you will be invited to the next steps of the interview process.

The Test: Do you have what it takes to work at Amazon?

  1. This is an Amazon Web Services Cloud Support Engineer Test (Powered by Hacker Rank)
  2. You will have 60 minutes to complete as many of the questions as possible
  3. Questions will consist of both open text and multiple choice (no coding or scripting)
  4. We don't expect you to get every question correct, so if you don't know an answer please feel free to continue to the next question
  5. Once you have completed and submitted your Hacker Rank Assessment our Recruiting team will follow up within the next 48 business hours with an update about next steps in the interview process
  6. Candidates with a passing score will be invited directly onsite to do an in-person interview at one of our Amazon locations
  7. To understand more about the environment, time limits, etc. you can read the FAQ here

Questions?  Want to know more about the position?  Please feel free to reach out anytime. Thanks again and we look forward to meeting you soon!


Read full article from The AWS Tech Challenge! | Marco Moyano | Pulse | LinkedIn


What does it mean when "N/A" appears for a company's P/E ratio? | Investopedia



What does it mean when "N/A" appears for a company's P/E ratio? | Investopedia

A: A "N/A" reported in a stock's price-to-earnings ratio (P/E), can mean one of two things. The first, and simplest, would be that there is no data at time of reporting to calculate this ratio. This will be the case with a newly listed company that has yet to release its earnings. The second reason that a stock would report "N/A" as its P/E ratio could be that the number is negative. Negative P/E ratios are mathematically possible, but because they are generally not accepted by the financial community, they are usually reported as "N/A," or not applicable. The P/E ratio is calculated as the stock's current price divided by its earnings per share (EPS). Obviously, it is not possible for a stock to have a negative price, so the negative P/E ratio comes from the EPS of the company being negative (i.e. net loss). Investors can interpret seeing the "N/A" as the company reporting a net loss , and should be aware they are buying shares of a company that is losing money per share of its stock.

Read full article from What does it mean when "N/A" appears for a company's P/E ratio? | Investopedia


LeetCode blog: Coins in a Line_peking2_新浪博客



LeetCode blog: Coins in a Line_peking2_新浪博客

问题:There are n coins in a line. Two players take turns to take a coin from one of the ends of the line until there are no more coins left. The player with the larger amount of money wins. Assume that you go first, describe an algorithm to compute the maximum amount of money you can win.

这是LeetCode博客里的一道题,不在OJ里,因此一直没有做过。今天有人提到面试碰到了,我就想做做看。没有看LeetCode的分析,想先自己做。题目的要求是自己先拿硬币,那自己可以拿第一个或者最后一个,但是如何决定要拿哪一个就需要依靠子问题的结果了,这就是典型的DP思路了。首先想到了这个公式
dp[i][j]=max(A[i]+sum[i+1][j]-dp[i+1][j], A[j]+sum[i][j-1]-dp[i][j-1])

dp[i][j]代表从第i个硬币到第j个硬币这个子问题的结果,也就是可以拿到的最大钱数。那么你有两种选择
1. 如果你取第一个的话,剩下的子问题就变成了(i+1, j)了,由于轮到对方取了,因此对方可以得到dp[i+1][j]的钱数,而你则得到sum[i+1,j]-dp[i+1][j]的钱数,也就是剩余的钱数。
2. 如果你取最后一个的话,同理。
再分析方程A[i]+sum[i+1][j]=sum[i][j], A[j]+sum[i][j-1]=sum[i][j]
因此方程可以简化为
dp[i][j]=max(sum[i][j]-dp[i+1][j], sum[i][j]-dp[i][j-1])=sum[i][j]-min(dp[i+1][j],dp[i][j-1])

Read full article from LeetCode blog: Coins in a Line_peking2_新浪博客


Coins in a Line II | lintcode题解



Coins in a Line II | lintcode题解

Question

There are n coins with different value in a line. Two players take turns to take one or two coins from left side until there are no more coins left. The player who take the coins with the most value wins.

+

Could you please decide the first player will win or lose?

+

Example Given values array A = [1,2,2], return true.

+

Given A = [1,2,4], return false.

+

Thoughts

state

DP[i]表示从i到end能取到的最大value

+

function

当我们走到i时,有两种选择

+

  1. values[i]
  2. values[i] + values[i+1]

1. 我们取了values[i],对手的选择有 values[i+1]或者values[i+1] + values[i+2] 剩下的最大总value分别为DP[i+2]DP[i+3], 对手也是理性的所以要让我们得到最小value

+

所以 value1 = values[i] + min(DP[i+2], DP[i+3])

+

2. 我们取了values[i]values[i+1] 同理 value2 = values[i] + values[i+1] + min(DP[i+3], DP[i+4])

+

最后

DP[I] = max(value1, value2)  


Read full article from Coins in a Line II | lintcode题解


Leetcode: Day 114, Lintcode, #395, Coins in a Line II



Leetcode: Day 114, Lintcode, #395, Coins in a Line II

Day 114, Lintcode, #395, Coins in a Line II

Coins in a Line II
There are n coins with different value in a line. Two players take turns to take one or two coins from left side until there are no more coins left. The player who take the coins with the most value wins.
Could you please decide the first player will win or lose?
-----------------------------------------------------
方法一
coins表示在i点的最大利益
getTwo表示在i点最大利益是否要取2个coin

Read full article from Leetcode: Day 114, Lintcode, #395, Coins in a Line II


lintcode 中等题:Coins in Line II 硬币排成线 II



lintcode 中等题:Coins in Line II 硬币排成线 II

有 n 个不同价值的硬币排成一条线。两个参赛者轮流从左边依次拿走 1 或 2 个硬币,直到没有硬币为止。计算两个人分别拿到的硬币总价值,价值高的人获胜。

请判定 第一个玩家 是输还是赢?

样例

给定数组 A = [1,2,2], 返回 true.

给定数组 A = [1,2,4], 返回 false.

解题

动态规划、博弈论

坑死,看了好久

定义dp[i]表示从i到end能取到的最大值

当我们在i处,有两种选择:

1.若取values[i],对方可以取values[i+1] 或者values[i+1] + values[i+2]

当对方取values[i+1] 后 ,我们只能从 i+2 到end内取,我们所取得最大值是dp[i+2],  注意:对方所选取的结果一定是使得我们以后选取的值最小

当对方取values[i+1] + values[i+2]后,我们只能从i+3到end内取,我们所取得最大值是dp[i+3]。

此时:dp[i] = values[i] + min(dp[i+2],dp[i+3]) , 注意:对方所选取的结果一定是使得我们以后选取的值最小

2.若取values[i] + values[i+1],对方可取values[i+2] 或者values[i+2] + values[i+3]

当对方取values[i+2]后,我们只能从i+3到end内取,我们取得最大值是dp[i+3]

当对方取values[i+2]+values[i+3]后,我们只能从i+4到end内去,我们取得最大值是dp[i+4]

此时:dp[i] = values[i] + values[i+1]+min(dp[i+3],dp[i+4])

这里的取最小值和上面一样的意思,对方选取过之后的值一定是使得我们选取的值最小,对方不傻并且还很聪明

最后我们可以取上面两个dp[i]的最大值,就是答案,这里意思是:对方留得差的方案中,我们选取的最大值。


Read full article from lintcode 中等题:Coins in Line II 硬币排成线 II


LeetCode Climbing Stairs 递归求解和动态规划法 - 靖空间 - 博客频道 - CSDN.NET



LeetCode Climbing Stairs 递归求解和动态规划法 - 靖空间 - 博客频道 - CSDN.NET

Climbing Stairs

 

You are climbing a stair case. It takes n steps to reach to the top.

Each time you can either climb 1 or 2 steps. In how many distinct ways can you climb to the top?

简单题目,相当于fibonacci数列问题,难点就是要会思维转换,转换成为递归求解问题,多训练就可以了。

所以这种类型的题目相对于没有形成递归逻辑思维的人来说,应该算是难题。

我的想法是:

每次有两种选择,两种选择之后又是各有两种选择,如此循环,正好是递归求解的问题。

写成递归程序其实非常简单,三个语句就可以:


Read full article from LeetCode Climbing Stairs 递归求解和动态规划法 - 靖空间 - 博客频道 - CSDN.NET


【新提醒】Uber 电面 china growth (新题附代码)【一亩三分地论坛面经版】 - Powered by Discuz!



【新提醒】Uber 电面 china growth (新题附代码)【一亩三分地论坛面经版】 - Powered by Discuz!

上周五面了Uber China Growth, 面试官是个国人小哥,题目还挺难的(T T),如下:

有两个人A和B,给一个数组array,A和B轮流在这个array中取出数字,每次一个,并且只能取array第一个数字或者最后一个数字,取出数字后,array也随之更新,A先取,两人轮流,直到取完为止。A和B都相当相当相当的机智,他们都按照某个让自己最终能取出所有数字和最大的算法来取数字(这个算法是你要实现的),最后让你返回A最终得到的数字和。
. from: 1point3acres.com/bbs
当时电话面试,我也是理解了好久题目,给两个例子:. from: 1point3acres.com/bbs
例子1: array = {1,2,3}
            只能选头尾,A会先选3,B会选2,A接着选1,最后返回4。

例子2: array = {5, 9, 3, 1 }
            A先选:如果选5的话,虽然比尾部的1大,但是就把下一个较大的数字9让给了B,所以A先选1,. 鐗涗汉浜戦泦,涓€浜╀笁鍒嗗湴
            B选:现在array变成了{5,9,3},B会选5,
            A选:现在array变成了{9,3},于是A开心的选了9,
            B选:现在array变成了{3},于是B只能选3.. 鐗涗汉浜戦泦,涓€浜╀笁鍒嗗湴
            所以返回和为 1+9=10。. From 1point 3acres bbs

当时拿到这个题懵的很 =。=,anyway,上代码

Read full article from 【新提醒】Uber 电面 china growth (新题附代码)【一亩三分地论坛面经版】 - Powered by Discuz!


4 Zika Cases in Florida Were Likely Spread by Local Mosquitoes, C.D.C. Says - The New York Times



4 Zika Cases in Florida Were Likely Spread by Local Mosquitoes, C.D.C. Says - The New York Times

Four cases of Zika infection in Florida are very likely to have been caused by mosquitoes there, the State Department of Health said Friday — the first documented instances of local transmission in the continental United States.

"Zika is now here," Dr. Thomas R. Frieden, the director of the Centers for Disease Control and Prevention, said at a news briefing.

The C.D.C. and Florida officials said that for now, the area of concern is limited to one square mile in the Wynwood neighborhood of Miami, a gentrifying area with restaurants and art galleries just north of downtown.

Health authorities are not advising people to stay away from the neighborhood, Dr. Frieden said. The four people appear to have been infected in early July; since then, mosquito control efforts have been stepped up in the area, and additional cases have not been identified.


Read full article from 4 Zika Cases in Florida Were Likely Spread by Local Mosquitoes, C.D.C. Says - The New York Times


Share my o(log(min(m,n)) solution with explanation | LeetCode Discuss



Share my o(log(min(m,n)) solution with explanation | LeetCode Discuss

To solve this problem, we need to understand "What is the use of median". In statistics, the median is used for dividing a set into two equal length subsets, that one subset is always greater than the other. If we understand the use of median for dividing, we are very close to the answer.

First let's cut A into two parts at a random position i:

      left_A             |        right_A  A[0], A[1], ..., A[i-1]  |  A[i], A[i+1], ..., A[m-1]  

Since A has m elements, so there are m+1 kinds of cutting( i = 0 ~ m ). And we know: len(left_A) = i, len(right_A) = m - i . Note: when i = 0 , left_A is empty, and when i = m , right_A is empty.

With the same way, cut B into two parts at a random position j:

      left_B             |        right_B  B[0], B[1], ..., B[j-1]  |  B[j], B[j+1], ..., B[n-1]  

Put left_A and left_B into one set, and put right_A and right_B into another set. Let's name them left_part and right_part :

      left_part          |        right_part  A[0], A[1], ..., A[i-1]  |  A[i], A[i+1], ..., A[m-1]  B[0], B[1], ..., B[j-1]  |  B[j], B[j+1], ..., B[n-1]  

If we can ensure:

1) len(left_part) == len(right_part)  2) max(left_part) <= min(right_part)  

then we divide all elements in {A, B} into two parts with equal length, and one part is always greater than the other. Then median = (max(left_part) + min(right_part))/2.

To ensure these two conditions, we just need to ensure:

(1) i + j == m - i + n - j (or: m - i + n - j + 1)      if n >= m, we just need to set: i = 0 ~ m, j = (m + n + 1)/2 - i  (2) B[j-1] <= A[i] and A[i-1] <= B[j]  

(For simplicity, I presume A[i-1],B[j-1],A[i],B[j] are always valid even if i=0/i=m/j=0/j=n . I will talk about how to deal with these edge values at last.)

So, all we need to do is:

Searching i in [0, m], to find an object `i` that:      B[j-1] <= A[i] and A[i-1] <= B[j], ( where j = (m + n + 1)/2 - i )  

And we can do a binary search following steps described below:

<1> Set imin = 0, imax = m, then start searching in [imin, imax]    <2> Set i = (imin + imax)/2, j = (m + n + 1)/2 - i    <3> Now we have len(left_part)==len(right_part). And there are only 3 situations       that we may encounter:      <a> B[j-1] <= A[i] and A[i-1] <= B[j]          Means we have found the object `i`, so stop searching.      <b> B[j-1] > A[i]          Means A[i] is too small. We must `ajust` i to get `B[j-1] <= A[i]`.          Can we `increase` i?              Yes. Because when i is increased, j will be decreased.              So B[j-1] is decreased and A[i] is increased, and `B[j-1] <= A[i]` may              be satisfied.          Can we `decrease` i?              `No!` Because when i is decreased, j will be increased.              So B[j-1] is increased and A[i] is decreased, and B[j-1] <= A[i] will              be never satisfied.          So we must `increase` i. That is, we must ajust the searching range to          [i+1, imax]. So, set imin = i+1, and goto <2>.      <c> A[i-1] > B[j]          Means A[i-1] is too big. And we must `decrease` i to get `A[i-1]<=B[j]`.          That is, we must ajust the searching range to [imin, i-1].          So, set imax = i-1, and goto <2>.  

When the object i is found, the median is:

max(A[i-1], B[j-1]) (when m + n is odd)  or (max(A[i-1], B[j-1]) + min(A[i], B[j]))/2 (when m + n is even)  

Now let's consider the edges values i=0,i=m,j=0,j=n where A[i-1],B[j-1],A[i],B[j] may not exist. Actually this situation is easier than you think.

What we need to do is ensuring that max(left_part) <= min(right_part). So, if i and j are not edges values(means A[i-1],B[j-1],A[i],B[j] all exist), then we must check both B[j-1] <= A[i] and A[i-1] <= B[j]. But if some of A[i-1],B[j-1],A[i],B[j] don't exist, then we don't need to check one(or both) of these two conditions. For example, if i=0, then A[i-1] doesn't exist, then we don't need to check A[i-1] <= B[j]. So, what we need to do is:

Searching i in [0, m], to find an object `i` that:      (j == 0 or i == m or B[j-1] <= A[i]) and      (i == 0 or j == n or A[i-1] <= B[j])      where j = (m + n + 1)/2 - i  

And in a searching loop, we will encounter only three situations:

<a> (j == 0 or i == m or B[j-1] <= A[i]) and      (i == 0 or j = n or A[i-1] <= B[j])      Means i is perfect, we can stop searching.    <b> j > 0 and i < m and B[j - 1] > A[i]      Means i is too small, we must increase it.    <c> i > 0 and j < n and A[i - 1] > B[j]      Means i is too big, we must decrease it.  


Read full article from Share my o(log(min(m,n)) solution with explanation | LeetCode Discuss


如何看待中国学生为了进 Google、微软等企业疯狂地刷题? - 程序员 - 知乎



如何看待中国学生为了进 Google、微软等企业疯狂地刷题? - 程序员 - 知乎

自从我国开始反思批判应试教育了之后,我见到了很多类似这样的 Argument:"我们培养了大量的考试机器,扼杀了中国的爱因斯坦/贝多芬/毕加索/爱迪生/..." 这个题目也一样,只不过爱因斯坦换成了 Linus,贝多芬换成了乔布斯。这类论断最大的问题就是没有搞清芸芸众生和世之奇才的区别。你说学生为了高考、考研、找工作而刷题,而不是去读《从0到1》,去试图实现一个优秀操作系统内核,去研读更艰深的理论研究;可是我看到的是,真正的未来的 Linus 四年级就开始编程,大学精研各类黑魔法,随便写几行代码就比我快十倍整洁一百倍;真正的未来的乔布斯高中毕业就创业了,几年就搞出了很有意思的东西,现在已经小有成就;未来的爱因斯坦中学就看完了费曼,大学期间在研究组专心钻研理论物理;更有如贝勒爷这样的未来中国政坛之希望,从小黑格尔尼采就没断过。这些人真的不刷题,但你也真的很难见到,所以你以为他们不存在。

Read full article from 如何看待中国学生为了进 Google、微软等企业疯狂地刷题? - 程序员 - 知乎


LeetCode 刷题指南(一):为什么要刷题 - Just For Fun - SegmentFault



LeetCode 刷题指南(一):为什么要刷题 - Just For Fun - SegmentFault

LeetCode 是一个非常棒的 OJ(Online Judge)平台,收集了许多公司的面试题目。相对其他 OJ 平台而言,有着下面的几个优点:

  • 题目全部来自业内大公司的真实面试

  • 不用处理输入输出,精力全放在解决具体问题上

  • 题目有丰富的讨论,可以参考别人的思路

  • 精确了解自己代码在所有提交代码中运行效率的排名

  • 支持多种主流语言:C/C++,Python, Java

  • 可以在线进行测试,方便调试

下面是我刷 LeetCode 的一些收获,希望能够引诱大家有空时刷刷题目。

问题:抽象思维

波利亚用三本书:《How To Solve It》、《数学的发现》、《数学与猜想》)来试图阐明人类解决问题的一般性的思维方法,总结起来主要有以下几种:

  • 时刻不忘未知量。即时刻别忘记你到底想要求什么,问题是什么。(动态规划中问题状态的设定)

  • 试错。对题目这里捅捅那里捣捣,用上所有的已知量,或使用所有你想到的操作手法,尝试着看看能不能得到有用的结论,能不能离答案近一步(回溯算法中走不通就回退)。

  • 求解一个类似的题目。类似的题目也许有类似的结构,类似的性质,类似的解方案。通过考察或回忆一个类似的题目是如何解决的,也许就能够借用一些重要的点子(比较 Ugly Number 的三个题目:263. Ugly Number264. Ugly Number II313. Super Ugly Number)。

  • 用特例启发思考。通过考虑一个合适的特例,可以方便我们快速寻找出一般问题的解。

  • 反过来推导。对于许多题目而言,其要求的结论本身就隐藏了推论,不管这个推论是充分的还是必要的,都很可能对解题有帮助。

刷 LeetCode 的最大好处就是可以锻炼解决问题的思维能力,相信我,如何去思考本身也是一个需要不断学习和练习的技能。

此外,大量高质量的题目可以加深我们对计算机科学中经典数据结构的深刻理解,从而可以快速用合适的数据结构去解决现实中的问题。我们看到很多ACM大牛,拿到题目后立即就能想出解法,大概就是因为他们对于各种数据结构有着深刻的认识吧。LeetCode 上面的题目涵盖了几乎所有常用的数据结构:

  • Stack:简单来说具有后进先出的特性,具体应用起来也是妙不可言,可以看看题目 32. Longest Valid Parentheses

  • Linked List:链表可以快速地插入、删除,但是查找比较费时(具体操作链表时结合图会简单很多,此外要注意空节点)。通常链表的相关问题可以用双指针巧妙的解决,160. Intersection of Two Linked Lists 可以帮我们重新审视链表的操作。

  • Hash Table:利用 Hash 函数来将数据映射到固定的一块区域,方便 O(1) 时间内读取以及修改。37. Sudoku Solver 数独是一个经典的回溯问题,配合 HashTable 的话,运行时间将大幅减少。

  • Tree:树在计算机学科的应用十分广泛,常用的有二叉搜索树,红黑书,B+树等。树的建立,遍历,删除相对来说比较复杂,通常会用到递归的思路,113. Path Sum II 是一个不错的开胃菜。

  • Heap:特殊的完全二叉树,"等级森严",可以用 O(nlogn) 的时间复杂度来进行排序,可以用 O(nlogk) 的时间复杂度找出 n 个数中的最大(小)k个,具体可以看看 347. Top K Frequent Elements

算法:时间空间

我们知道,除了数据结构,具体算法在一个程序中也是十分重要的,而算法效率的度量则是时间复杂度和空间复杂度。通常情况下,人们更关注时间复杂度,往往希望找到比 O( n^2 ) 快的算法,在数据量比较大的情况下,算法时间复杂度最好是O(logn)或者O(n)。计算机学科中经典的算法思想就那么多,LeetCode 上面的题目涵盖了其中大部分,下面大致来看下。

当然,还有一部分问题可能需要一些数学知识去解决,或者是需要一些位运算的技巧去快速解决。总之,我们希望找到时间复杂度低的解决方法。为了达到这个目的,我们可能需要在一个解题方法中融合多种思想,比如在 300. Longest Increasing Subsequence 中同时用到了动态规划和二分查找的方法,将复杂度控制在 O(nlogn)。如果用其他方法,时间复杂度可能会高很多,这种题目的运行时间统计图也比较有意思,可以看到不同解决方案运行时间的巨大差异,如下:

当然有时候我们会牺牲空间换取时间,比如在动态规划中状态的保存,或者是记忆化搜索,避免在递归中计算重复子问题。213. House Robber II一个Discuss会教我们如何用记忆化搜索减少程序执行时间。

语言:各有千秋

对一个问题来说,解题逻辑不会因编程语言而不同,但是具体coding起来语言之间的差别还是很大的。用不同语言去解决同一个问题,可以让我们更好地去理解语言之间的差异,以及特定语言的优势。

速度 VS 代码量

C++ 以高效灵活著称,LeetCode 很好地印证了这一点。对于绝大多数题目来说,c++ 代码的运行速度要远远超过 python 以及其他语言。和 C++ 相比,Python 允许我们用更少的代码量实现同样的逻辑。通常情况下,Python程序的代码行数只相当于对应的C++代码的行数的三分之一左右。

347 Top K Frequent Elements 为例,给定一个数组,求数组里出现频率最高的 K 个数字,比如对于数组 [1,1,1,2,2,3],K=2 时,返回 [1,2]。解决该问题的思路比较常规,首先用 hashmap 记录每个数字的出现频率,然后可以用 heap 来求出现频率最高的 k 个数字。

如果用 python 来实现的话,主要逻辑部分用两行代码就足够了,如下:

num_count = collections.Counter(nums) return heapq.nlargest(k, num_count, key=lambda x: num_count[x]) 

当然了,要想写出短小优雅的 python 代码,需要对 python 思想以及模块有很好的了解。关于 python 的相关知识点讲解,可以参考这里

而用 C++ 实现的话,代码会多很多,带来的好处就是速度的飞跃。具体代码在这里,建立大小为 k 的小顶堆,每次进堆时和堆顶进行比较,核心代码如下:

// Build the min-heap with size k. for(auto it = num_count.begin(); it != num_count.end(); it++){   if(frequent_heap.size() < k){       frequent_heap.push(*it);   }   else if(it->second >= frequent_heap.top().second){       frequent_heap.pop();       frequent_heap.push(*it);   } } 

语言的差异

我们都知道 c++ 和 python 是不同的语言,它们有着显著的区别,不过一不小心我们就会忘记它们之间的差别,从而写出bug来。不信?来看 69 Sqrt(x),实现 int sqrt(int x)。这题目是经典的二分查找(当然也可以用更高级的牛顿迭代法),用 python 来实现的话很容易写出 AC 的代码

如果用 C++ 的话,相信很多人也能避开求中间值的整型溢出的坑:int mid = low + (high - low) / 2;,于是写出下面的代码:

int low = 0, high = x; while(low <= high){   // int mid = (low+high) / 2,  may overflow.   int mid = low + (high - low) / 2;   if(x>=mid*mid && x<(mid+1)*(mid+1)) return mid;   else if(x < mid*mid)  high = mid - 1;   else low = mid + 1; } 

很可惜,这样的代码仍然存在整型溢出的问题,因为mid*mid 有可能大于 INT_MAX,正确的代码在这里。当我们被 python 的自动整型转换宠坏后,就很容易忘记c++整型溢出的问题。

除了臭名昭著的整型溢出问题,c++ 和 python 在位运算上也有着一点不同。以 371 Sum of Two Integers 为例,不用 +, - 实现 int 型的加法 int getSum(int a, int b)。其实就是模拟计算机内部加法的实现,很明显是一个位运算的问题,c++实现起来比较简单,如下:

int getSum(int a, int b) {     if(b==0){         return a;     }     return getSum(a^b, (a&b)<<1); } 

然而用 python 的话,情况变的复杂了很多,归根到底还是因为 python 整型的实现机制,具体代码在这里

讨论:百家之长

如果说 LeetCode 上面的题目是一块块金子的话,那么评论区就是一个点缀着钻石的矿山。多少次,当你绞尽脑汁终于 AC,兴致勃发地来到评论区准备吹水。结果迎接你的却是大师级的代码。于是,你高呼:尼玛,竟然可以这样!然后闭关去思考那些优秀的代码,顺便默默鄙视自己。

除了优秀的代码,有时候还会有直观的解题思路分享,方便看看别人是如何解决这个问题的。@MissMary在"两个排序数组中找出中位数"这个题目中,给出了一个很棒的解释:Share my o(log(min(m,n)) solution with explanation,获得了400多个赞。

你也可以评论大牛的代码,或者提出改进方案,不过有时候可能并非如你预期一样改进后代码会运行地更好。在 51. N-Queens 的讨论 Accepted 4ms c++ solution use backtracking and bitmask, easy understand 中,@binz 在讨论区中纳闷自己将数组 vector<int> (取值非零即一)改为 vector<bool> 后,运行时间变慢。@prime_tang 随后就给出建议说最好不要用 vector<bool>,并给出了两个 StackOverflow 答案

当你逛讨论区久了,你可能会有那么一两个偶像,比如@StefanPochmann。他的一个粉丝 @agave 曾经问 StefanPochmann 一个问题:

Hi Stefan, I noticed that you use a lot of Python tricks in your solutions, like "v += val," and so on... Could you share where you found them, or how your learned about them, and maybe where we can find more of that? Thanks!

StefanPochmann 也不厌其烦地给出了自己的答案:

@agave From many places, though I'd say I learned a lot on CheckiO and StackOverflow (when I was very active there for a month). You might also find some by googling python code golf.

原来大神也是在 StackOverflow 上修炼的,看来需要在 为什么离不开 StackOverflow 中添加一个理由了:因为 StefanPochmann 都混迹于此。

类似这样友好,充满技术味道的讨论,在 LeetCode 讨论区遍地都是,绝对值得我们去好好探访。

成长:大有益处

偶尔会听旁边人说 XX 大牛 LeetCode 刷了3遍,成功进微软,还拿了 special offer!听起来好像刷题就可以解决工作问题,不过要知道还有刷5遍 LeetCode 仍然没有找到工作的人呢。所以,不要想着刷了很多遍就可以找到好工作,毕竟比你刷的还疯狂的大有人在(开个玩笑)。

不过,想想前面列出的那些好处,应该值得大家抽出点时间来刷刷题了吧。


Read full article from LeetCode 刷题指南(一):为什么要刷题 - Just For Fun - SegmentFault


Google Fiber plans to use cheap wireless tech to beat the cable guys - Recode



Google Fiber plans to use cheap wireless tech to beat the cable guys - Recode

CFO Ruth Porat gives the unit a shout-out. By Mark Bergen @mhbergen Jul 28, 2016, 6:17p George Frey/Getty Images Back in April, Recode told you about the next chapter in Google Fiber: An ambitious plan to beam wireless into homes. Today, on Alphabet's second-quarter earnings call, the company gave its most public acknowledgment that wireless is the linchpin of its strategy to take on the large cable and broadband industry. "We continue to see Fiber as a huge market opportunity," said CFO Ruth Porat, citing the company's efforts to push "the frontier with tech applications." She continued: "We're exploring both Fiber and wireless, and you may have seen our recent acquisition of Webpass." Fiber snapped up the small internet provider Webpass, which relies on wireless tech to serve city markets. Porat, being a Google executive, did not get into any details on Fiber's plans here. She did reiterate that it is the biggest source of spending outside of the core Google business.

Read full article from Google Fiber plans to use cheap wireless tech to beat the cable guys - Recode


Google announces add-ons for Docs and Sheets' mobile apps



Google announces add-ons for Docs and Sheets' mobile apps

Want to be able to sign documents on the go? You can download the Android DocuSign app and prepare documents for signatures from inside the Google Docs interface. Need to add complex annotations to a document while riding the train? Use EasyBib to streamline the process. Users can add ProsperWorks to import CRM data, AppSheet to generate mobile apps from data sheets, Scanbot to capture physical documents with your smartphone camera and more.


Read full article from Google announces add-ons for Docs and Sheets' mobile apps


Google Play Music's podcasts are convenient but lack features



Google Play Music's podcasts are convenient but lack features

I have two main gripes with the new Play Music integration: the inability to build custom playlists and the omission of a number of popular shows. Dedicated podcast search wouldn't hurt, but I can survive without it. If a robust feature set is what you're after, Pocket Casts is probably still the best option on Android. It's worth the $4, in my opinion. Even so, Google's new podcast offering is a massive improvement over Stitcher, an app that goes down for days and sometimes weeks at a time.


Read full article from Google Play Music's podcasts are convenient but lack features


How Do I Write a Jackson JSON Serializer & Deserializer? | Steve Hill's Development Blog



How Do I Write a Jackson JSON Serializer & Deserializer? | Steve Hill's Development Blog

Update (12/22/2015) Considering writing serialization classes instead? Check out Serializing POJOs with Jackson.

Jackson is a great JSON serialization library for Java. Finding out how to write serializers and deserializers can be frustrating, in no small part thanks to the enormous API Jackson comes with.

Note The following is known to work with Jackson 1.8.5, which ships with RESTEasy 2.3.2.Final.

Assume we have a naive User class we're interested in writing the Serializer and Deserializer for. Not much is notable here, except for the annotations that tell Jackson who knows how to serialize and deserialize this class.


Read full article from How Do I Write a Jackson JSON Serializer & Deserializer? | Steve Hill's Development Blog


Latest Jackson Integration Improvements in Spring - DZone Java



Latest Jackson Integration Improvements in Spring - DZone Java

Prior to Spring Framework 4.1.1, Jackson HttpMessageConverters were usingObjectMapper default configuration. In order to provide a better and easily customizable default configuration, a new Jackson2ObjectMapperBuilder has been introduced. It is the JavaConfig equivalent of the well known Jackson2ObjectMapperFactoryBean used in XML configuration.

Jackson2ObjectMapperBuilder provides a nice API to customize various Jackson settings while retaining Spring Framework provided default ones. It also allows to createObjectMapper and XmlMapper instances based on the same configuration.

Both Jackson2ObjectMapperBuilder and Jackson2ObjectMapperFactoryBean define a better Jackson default configuration. For example, theDeserializationFeature.FAIL_ON_UNKNOWN_PROPERTIES property set to false, in order to allow deserialization of JSON objects with unmapped properties.

Jackson support for Java 8 Date & Time API data types is automatically registered when Java 8 is used and jackson-datatype-jsr310 is on the classpath. Joda-Time support is registered as well when jackson-datatype-joda is part of your project dependencies.

These classes also allow you to register easily Jackson mixinsmodulesserializers or even property naming strategy like PropertyNamingStrategy.CAMEL_CASE_TO_LOWER_CASE_WITH_UNDERSCORES if you want to have your userName java property translated to user_name in JSON.


Read full article from Latest Jackson Integration Improvements in Spring - DZone Java


How to control the JSON serialization with Jackson @JsonView and Spring-Boot | code.relief();



How to control the JSON serialization with Jackson @JsonView and Spring-Boot | code.relief();

When returning data to our Rest client application, depending on which Rest service was called, we need to limit which data will be serialized while using the same data model. To do this we can use the @JsonView annotation which is provided by the Jackson framework and its integration with Spring-Boot.

Let say we have a simple model like the one below:

SimpleModel

And we want to create two Rest services.

The first Rest service would return some basic User information like its firstname and lastname but without the messages attached to it.


Read full article from How to control the JSON serialization with Jackson @JsonView and Spring-Boot | code.relief();


Big Data Vendor Revenue And Market Forecast 2012-2017 - Wikibon



Big Data Vendor Revenue And Market Forecast 2012-2017 - Wikibon

As mentioned in the introduction of this report, Hadoop-related software and services matured rapidly in 2012, leading to increased adoption of enterprise-level products by companies in industries beyond the Web. In many cases, companies that had previously deployed community (read: free) versions of vendor Big Data software bundles for proof-of-concept projects began upgrading to paid software and services to support production-level deployments.

As a result, leading Hadoop distribution vendors Cloudera and MapR enjoyed significant revenue growth last year. Cloudera grew revenue to $56 million in 2012 from $18 million in 2011. MapR grew revenue to $23 million in 2012 from $7 million in 2011. Hortonworks, in its first full year of existence, did $18 million in revenue in 2012.

Likewise, in the related NoSQL space a handful of vendors that offer commercial versions of popular open source databases enjoyed significant revenue growth as pilot projects blossomed into production deployments supporting real-time, Web-scale applications and services.

Among these vendors is 10gen, which offers a commercial version of the open source, document-oriented MongoDB; Aerospike, whose NoSQL database supports very low-latency online transactional applications; and DataStax, the company behind commercial Cassandra that counts Netflix among its marquee customers.

Leading the way in terms of revenue in the Hadoop/NoSQL subsegment of the Big Data market in 2012 was a 10-year-old firm, MarkLogic. The company's NoSQL document store is in use at Bank Of America, the Defense Intelligence Agency and Warner Brothers, among other household names in the media and financial services industries.

Ultimately, however, the NoSQL market is largely up for grabs. Each NoSQL database has its related strengths and weaknesses, and no one NoSQL database currently "does it all." Big Data practitioners must take a number of factors into consideration when selecting a NoSQL database to facilitate large-scale transactional workloads, including scalability, performance, security, and ease-of-development.


Read full article from Big Data Vendor Revenue And Market Forecast 2012-2017 - Wikibon


hihoCoder week 84-1-Lucky Substrings | bitJoy > code



hihoCoder week 84-1-Lucky Substrings | bitJoy > code

A string s is LUCKY if and only if the number of different characters in s is a fibonacci number. Given a string consisting of only lower case letters, output all its lucky non-empty substrings in lexicographical order. Same substrings should be printed once.

输入
A string consisting no more than 100 lower case letters.

输出
Output the lucky substrings in lexicographical order, one per line. Same substrings should be printed once.

样例输入
aabcd

样例输出
a
aa
aab
aabc
ab
abc
b
bc
bcd
c
cd
d


如果一个字符串中不同字母的个数是斐波那契数,则称这个字符串是Lucky的,问字符串S中哪些子串是Lucky子串。

要正确理解Lucky的定义,是不同字母的个数,而不是不同字母的个数序列。比如aabc是Lucky的,因为其有a,b,c共3种字母,而3在斐波那契数列中,所以aabc是Lucky的。不能理解为aabc中a出现2次,b,c分别出现1次,构成1,1,3是斐波那契数列,所以aabc是Lucky的。

所以只能枚举所有子串,判断每个子串是否为Lucky的。如果知道了S[i,...,j]中不同字母的个数,判断S[i,...,j+1]时,只要判断S[j+1]这个字母是否在之前出现过。所以通过保存之前不同字母的个数,可以快速判断S[i,...,j+1]的情况。


Read full article from hihoCoder week 84-1-Lucky Substrings | bitJoy > code


Problem A. Lucky Substrings · Data Structure and Algorithm notes



Problem A. Lucky Substrings · Data Structure and Algorithm notes

A string s is LUCKY if and only if the number of different characters in s is a fibonacci number. Given a string consisting of only lower case letters, output all its lucky non-empty substrings in lexicographical order. Same substrings should be printed once.

+

输入

A string consisting no more than 100 lower case letters.

+

输出

Output the lucky substrings in lexicographical order, one per line. Same substrings should be printed once.

+

样例输入

aabcd 

样例输出

a aa aab aabc ab abc b bc bcd c cd d 

题解

简单实现题,即判断 substring 中不同字符串的个数是否为 fibonacci 数,最后以字典序方式输出,且输出的字符串中相同的只输出一次。分析下来需要做如下几件事:

+

  1. 两重 for 循环取输入字符串的所有可能子串。
  2. 判断子串中不同字符的数目,这里使用可以去重的数据结构Set比较合适,最后输出Set的大小即为不同字符的数目。
  3. 判断不同字符数是否为 fibonacci 数,由于子串数目较多,故 fibonacci 应该首先生成,由于字符串输入最大长度为100,故使用哈希表这种查询时间复杂度为 O(1)O(1) 的数据结构。
  4. 将符合条件的子串加入到最终结果,由于结果需要去重,故选用Set数据结构。


Read full article from Problem A. Lucky Substrings · Data Structure and Algorithm notes


2016 年 4 月小结 - Lucida



2016 年 4 月小结 - Lucida

  • 单词量从上个月的 13700 上升到 14700
  • 通过 Bigger Leaner Stronger 的运动计划和饮食方案,体重从 68kg 下降到 66.5 kg。

习惯

这个月并未有新的习惯

游戏

  • Starcraft 2: 开始用 Zerg 练习对战模式,通过 YouTube 的教程,从 Very Easy + Normal Speed 一路打到和 Very Hard + Fastest 互有胜负。

阅读

书名: 进度 简评

技术

  • Algorithms 4th: 100% 总算看完了,尽管跳过了不少课后题。重温图算法和字符串算法。
  • Facts and Fallacies on Software Engineering:100% 非常辛辣简洁的对软件工程书。作者用其 40+ 年的经验把各种方法,各种理论,以及开源软件黑了一遍。

非技术

  • Essentialism: 100% 重温精要主义
  • The Life Project: 100% 讲述了英国从 1946 年开始,一直做到现在的人口调查(Cohort),通过 70 年对几代人群的不断跟踪,以及对数据的整理,诞生了很多社科理论
  • 褚时健传:100% 非常强悍的个人经历:16 岁丧父,24 岁丧母,而立之年被打倒,文革期间带领制糖厂在极其困难的条件下为将其转亏为盈,50 岁时上任玉溪卷烟厂,将其从一个地方小厂逐步打造成千亿级别的亚洲第一卷烟厂,70 岁时由于政治斗争被 TG 以贪污为名判刑,其女儿于同期自杀,在这种条件下,80 岁时出狱,用褚橙重新出发。我想,这才是对 Resilient 最好的解读。

阅读 Medium 一段时间之后发现它并非每天都有必读文章,于是把阅读频率降到了一周两三次。然而收益于单词量的增长,每天可以阅读七八篇 NY Times 的长篇报道,以及两三篇 Economist 文章。


Read full article from 2016 年 4 月小结 - Lucida


re: Why Uber Engineering Switched from Postgres to MySQL - Ayende @ Rahien



re: Why Uber Engineering Switched from Postgres to MySQL - Ayende @ Rahien

time to read 6 min | 1173 words The Uber Engineering group have posted a really great blog post about their move from Postgres to MySQL. I mean that quite literally, it is a pleasure to read, especially since they went into such details as the on-disk format and the implications of that on their performance. For fun, there is another great post from Uber, about moving from MySQL to Postgres , which also has interesting content. Go ahead and read both, and we'll talk when you are done. I want to compare their discussion to what we have been doing. In general, Uber's issue fall into several broad categories: Secondary indexes cost on write Replication format Connection handling Secondary indexes Postgres maintain a secondary index that points directly to the data on disk, while MySQL has a secondary index that has another level of indirection. The images show the difference quite clearly:

Read full article from re: Why Uber Engineering Switched from Postgres to MySQL - Ayende @ Rahien


一些不错的电子书网站 | 正经的程序猿



一些不错的电子书网站 | 正经的程序猿

1、各类技术电子书(中文版的也不少),大部分是和开源项目有关的:

https://www.gitbook.com/

2、各类技术电子书,各种国外知名出版社(主要OReilly)的书,有些上传时间年代久远的已经被百度河蟹了:

http://www.salttiger.com/

3、同样是技术类电子书,不过是国外的网站,不备梯子的情况下有点卡:

http://it-ebooks.info/

4、有但不限于技术类的电子书网,好像下载也是略慢:

http://bookdl.com/


Read full article from 一些不错的电子书网站 | 正经的程序猿


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