Project Lombok



Project Lombok

Any class definition may be annotated with @ToString to let lombok generate an implementation of the toString() method. By default, it'll print your class name, along with each field, in order, separated by commas.

By setting the includeFieldNames parameter to true you can add some clarity (but also quite some length) to the output of the toString() method.

By default, all non-static fields will be printed. If you want to skip some fields, you can name them in the exclude parameter; each named field will not be printed at all. Alternatively, you can specify exactly which fields you wish to be used by naming them in the of parameter.

By setting callSuper to true, you can include the output of the superclass implementation of toString to the output. Be aware that the default implementation of toString() in java.lang.Object is pretty much meaningless, so you probably don't want to do this unless you are extending another class.


Read full article from Project Lombok


Kafka - Rewind Consumer Offsets



Kafka - Rewind Consumer Offsets

One of the most important features from Apache Kafka is how it manages Multiple Consumers. Each consumer group has a current offset, that determine at what point in a topic this consumer group has consume messages. So, each consumer group can manage its offset independently, by partition.

This offers the possibility to rollback in time and reprocess messages from the beginning of a topic and regenerate the current status of the system.


Read full article from Kafka - Rewind Consumer Offsets


KIP-35 - Retrieving protocol version - Apache Kafka - Apache Software Foundation



KIP-35 - Retrieving protocol version - Apache Kafka - Apache Software Foundation

This KIP aims to solve the problem that there is currently no way for a Kafka client to know which API version the broker supports. This means a client might not be able to perform its desired functionality, nor report any meaningful errors back to the application. This makes it hard for clients and applications to support multiple versions of Kafka, which in turn limits the Kafka eco-system since applications and clients will need to be manually built or configured for a specific broker version.


Read full article from KIP-35 - Retrieving protocol version - Apache Kafka - Apache Software Foundation


Portland deaths: Two stabbed trying to stop anti-Muslim abuse - BBC News



Portland deaths: Two stabbed trying to stop anti-Muslim abuse - BBC News

27 May 2017 These are external links and will open in a new window These are external links and will open in a new window Close share panel Image copyright CBS/EVN Image caption The attack took place on a MAX train at Hollywood Transit Station Two men have been killed as they tried to stop a man abusing two women who appeared to be Muslim, police in the US city of Portland say. The abusive man turned on the two men and fatally stabbed them, police said. The incident happened on a commuter train. Another passenger was wounded before the attacker was arrested. The Council on American-Islamic Relations urged President Trump to speak out against increasing Islamophobia in the US. It accused the president of exacerbating the trend with his statements and policies. The attack took place at about 16:30 local time (00:30 GMT) on a train at Hollywood Transit Station, police said in a statement . One of the victims died at the scene, the other died in hospital.

Read full article from Portland deaths: Two stabbed trying to stop anti-Muslim abuse - BBC News


What is the difference between Recruitment and Talent Acquisition | Hemant Kumaarr | Pulse | LinkedIn



What is the difference between Recruitment and Talent Acquisition | Hemant Kumaarr | Pulse | LinkedIn

Talent Acquisition means a view of not only filling positions, but also utilization of the candidates and their skills that come out of a rigorous recruiting process as a means to fill similar positions in the future also.

These future positions can be identified today by looking at the succession management plan, or by analyzing the history of attrition for certain positions. This makes it easy to predict that specific openings will occur at a pre-determined period in time.

In few cases of Strategic Talent Acquisition, clients will recruit today for positions that do not even exist today but are expected to become available in the future.

Read full article from What is the difference between Recruitment and Talent Acquisition | Hemant Kumaarr | Pulse | LinkedIn


Donald Trump, Emmanuel Macron share a long handshake



Donald Trump, Emmanuel Macron share a long handshake

During their first meeting, President Trump and France's Emmanuel Macron shook hands for long enough to catch the attention of the pool.

Per the pool report: "They shook hands for an extended period of time. Trump and Macron gripped the other's hand with considerable intensity, their knuckles turning white and their jaws clenching and faces tightening."


Read full article from Donald Trump, Emmanuel Macron share a long handshake


Trump at NATO: Handshake with Macron in Brussels shows his trick doesn't always work — Quartz



Trump at NATO: Handshake with Macron in Brussels shows his trick doesn't always work — Quartz

While in the United States, president Donald Trump notoriously shakes people's hands to the point where he's almost twisting their arms out of the sockets, often leading to comically awkward scenes during photo-ops with heads of states or politicians. But during his first overseas trip as president, Trump seems to be losing at his own game.


Read full article from Trump at NATO: Handshake with Macron in Brussels shows his trick doesn't always work — Quartz


30 Behaviors That Will Make You Unstoppable – Thrive Global



30 Behaviors That Will Make You Unstoppable – Thrive Global

A lot of people are good at what they do. Some are even elite. A select few are completely unstoppable.

Those who are unstoppable are in their own world. They don't compete with anyone but themselves. You never know what they will do — only that you will be forced to respond. Even though they don't compete with you, they make you compete with them.

Are you unstoppable? By the end of this blog you will be.

Let's get started:

1. Don't think — know and act.

"Don't think. You already know what you have to do, and you know how to do it. What's stopping you?" — Tim Grover


Read full article from 30 Behaviors That Will Make You Unstoppable – Thrive Global


Donald Trump offers shoves and strange handshakes on the world stage | Ross Barkan | Opinion | The Guardian



Donald Trump offers shoves and strange handshakes on the world stage | Ross Barkan | Opinion | The Guardian

Thursday 25 May 2017 19.09 EDT Donald Trump doesn't have to open up his mouth to make news anymore. The poor prime minister of Montenegro, a country with less people than El Paso, Texas, learned this the hard way when Trump gave him a big shove on Thursday to get to the front of a pack of world leaders. Doesn't Dusko Markovic know you can't box out The Donald? The shove came as Trump met with the uncomfortable members of Nato in Brussels to lecture them on their need to spend more on their defense. What this has to do with shoving Markovic in an attempt to shake hands with Nato Secretary-General Jens Stoltenberg is entirely unclear, but no one ever said making America great again was easy. Especially when the new president loves to shake hands. But it's his handy clash with France's new president, Emmanuel Macron, that will likely overshadow whatever Trump has been trying to do on his first jaunt abroad as commander-in-chief. Trump v Macron:

Read full article from Donald Trump offers shoves and strange handshakes on the world stage | Ross Barkan | Opinion | The Guardian


Donald Trump offers shoves and strange handshakes on the world stage | Ross Barkan | Opinion | The Guardian



Donald Trump offers shoves and strange handshakes on the world stage | Ross Barkan | Opinion | The Guardian

Thursday 25 May 2017 19.09 EDT Donald Trump doesn't have to open up his mouth to make news anymore. The poor prime minister of Montenegro, a country with less people than El Paso, Texas, learned this the hard way when Trump gave him a big shove on Thursday to get to the front of a pack of world leaders. Doesn't Dusko Markovic know you can't box out The Donald? The shove came as Trump met with the uncomfortable members of Nato in Brussels to lecture them on their need to spend more on their defense. What this has to do with shoving Markovic in an attempt to shake hands with Nato Secretary-General Jens Stoltenberg is entirely unclear, but no one ever said making America great again was easy. Especially when the new president loves to shake hands. But it's his handy clash with France's new president, Emmanuel Macron, that will likely overshadow whatever Trump has been trying to do on his first jaunt abroad as commander-in-chief. Trump v Macron:

Read full article from Donald Trump offers shoves and strange handshakes on the world stage | Ross Barkan | Opinion | The Guardian


Using Spring managed Bean in non-managed object - JDriven



Using Spring managed Bean in non-managed object - JDriven

We have to deal with legacy code, even when we would like to use the best and newest technologies available. Imagine the new code is written with the newest technologies of the Spring Framework and the legacy code is not written in Spring at all. Then using Spring managed Beans in non-managed Spring objects is one of the patterns we have to deal with. The legacy code has non-managed Spring objects, while the code we want to reference to is a Spring managed Bean. How do we solve this problem?

Read full article from Using Spring managed Bean in non-managed object - JDriven


[TIKA-1723] Integrate language-detector into Tika - ASF JIRA



[TIKA-1723] Integrate language-detector into Tika - ASF JIRA

The language-detector project at https://github.com/optimaize/language-detector is faster, has more languages (70 vs 13) and better accuracy than the built-in language detector.

This is a stab at integrating it, with some initial findings. There are a number of issues this raises, especially if Chris A. Mattmann moves forward with turning language detection into a pluggable extension point.


Read full article from [TIKA-1723] Integrate language-detector into Tika - ASF JIRA


Traveling With Baby? 8 Ways to Keep Little Ones Amused | What to Expect



Traveling With Baby? 8 Ways to Keep Little Ones Amused | What to Expect

  • Carrie Underwood you're not, but your baby loves to hear you sing just the same. Not only does he adore your familiar voice, but music is a surefire soother. You don't have to stick to lullabies either. Croon your rock-and-roll faves, and then switch it up by humming the songs, or substituting "Moo moo moo" for the words. Even better, swap your baby's name for the name in a song like "My Darling Clementine" or Eric Clapton's "Layla." By five months your baby recognizes his own name, so your song is sure to get his attention. Worried that the guy in 19C won't be as enamored of your rendition? He's sure to like it better than the alternative (crying, and lots of it).


  • Read full article from Traveling With Baby? 8 Ways to Keep Little Ones Amused | What to Expect


    Checking Character Properties (The Java™ Tutorials > Internationalization > Working with Text)



    Checking Character Properties (The Java™ Tutorials > Internationalization > Working with Text)

    The Character.getType method returns the Unicode category of a character. Each category corresponds to a constant defined in the Character class. For instance, getType returns the Character.UPPERCASE_LETTER constant for the character A. For a complete list of the category constants returned by getType, see the Character API documentation. The following example shows how to use getType and the Character category constants. All of the expressions in these if statements are true:


    Read full article from Checking Character Properties (The Java™ Tutorials > Internationalization > Working with Text)


    “This Is Crazy”: Elizabeth Warren Mops the Floor with Steve Mnuchin in a Brutal Exchange | Vanity Fair



    "This Is Crazy": Elizabeth Warren Mops the Floor with Steve Mnuchin in a Brutal Exchange | Vanity Fair

    Levin Report "This Is Crazy": Elizabeth Warren Mops the Floor with Steve Mnuchin in a Brutal Exchange "This is like something straight out of George Orwell." by By Tasos Katopodis/Getty Images. Few of Donald Trump's genuinely populist economic proposals from the campaign trail seem to have survived the transition to the White House. In retrospect, it seems foolish to have put any stock whatsoever in his sundry musings about "the government" paying for everyone's health care , or hedge funds "getting away with murder," or how the wealthy should "pay more" in taxes , or how he'd like to see a minimum wage "increase of some magnitude." Each of those proposals was quickly replaced by its opposite, almost as if Trump doesn't care about the words he says or actually believe in anything at all. So it should come as no surprise that Donald Trump has vacillated on the possibility of bringing back Glass-Steagall,

    Read full article from "This Is Crazy": Elizabeth Warren Mops the Floor with Steve Mnuchin in a Brutal Exchange | Vanity Fair


    Dems push for House vote on releasing Trump’s tax returns | TheHill



    Dems push for House vote on releasing Trump's tax returns | TheHill

    Trump has long maintained he won't releasing his tax returns because of an ongoing IRS audit, though many have noted that individuals under audit can still choose to make their tax returns public.

    Trump's lawyers said last week that his income tax returns don't show income from Russian sources or debt owed to Russians, with the exceptions of $95 million paid by a Russian billionaire for a Florida estate and $12.2 million related to holding the Miss Universe pageant in Moscow in 2013.

    CNN reported last week that Senate investigators probing Russia's role in the 2016 election have also asked the Treasury Department's criminal investigation division for information regarding Trump and top associates. 


    Read full article from Dems push for House vote on releasing Trump's tax returns | TheHill


    Donald Trump Reportedly Asked James Comey To Stop Michael Flynn Investigation | HuffPost



    Donald Trump Reportedly Asked James Comey To Stop Michael Flynn Investigation | HuffPost

    05/16/2017 05:38 pm ET | Updated 26 minutes ago Donald Trump Reportedly Asked James Comey To Stop Michael Flynn Investigation The president reportedly made the request during a February meeting with the then-FBI director. President Donald Trump asked former FBI Director James Comey to end his agency's investigation of former national security adviser Michael Flynn,  The New York Times reported Tuesday.  According to the bombshell report , Trump made the request of Comey during a February meeting in the Oval Office. Comey reportedly detailed the meeting in a memo, which an FBI official later shared with the Times.  A White House statement to HuffPost denied the events described in the memo: While the President has repeatedly expressed his view that General Flynn is a decent man who served and protected our country, the President has never asked Mr. Comey or anyone else to end any investigation, including any investigation involving General Flynn.

    Read full article from Donald Trump Reportedly Asked James Comey To Stop Michael Flynn Investigation | HuffPost


    Trump revealed highly classified information to Russian foreign minister and ambassador - The Washington Post



    Trump revealed highly classified information to Russian foreign minister and ambassador - The Washington Post

    Get breaking news alerts from The Washington Post Turn on desktop notifications? It looks like you've previously blocked notifications. Please update your browser permissions to allow them. The inside track on Washington politics. Be the first to know about new stories from PowerPost. Sign up to follow, and we'll e-mail you free updates as they're published. You'll receive free e-mail news updates each time a new story is published. You're all set! The inside track on Washington politics. Be the first to know about new stories from PowerPost. Sign up to follow, and we'll e-mail you free updates as they're published. You'll receive free e-mail news updates each time a new story is published. You're all set! (The Washington Post) President Trump revealed highly classified information to the Russian foreign minister and ambassador in a White House meeting last week, according to current and former U.S. officials,

    Read full article from Trump revealed highly classified information to Russian foreign minister and ambassador - The Washington Post


    Avoid Unwanted Component Scanning of Spring Configuration - DZone Java



    Avoid Unwanted Component Scanning of Spring Configuration - DZone Java

    I came through interesting problem on Stack Overflow. Brett Ryan had problem that Spring Security configuration was initialized twice. When I was looking into his code I spot the problem. Let me show show the code.

    He has pretty standard Spring application (not using Spring Boot). Uses more modern Java servlet Configuration based on Spring's AbstractAnnotationConfigDispatcherServletInitializer.


    Read full article from Avoid Unwanted Component Scanning of Spring Configuration - DZone Java


    @EnableAutoConfiguration Annotation in Spring Boot



    @EnableAutoConfiguration Annotation in Spring Boot

    @EnableAutoConfiguration annotation auto-configures the beans that are present in the classpath. This simplifies the developers work by guessing the required beans from the classpath and configure it to run the application. This annotation is part of the spring boot project.


    Read full article from @EnableAutoConfiguration Annotation in Spring Boot


    codeforces #413 B T-shirt buying (贪心) | 蒟蒻111qqz的小窝



    codeforces #413 B T-shirt buying (贪心) | 蒟蒻111qqz的小窝

    题意:有n个T恤,每个价格都不同,有三种颜色,分别用1,2,3表示,每件T恤给出前xiong和后背的颜色。现在有m个顾客排成一队,对于每个顾客,给出他喜欢的颜色,只要一个T恤的前xiong或者后背的颜色之一满足该颜色即可。顾客总希望买符合他喜欢颜色的T恤中价格最低的。现在问每个顾客买到的T恤的价格,如果某个顾客没有买T恤,输出-1

    思路:贪一下?

    对于每个颜色,找到价格最低的。记录的时候顺便记录id,以标记某件有2个颜色的衣服是否卖出去了。


    Read full article from codeforces #413 B T-shirt buying (贪心) | 蒟蒻111qqz的小窝


    Java动态修改Enum实例-码农场



    Java动态修改Enum实例-码农场

    众所周知,enum类型实例数量是固定的,甚至还被用来设计单例。但有时候仍然存在需要动态增加Enum实例的场景,这也并非一定是设计失败,也可能是增加灵活性的实际需求,比如一些web框架,再比如HanLPFork HanLP 给HanLP点赞 关注HanLP中的动态用户自定义词性。然而最大的障碍是switch语句生成的虚构类,本文参考Java Specialists第161期,提供一份可用的解决方案与实例代码。


    Read full article from Java动态修改Enum实例-码农场


    程序员4月书讯:Angular来了! - 图灵教育 - 博客频道 - CSDN.NET



    程序员4月书讯:Angular来了! - 图灵教育 - 博客频道 - CSDN.NET

    作者:Raymond Camden
    译者:马德奎
    定价:39.00元 / 电子书:19.99元

    • 为服务器减压,节省网络流量,提升访问速度!
    • 让离线应用程序得以真正实现!

    《客户端存储技术》从实用角度出发,以丰富的示例代码介绍Cookie、Web存储、IndexedDB等多种客户端存储技术,以及用于简化客户端存储的JavaScript库,如Lockr、Dexie和localForage等。还会清楚公正地讨论这些技术实际上得到了多大程度的支持。

    本书适合所有Web开发人员阅读。


    Read full article from 程序员4月书讯:Angular来了! - 图灵教育 - 博客频道 - CSDN.NET


    About Knife — Chef Docs



    About Knife — Chef Docs

    knife is a command-line tool that provides an interface between a local chef-repo and the Chef server. knife helps users to manage:

    • Nodes
    • Cookbooks and recipes
    • Roles, Environments, and Data Bags
    • Resources within various cloud environments
    • The installation of the chef-client onto nodes
    • Searching of indexed data on the Chef server

    Read full article from About Knife — Chef Docs


    JEP 195: Scalable Native Memory Tracking



    JEP 195: Scalable Native Memory Tracking

    This project is focused on solving the bottlenecks in the current native memory tracking implementation, especially the memory and CPU overheads on tracking malloc activities.

    The new approach eliminates malloc tracking records by co-locating tracking data along with malloc'd memory, which not only reduces the memory for the tracking data but also avoids the processing of raw tracking data. A lock-free hash table is used to track malloc allocation sites; this data structure further reduces the memory overhead for malloc detail tracking and query time. It also avoids blocking calls on regular JVM execution paths while tracking malloc activities, which should also reduce the impact to JVM performance.

    The new implementation co-locates the malloc tracking header with user data, it ensures that user data aligns with malloc alignment in a production build (8 bytes on 32-bit systems and 16 bytes on 64-bit systems), and 8-byte alignment on debug build.


    Read full article from JEP 195: Scalable Native Memory Tracking


    White nationalist Richard Spencer leads torch-bearing protesters defending Lee statue - The Washington Post



    White nationalist Richard Spencer leads torch-bearing protesters defending Lee statue - The Washington Post

    The inside track on Washington politics. Be the first to know about new stories from PowerPost. Sign up to follow, and we'll e-mail you free updates as they're published. You'll receive free e-mail news updates each time a new story is published. You're all set! Get breaking news alerts from The Washington Post Turn on desktop notifications? It looks like you've previously blocked notifications. Please update your browser permissions to allow them. The inside track on Washington politics. Be the first to know about new stories from PowerPost. Sign up to follow, and we'll e-mail you free updates as they're published. You'll receive free e-mail news updates each time a new story is published. You're all set! Protesters gather at Lee Park in Charlottesville on Saturday. (Allison Wrabel/Daily Progress) RICHMOND — Self-proclaimed white nationalist Richard Spencer led a large group of demonstrators carrying torches and chanting "You will not replace us" Saturday in Charlottesville,

    Read full article from White nationalist Richard Spencer leads torch-bearing protesters defending Lee statue - The Washington Post


    [SOLR-5772] duplicate documents between solr "block join" documents and "normal" document - ASF JIRA



    [SOLR-5772] duplicate documents between solr "block join" documents and "normal" document - ASF JIRA

    I have seen the same issue myself as I started to make use of nested documents. The only way to ensure uniqueness (when updating) is to always have a sub-document even if this does not reflect your data.

    This is especially inconvenient since the "empty" child document must have an id field since it is a required field.

    I also found this unanswered StackOverflow post that shows another user seeing this bug:


    Read full article from [SOLR-5772] duplicate documents between solr "block join" documents and "normal" document - ASF JIRA


    LintCode二叉树&递归分治题总结 - Logan's - 博客频道 - CSDN.NET



    LintCode二叉树&递归分治题总结 - Logan's - 博客频道 - CSDN.NET

    376. Binary Tree Path Sum

    要求等于target从根节点到叶子节点的路径和的组合,用DFS。

    递归需要注意的是,终止情况是什么,也就是遇到叶子节点的时候返回,如果遇到叶子节点的时候恰好满足路径和等于target,就把这条路径加到总结果里面。

    然后就是递归的主题,遇到左子节点、遇到右子节点的时候进入子递归。然后记得加入path路径后要remove掉,以方便保持当前路径的唯一性。


    Read full article from LintCode二叉树&递归分治题总结 - Logan's - 博客频道 - CSDN.NET


    When to use dynamic programming - 'Aha !' Moments In Coding - Quora



    When to use dynamic programming - 'Aha !' Moments In Coding - Quora

    Wikipedia: There are two key attributes that a problem must have in order for dynamic programming to be applicable: optimal substructure and overlapping subproblems.

    1.) Optimal substructure: In layman terms, if I could break a problem into smaller versions of it, and then combine solutions to the smaller problems, I'll have solved the problem at hand.

    2.) Overlapping subproblems:  While solving those smaller problem that leads to the same repetitive calculation steps, we term these as overlapping sub problems.

    Hence instead of solving for the same calculation steps over and over, we can store solutions to previous calculated steps it into a memory such as hash map or an array.

    *Note: Some problems that exhibit optimal substructure but not overlapping subproblems are termed  'divide and conquer' method instead. Such as merge sort.

    *Edit: I have kindof internalised the above as simply figuring out whether a solution to a problem can be built from a bottom to top approach. So instead of the standard Fibionacci algorithm that does fib(n − 1) + fib(n − 2), you would do fib(1), fib(2) ... fib(n) and  'cache' intermittent result.

    Either that, or we could also view problem as: if we can cache it to optimize, cache it ! (at the expense of memory of course)

    Read full article from When to use dynamic programming - 'Aha !' Moments In Coding - Quora


    What is the best way to use Apache Solr for relational JOIN? - Quora



    What is the best way to use Apache Solr for relational JOIN? - Quora

    Why not run a single-use script that does the joins on the SOLR index to replace the authorID with the author name, or add the field if you need both?  Updating 10,000,000+ documents will take a while, but it's certainly doable.  Then you can have new documents indexed with both fields as well, doing the JOIN one at a time.

    In general, SOLR works best with completely denormalized data.

    EDIT:
    Okay, if it's more than just authors' names, you could still denormalize the data, repeating your documents for each of the related author documents.  However, that's an ugly solution, and SOLR 4 does have "JOIN" capability.  You'd first need to at least have a pipeline where author data is indexed into SOLR in real-time.  Then yes, I'd use ElasticSearch to easily handle the complex SOLR queries involving JOIN-like operations.

    Read full article from What is the best way to use Apache Solr for relational JOIN? - Quora


    Bloomberg - 小土刀的面试刷题笔记



    Bloomberg - 小土刀的面试刷题笔记

    总的面试时间是一个小时,面我的是两个白人大叔,人都还算是nice,不过2对1就是有点车轮战的感觉。。。 下面直接上干活:

    1. Why BB
    2. Why Software Engineer
    3. What is hashtable? How to resolve the collision?
    4. Difference between C and C++
    5. How to mimic Class in C++ using C (especiallythe private part)
    6. Find out the maximum average of 30 numbers givena sequence of number
    7. Follow up: how to make it able to deal with realtime data?
    8. Logic question: given a scale, how to tell thedifferent one from 12 balls or something (using the minimum times of comparison)
    9. Chatting about projects on the resume

    卖车票,n个车票窗口,每个窗口里有a_i张票,票价和窗口内剩的票数一样。需要卖掉m张票。问卖m张票得到的最多的总钱数(max profit)

    这道题是不是用priority Queue啊?Maxheap

    海量live stream的数字,求median


    Read full article from Bloomberg - 小土刀的面试刷题笔记


    Amazon - 小土刀的面试刷题笔记



    Amazon - 小土刀的面试刷题笔记

    设计一个 zoo

    问清楚

    Opentable

    opentable, design. 完全自己设计数据结构 和 接口需求, 用户输入 restaurant, timeslot, 人数, 返回是否可以预订

    一个restaurant 可能有多个桌子, 每个桌子可能可以坐多个人 如果预订的时候,人数大于一个桌子, 可以把相邻的桌子 combine timeslot 30分钟算一个, 一天就可以算24*2个, 编号从0到47, 用户的输入只能有一个 timeslot

    三角形棋盘

    只有一个空,像跳棋那么走,走过空就可以把中间那抽掉,然后OOD设计。然后follow就是如果不同棋盘怎 么设计

    traffic management system

    大 概就是一个十字路口,有好几个方向的汽车,红绿灯,行人,设计这个的controller吧,然 后边讨论思路边写controller的method什么的,最后讨论讨论怎么initialization

    问题是很模糊的问题,让我设计一个交 通路口,目的是统计车流,反馈给我们的用户。一听我就知道是故意很模糊的,所以我就加 紧clarify,比如问每个时段和日期车流不同,如何区别;这个application是给谁用的;交 通路口可以分N车道,如何规范;等等一系列

    图书推荐系统

    你有朋友A,朋友A有他的朋友B, 你要看到所有A,B,B的朋友的推荐书单。要代码实现

    OO DESIGN一个"UBER"

    问清楚

    文件系统

    主要focus文件权限的设计

    poker game

    OOD design a poker game and different methods in each class.1

    电梯设计

    经典设计题

    设计电梯箱,按键面板等对象和它们之间的关系,没有深入调度
    算法细节。

    解析表达式

    解析表达 式,例如"1*2 + 3",关键要用面向对象的思想设计。需要可以拓展,支持括号,支持开 方之类的。这题感觉自己没思路,瞎答了一通

    @@@ Parking Lot

    传统题目

    一开始从OOD的角度来设计。后来面试官说我应该think bigger,才意识到应该是从一个 通用系统架构的角度来回答这个问题。于是就开始扯后台系统架构,想到经典的三层系统机 构从来不会答偏题于是就开始往上搬了。第一层接入层,第二层逻辑层,第三层存储层。接 入层收到用户请求根据协议和请求类型转发给合适的逻辑层。逻辑层包括多个不同服务,各 干各的事,完成库存啊计费啊汇率转换啊等等操作。存储层当然就是数据库,mysql和 nosql大家都懂的,上来把基本表建好,就直接用吧,有需要就扯缓存。比如我就扯了用 redis当缓存,缓存当然有各种不同粒度,各自命中率肯定不一样等等。问我如何扩展方 面,我的回答就是各层内部放入是随便加服务的,只要服务起来了之后到Zookeeper去注 册让其他层的服务调用的时候能找到就好了,存储层扩展有很多Proxy可以用,比如我厂就 有一个叫Atlas的开源项目,是一个很出色的Mysql Proxy,大家可以去Git看看。然后大家 可以根据需要扯一些优化点,找不到也无所谓。

    设计一个机场调度系统

    和面试官多 交流有哪些实体需要抽象吧,要想清楚业务流程里的参与者和用例,还有之后的耦合内聚怎么优化等等。

    查询机制

    给一个数组和一个范围,要返回范围里的最小值,然后扩 展到如何缓存这个查询。一开始搞我以为是算法题,DP?排序?扯了半天,后来发现原来 是OOD,囧。。。关键是如何解耦缓存查询和实时查询这俩类,然后扯了扯工厂模式,依 赖注入等等。

    设计电话本

    http://www.cs.gordon.edu/courses/cs211/AddressBookExample/

    生物分类

    设计数据结构表示生物学门纲目科属种

    OOD (Tic-tac Game) Followups

    CC150

    HashTable出现很多collision怎么办

    (Rehashing)load factor

    truck tracking system

    要求实现查询truck的地点,每天的行程之类 的。一开始写了一个truck class,然后在引导下一点一点的增加功能

    火箭打彗星

    火箭每次发射之后需要五分钟准备时间,雷达会监控彗星出现的距离,每 个火箭只能打最近的一个彗星,问用什么data structure 记录彗星的情况,要求时间复杂度 O(1)的

    图书推荐系统

    类似facebook, twitter那样的好友系统,可以看评价,可以写评价,有好友
    列表一类的。

    顺序 hashmap

    重写一个HashMap,多加一个功能,可以按照insert的顺序输出出来


    Read full article from Amazon - 小土刀的面试刷题笔记


    lintcode阶梯训练第三关(九章) - Dashuai_Liu的博客 - 博客频道 - CSDN.NET



    lintcode阶梯训练第三关(九章) - Dashuai_Liu的博客 - 博客频道 - CSDN.NET

    595、Binary Tree Longest Consecutive Sequence

    • 题目
      Given a binary tree, find the length of the longest consecutive sequence path.
      The path refers to any sequence of nodes from some starting node to any node in the tree along the parent-child connections. The longest consecutive path need to be from parent to child (cannot be the reverse).


    Read full article from lintcode阶梯训练第三关(九章) - Dashuai_Liu的博客 - 博客频道 - CSDN.NET


    FG面经Prepare: BST to Double LinkedList - neverlandly - 博客园



    FG面经Prepare: BST to Double LinkedList - neverlandly - 博客园

    FG面经Prepare: BST to Double LinkedList

    BST to double linkedlist in inorder traversal sequence
    Follow Up: 如果这个BST自带prev, next, 给一个value,插进去这个node,并补全left,right,prev,next

    Read full article from FG面经Prepare: BST to Double LinkedList - neverlandly - 博客园


    Pocket Gem OA: Log Parser - neverlandly - 博客园



    Pocket Gem OA: Log Parser - neverlandly - 博客园

    time a given player spends actually connected to the  network.  We keep console logs of various game subsystems for each play session. Each log message  has the following format:  (MM/dd/yyyy-hh:mm:ss) :: [message logged]  Sample log lines:  (11/12/2015-02:34:56) :: START  (01/02/1990-13:10:00) :: DISCONNECTED  (03/13/2018-21:01:01) :: ERROR - File "close.png" not found.  Log messages that pertain to network connectivity are as follows:  START : Logged when the game starts up.  CONNECTED : Logged when a network connection is established.  DISCONNECTED : Logged when network connection is lost.  SHUTDOWN : Logged when the player is quitting the game.  A player's session length is the amount of time between the START and SHUTDOWN  messages.  A player's connected time is the amount of time they spend in a connected state. A player starts  the game disconnected, becomes connected when we log a CONNECTED message, and  becomes disconnected when we log a DISCONNECTED message.  You can make the following assumptions:  All logs will be properly formatted  All dates will be valid  No log message will stretch across multiple lines  All log files will be ordered chronologically  There will always be exactly one START and exactly one SHUTDOWN event logged  Input  A file containing lines of log messages.  Output  The connectivity percentage as a string, rounded down to an integer.  Examples  (01/01/2000-01:00:00) :: START  (01/01/2000-01:01:00) :: CONNECTED  (01/01/2000-01:21:00) :: DISCONNECTED  (01/01/2000-01:50:00) :: SHUTDOWN  The player spent 20 minutes out of 50 connected, 20 / 50 = 0.4, output should be "40%"  (02/03/2002-14:00:00) :: START  (02/03/2002-14:00:00) :: CONNECTED  (02/03/2002-14:08:00) :: DISCONNECTED  (02/03/2002-14:10:00) :: CONNECTED  (02/03/2002-14:15:00) :: SHUTDOWN  The player spent 13 minutes out of 15 connected, 13 / 15 = 0.8667, output should be "86%"  More sample input can be found in the text files input_1.txt, input_2.txt, and input_3.txt
    复制代码
    复制代码
    有事游戏中有Log用于记录各种状态,想知道究竟用户连接的时间是多少。状态除了START, CONNECTED, DISCONNECTED, SHUTDONW外还有ERROR啥的,但是只需要关注前四个。  输入形式: vector<string> lines  (11/01/2015-04:00:00) :: START  (11/01/2015-04:00:00) :: CONNECTED  (11/01/2015-04:30:00) :: DISCONNECTED  (11/01/2015-04:45:00) :: CONNECTED  (11/01/2015-05:00:00) :: SHUTDOWN

    Read full article from Pocket Gem OA: Log Parser - neverlandly - 博客园


    Pocket Gem OA: Path Finder - neverlandly - 博客园



    Pocket Gem OA: Path Finder - neverlandly - 博客园

    1. 有向图 找所有start node到end node之间的路径 输入是一个txt 形式如下: A E A : B C D. B : C C : E D : B. 输出一个List<String> 是从A到E所有的path

    Read full article from Pocket Gem OA: Path Finder - neverlandly - 博客园


    Word Cloud Data (Practice Interview Question) | Interview Cake



    Word Cloud Data (Practice Interview Question) | Interview Cake

    To do this, you'll need data. Write code that takes a long string and builds its word cloud data in a dictionary

    A hash table (also called a hash, hash map, map, unordered map or dictionary) is a data structure that pairs keys to values.

      light_bulb_to_hours_of_light = {      'incandescent': 1200,      'compact fluorescent': 10000,      'LED': 50000  }  

    Hash tables:

    • take on average O(1)O(1) time for insertions and lookups
    • are unordered (the keys are not guaranteed to stay in the same order)
    • can use many types of objects as keys (commonly strings)

    Hash tables can be thought of as arrays, if you think of array indices as keys!

    In fact, hash tables are built on arrays. So if you ever want to use a hash table but know your keys will be sequential integers (like 1..1001..100), you can probably save time and space by just using an array instead.

    Note: hash tables have an average case insertion and lookup cost of O(1)O(1). In industry, we often confuse the average-case cost with worst case cost, but they're not really the same. Because of hash collisions and rebalancing, a hash table insertion or lookup can cost as much as O(n)O(n) time in the worst case. But usually in industry we assume hashing and resizing algorithms are clever enough that collisions are rare and cheap.

    , where the keys are words and the values are the number of times the words occurred.

    Think about capitalized words. For example, look at these sentences:

      'After beating the eggs, Dana read the next step:'  'Add milk and eggs, then add flour and sugar.'  

    What do we want to do with "After", "Dana", and "add"? In this example, your final dictionary should include one "Add" or "add" with a value of 22. Make reasonable (not necessarily perfect) decisions about cases like "After" and "Dana".


    Read full article from Word Cloud Data (Practice Interview Question) | Interview Cake


    Beautiful subArray | Now to Share



    Beautiful subArray | Now to Share

    Find the distinct subarrays with m odd numbers 

    For example :

    {2,5,4,9} , m=1 --> return 6

    {2,5}  , {5} , {2,5,4}, {5,4}, {4, 9} ,{9}


    Read full article from Beautiful subArray | Now to Share


    Delete Odd | Now to Share



    Delete Odd | Now to Share

    It has 1 parameter, list, areference to a LinkedListNode that is the head of a linked List. You function should remove all nodes from the list having data values that are odd integers, and then reutrn the head of the modified linked list.

     

    For example:

    2 -> 1->3->4->6

    return 

    2->4->6


    Read full article from Delete Odd | Now to Share


    Wolf, sheep, cabbage



    Wolf, sheep, cabbage

    Wolf, sheep, cabbage is a logic puzzle, in which the player (boatman) has to transport a wolf, a sheep and a cabbage from one river bank to the other. In the game the player must obey these rules:

    • The player can use a boat to transport the objects, but he may take at maximum one thing with him every time.
    • If the sheep remains unguarded on the same bank as the cabbage, than the sheep will eat the cabbage.
    • If the wolf remains unguarded on the same bank as the sheep, than the wolf will eat the sheep.

    Read full article from Wolf, sheep, cabbage


    FB面经 Prepare: K closest point to the origin - neverlandly - 博客园



    FB面经 Prepare: K closest point to the origin - neverlandly - 博客园

    Give n points on 2-D plane, find the K closest points to origin


    Read full article from FB面经 Prepare: K closest point to the origin - neverlandly - 博客园


    《Effective Java》学习笔记上 – 技术圈



    《Effective Java》学习笔记上 – 技术圈

    第2章 创建和销毁对象

    第1条:考虑用静态工厂方法代替构造方法

    静态工厂方法与构造方法的不同

    优点:

    • 静态工厂方法有名称。当一个类需要多个带有相同签名的构造器时,就用静态工厂方法代替构造方法,并且慎重选择名称以便突出区别。
    • 不用每次调用它们的时候都创建一个新对象。静态工厂方法能够为重复的调用返回相同的对象,有助于类总能严格控制在某个时刻那些实例不该存在。
    • 可以返回原返回类型的任何子类型的对象。有更大的灵活性;如APi可以返回对象,又同时不会使对象的类变成公有的,适用于基于接口的框架。公有的静态工厂方法返回的对象的类不仅可以是非公有的,而且该类还可以随着每次调用而发生变化,这取决于静态工厂方法的参数值。
    • 在创建参数化类型实例的时候,代码更简洁。

    缺点:

    • 类如果不含有公有的或者受保护的构造器,就不能被子类化。
    • 他们与其他的静态方法实际上没有任何区别。

    第2条:遇到多个构造器参数时要考虑用构造器

    与构造器相比,builder可以有多个可变的参数。builder模式十分灵活,可以利用单个builder构造多个对象。总之,如果类的构造器和静态工厂中具有多个参数,builder模式就是不错的选择,特别是当大多数参数是可选的时候。

    第3条:用私有构造器或者枚举类型强化singleton属性

    第4条:用私有构造器强化不可实例化的能力

    第5条:避免创建不必要的对象

    一般来说,最好能重用对象而不是在每次需要的时候就创建一个相同功能的对象。

    第6条:消除过期的对象引用

    • 清空对象引用应该是一种例外,而不是一种规范行为,消除过期引用最好的方法是让包含该引用的变量结束其生命周期。
    • stack类自己管理内存,只要是类自己管理内存,程序猿就应该警惕内存泄漏问题。
    • 内存泄漏的另一种常见来源是缓存。只要在缓存之外存在对某个项的键的引用,该项就有意义,那么就可以用weakhashmap代表缓存。
    • 内存泄漏的第三个常见来源是监听器和其他回调。确保回调立即被当做垃圾回收的最佳方法是只保存它们的弱引用,例如,只将它们保持成WeakHashMap中的键。

    第7条:避免使用终结方法

    • 终结方法(finalizer)通常是不可预测的,也是很危险的,一般情况下是不必要的。
    • java语言规范不仅不保证终结方法会被及时执行,而且根本不保证它们会被执行。
    • 使用终结方法有一个非常严重的(severe)性能损失
    • 显示的终结方法通常与try-finally结构结合起来使用,以确保及时终止。(显示终止方法的典型例子是InputStream,OutputStream和java.sql.Connection上的close方法,java.util.Timer上的cancel方法等)
    • 总之,除非作为安全网(当对象的所有者忘记调用前面段落中建议的显示终止方法时,终结方法可以充当安全网),或者是为了终止非关键的本地资源,否则请不要使用终结方法。

    第3章 对于所有对象都通用的方法

    第8条:覆盖equals时请遵守通用约定

    • 类的每个实例本质都是唯一的。对于代表活动实体而不是值的类来说确实如此,例如Thread。
    • 不关心类是否提供了"逻辑相等"的测试功能。
    • 超类已经覆盖了equals,从超类继承过来的行为对于子类也是合适的。
    • 类是私有的或是包级私有的,可以确定它的equals方法永远不会被调用。

    在实现equals方法时,必须遵守的通用约定

    • 自反性。对于任何非null的引用值x,x.equals(x)必须返回true。
    • 对称性。对于任何非null的引用值x和y,当且仅当y.equals(x)时,x.equals(y)必须返回true。
    • 传递性。对于任何非null的引用值x,y和z,如果x.equals(y)返回true,并且y.equals(x)也返回true,那么x.equals(z)也必须返回true。
    • 一致性。对于任何非null的引用值x和y,只要equals的比较操作在对象中所用的信息没有被修改,多次调用x.equals(y)就会一致的返回true,或者一致的返回false。
    • 非空性。意思是所有的对象都必须不等于null。

    实现提高质量equals方法的诀窍

    1. 使用==操作符检查"参数是否为这个对象的引用"。
    2. 使用instanceof操作符检查"参数是否为正确的类型"。
    3. 吧参数转换成正确的类型。
    4. 对于该类中的每个"关键(significant)"域,检查参数中的域是否与该对象中对应的域相匹配。
    5. 当编写完成了equals方法之后,应该问自己三个问题:它是是否对称的,传递的,一致的?
    6. 覆盖equals是总要覆盖hashCode。
    7. 不要企图让equals方法过于智能。
    8. 不要将equals声明中的Object对象替换为其他类型。

    第9条 覆盖equals是总要覆盖hashCode

    • 相等的对象必须具有相等的散列码(hash code)
    • 不要试图从散列码计算中出掉一个对象的关键部分来提高性能。

    第10条 始终要覆盖toString

    • 提供好的toString实现可以使类用起来更加舒适。
    • toString方法应该返回对象中包含的所有值得关注的信息。
    • 指定toString返回值的格式也有不足之处:如果这个类已经被广泛使用,一旦指定格式,就必须始终如一地坚持这种格式。
    • 无论是否决定指定格式,都应该在文档中明确地表明你的意图。如果要指定格式,则应该严格地去做。
    • 无论是否指定格式,都为toString返回值中包含的所有信息,提供一种编程式的访问途径。

    第11条 谨慎地覆盖clone

    第12条 考虑实现Comparable接口

    第4章 类和接口

    第13条:是类和成员的可访问性最小化

    • 区别设计良好的模块和设计不好的模块,最重要的因素在于,这个模块对于外部的其他模块而言,是否隐藏其内部数据和其他实现细节。(信息隐藏/封装)
    • 尽可能地使每个类或者成员不被外界访问
      1. 私有的(private)
      2. 包级私有的(package-private/default)
      3. 受保护的(protected)
      4. 公有的(public)
    • 如果方法覆盖了超类中的一个方法,子类中的访问级别就不允许低于超类的访问级别。接口中的所有方法都隐含着公有访问级别。
    • 实例域决不能是公有的,包含公有可变域的类并不是线程安全的。
    • 长度非零的数组总是可变的,所以类具有公有的静态final数组域,或者返回这种域的访问方法,这几乎总是错误的。
    • 总之,应该始终尽可能地降低可访问性。除了公有静态final域的特殊情况之外,公有类都不应该包含公有域。并且要确保公有静态final域所引用的对象都是不可变的。

    第14条:在公有类中使用访问方法而非公有域

    • 如果类可以在它所在的包的外部进行访问,就提供访问方法,以保留将来改变该类的内部表示法的灵活性。
    • 如果类是包级私有的,或者是私有的嵌套类,直接暴露它的数据域并没有本质的错误。
    • 公有类永远都不应该暴露可变域,虽然还是有问题,但是让公有类暴露不可变的域其危害比较小。但是,有时候会需要用包级私有的或者私有的嵌套类来暴露域,无论这个类是可变还是不可变的。

    第15条:使可变性最小化

    不可变类知识其实力不能被修改的类。每个实例中包含的所有信息都必须在创建实例的时候提供,并在对象的整个周期内固定不变。
    1. 不要提供任何会修改对象状态的方法(mutator)
    2. 保证类不会被扩展
    3. 使所有的域都是final的
    4. 使所有的域都成为私有的
    5. 确保对于任何可变组件的互斥访问(如果类具有指向可变的域,则必须确保该类的客户端无法获得指向这些对象的引用)
    – 创建并返回新的实例,而不是修改这个实例。大多数重要的不可变类都使用了这个模式,被称为函数的做法。
    – 不可变对象本质上是线程安全的,它们不要求同步,可以被自由地共享。不仅可以共享不可变对象,甚至也可以共享它们的内部信息,不需要保护性拷贝。缺点:对于每个不同的值都需要一个单独的对象。
    – 总之,坚决不用为每个get方法编写对应的set方法,除非有很好的理由要让类成为可变类,否则应该是不可变的。如果类不能被做成不可变的,仍然应改尽可能地限制它的可变性。

    第16条:复合优先于继承

    • 于方法调用不同,继承打破了封装性。
    • 不用扩展现有的类,而是在新的类中增加一个私有域,它引用现有类的一个实例。(复合/转发)这样得到的类将会非常稳固,它不依赖于现有类的实现细节。
    • 只有当子类真正是超类的子类型时(存在"is-a"关系),才适合用继承。

    第17条:要么为继承设计,并提供文档说明,要么就禁止继承

    第18条:接口优于抽象类

    • 接口和抽象类的区别:抽象类允许包含某些方法的实现,但接口不允许。为了实现有抽象类定义的类型,类必须成为抽象类的一个子类,Java只允许单继承,所以,抽象类作为类型定义受到了极大的限制。
      1. 现有的类可以很容易被更新,以实现新的接口。
      2. 接口的定义mixin(混合类型)的理想选择。(mixin允许任选的功能可被混合到类型的主要功能中)
      3. 接口允许我们构造非层次结构的类型框架。
    • 通过对你导出的每个重要的接口都提供一个抽象的骨架实现(skeletal implementation)类,把接口和抽象类的优点都集合起来。接口的作用仍然是定义类型,但是骨架实现类接管了所有与接口实现相关的工作。
      1. 按照惯例,骨架实现被称为AbstractInterface,这里的interface是指所实现的接口的名字。例如AbstractCollection,AbstractSet,AbstractList和AbstractMap等。
      2. 如果设计得当,骨架实现可以使程序员很容易提供他们自己的接口实现。
      3. 骨架实现为抽象类提供了实现上的帮助,但又不强加"抽象类被用作类型定义时"所特有的严格限制。
      4. 骨架实现类仍然能够有助于接口的实现。(模拟多重继承:实现这个接口的类可以把对于接口方法的调用,转发到一个内部私有类的实例上,这个内部私有类扩展了骨架的实现)
      5. 编写骨架实现类相对比较简单,但是有点单调乏味。
      6. 因为骨架实现类是为继承目的实现的,所以应该遵循第17条中介绍的所有关于设计和文档的指导原则。
      7. 骨架实现上有个小小的不同,就是简单实现(simple implementation),AbstractMap的SimpleEntry就是个例子。
    • 使用抽象类来定义允许多个实现的类型,与使用接口相比有一个明显的优势:抽象类的演变比接口的演变要容易得多。
    • 一般来说,要想在公有接口中增加方法,而不破坏实现这个接口的所有现有的类,这是不可能的。因此,设计公有的接口要非常谨慎,接口一旦被公开发行,并且被广泛实现,在想改变这个接口几乎是不可能的。
    • 总之,接口通常是定义允许多个实现的类型的最佳途径。这条规则有个例外,即但演变的容易性和灵活性和功能更为重要的时候。

    第19条:接口只用于定义类型

    当类实现接口时,接口就充当可以引用这个类的实例的类型。常亮接口模式是对接口的不良使用。简而言之,接口应该只被用来定义类型,它们不应该被用来导出常亮。

    第20条:类层次优于标签类

    • 类标签过于冗长,容易出错,并且效率低下。为了将标签类转变为类层次,首先要为标签类中的每个方法都要定义一个包含抽象方法的抽象类,这每个方法的行为都依赖于标签值。
    • 简而言之,标签类很少有适用的时候,当你想要编写一个包含显示标签域的类时,应该考虑一下,这个标签是否可以被取消,这个类是否可以用类层次来代替,当你遇到一个包含标签域的现有类时,就要考虑将它重构到一个层次结构中去。

    第21条:用函数对象消失策略

    函数指针的主要用途就是实现策略模式。为了在Java中实现这种模式,要声明一个接口来表示该策略,并且为每个具体策略声明一个实现了该接口的类。当一个具体策略只被使用过一次时,通常是使用匿名类来声明和实例化这个具体策略类。当一个具体策略是设计用来重复使用的时候,他的类通常就要被实现为私有的静态成员类,并通过公有的静态final域被导出,其类型为该策略接口。

    第22条:优先考虑静态成员类

    • 嵌套类是指被定义在另一个类的内部的类。嵌套类分为四种:静态成员类,非静态成员类,匿名类和局部类。
    • 如果一个嵌套类需要在单个方法之外仍然是可见的,或者它太长了,不适合于放在方法内部,就应该使用成员类。如果成员类的每个实例都需要一个指向其外围实例的引用,就要把成员类做成非静态的;否则,就做成静态的。架设这个嵌套类属于一个方法的内部,如果你只需要一个地方创建实例,并且已经有一个预置的类型可以说明这个类的特征,就要把它做成匿名类;否则,就做成局部类。


    Read full article from 《Effective Java》学习笔记上 – 技术圈


    Senate rejects repeal of Obama drilling rule | TheHill



    Senate rejects repeal of Obama drilling rule | TheHill

    Just In... — 21m 4s ago By Timothy Cama and Devin Henry - 05/10/17 10:29 AM EDT 8,223   Three Republicans joined Senate Democrats on Wednesday to reject an effort to overturn an Obama administration rule limiting methane emissions from oil and natural gas drilling. Only 49 senators voted to move forward with debate on legislation to undo the Bureau of Land Management (BLM) rule, short of the 51 votes needed.   ADVERTISEMENT Graham and Collins had previously publicized their plans to vote against the legislation. But McCain's vote came as a surprise. McCain said that he voted against the resolution because he fears that it would have prevented the BLM from writing an improved regulation in the future. "While I am concerned that the BLM rule may be onerous, passage of the resolution would have prevented the federal government, under any administration, from issuing a rule that is 'similar,' according to the plain reading of the Congressional Review Act," he said in a statement.

    Read full article from Senate rejects repeal of Obama drilling rule | TheHill


    学渣刷题: 24. Swap Nodes in Pairs



    学渣刷题: 24. Swap Nodes in Pairs

    Given a linked list, swap every two adjacent nodes and return its head.
    For example,
    Given 1->2->3->4, you should return the list as 2->1->4->3.
    Your algorithm should use only constant space. You may not modify the values in the list, only nodes itself can be changed.



    Solution:

    We use a dummy node to avoid a corner case of the first node.

    Go through the linked list, and flip the next node and the next.next node of the current one. And set the current one to its next.next.

    For this kind of problems, we need to be careful that when we process a node, it is not null.

    Read full article from 学渣刷题: 24. Swap Nodes in Pairs


    “The Handmaid’s Tale” is critical to the success of Hulu’s Live TV service | TechCrunch



    "The Handmaid's Tale" is critical to the success of Hulu's Live TV service | TechCrunch

    Part of the popularity of the show comes from the uncanny parallels to today's present-day political situation. Vulture aptly describes the potential similarities between present-day reality and the dystopia depicted in the series:

    Offred says that she is awake to the world now, that she was asleep before. "That's how we let it happen," she thinks. "Nothing changes instantaneously. In a gradually heating bathtub, you'd be boiled to death before you knew it." The change was incremental at first: Their rights were suspended in the interest of national security, in the name of fighting terrorism. They were asked to make sacrifices, perhaps, to give up just a little of their rights and freedoms for the greater good. Once you've made one compromise, what's another? What's one step more?

    This is how they take everything from you: one thing at a time.


    Read full article from "The Handmaid's Tale" is critical to the success of Hulu's Live TV service | TechCrunch


    Sally Yates Destroyed Ted Cruz, Proved That Michael Flynn Is in Deep Trouble



    Sally Yates Destroyed Ted Cruz, Proved That Michael Flynn Is in Deep Trouble

    Whew. May 8, 2017 It is not often that you see one woman demolish a state's entire delegation to the United States Senate, but Sally Yates did the Republic a great service on Monday afternoon by demonstrating that Texas has sent to Washington a remarkable pair of deuces. First, she slapped John Cornyn silly as regards her refusal to enforce the president*'s original travel ban, the issue over which she'd been fired. He pronounced himself disappointed, and she handed him his head. Via The Washington Post : CORNYN: Well, Ms. Yates, you had a distinguished career for 27 years at the Department of Justice and I voted for your confirmation because I believed that you had a distinguished career.

    Read full article from Sally Yates Destroyed Ted Cruz, Proved That Michael Flynn Is in Deep Trouble


    Low pay, high SF housing costs equal 1 homeless math teacher - San Francisco Chronicle



    Low pay, high SF housing costs equal 1 homeless math teacher - San Francisco Chronicle

    May 9, 2017 Updated: May 9, 2017 6:00am Math teacher and badminton coach Etoria Cheeks takes Muni Metro to her temporary home in San Francisco after her workday as a teacher ends. Math teacher and badminton coach Etoria Cheeks takes Muni Metro to... Etoria Cheeks teaches math at a public high school in San Francisco, explaining algebra and statistics to teenagers. But it's the math behind her housing predicament that simply doesn't add up. In a shocking indication of just how bad San Francisco's teacher housing situation is, Cheeks is homeless. She's a professional with a teaching credential and master's degree in one of the richest cities in the world who cannot find housing. She slept on bunk beds in downtown hostels for two months and a homeless shelter for one terrible night before the teachers' union found a retired member willing to let Cheeks sleep in her guest room until she finds her own place. "Technically, I'm still homeless until I have my own lease," Cheeks said.

    Read full article from Low pay, high SF housing costs equal 1 homeless math teacher - San Francisco Chronicle


    Lintcode20 Dices Sum solution 题解 - 简书



    Lintcode20 Dices Sum solution 题解 - 简书

    Throw n dices, the sum of the dices' faces is S. Given n, find the all possible value of S along with its probability.

    Notice:You do not care about the accuracy of the result, we will help you to output results.

    扔 n 个骰子,向上面的数字之和为 S。给定 Given n,请列出所有可能的 S 值及其相应的概率。

    注意:你不用关注答案的准确性,我们会帮你输出答案

    【题目链接】

    http://www.lintcode.com/en/problem/dices-sum/

    【题目解析】

    这题用dfs做感觉更加直观,但是过不了time cost。换成dp的方法我是这么想的:

    用dp[i][j]表示有i + 1个骰子的情况下,掷到的和为j的次数。那么intialize这个dp[0][j], j = 1...6的值都为1,然后从i = 1开始做循环。i个骰子和i + 1个骰子的差别就是1个骰子(废话),所以再用一个k = 1...6进行遍历,那么i + 1个骰子掷到j + k的次数就是原来dp[i][j + k]的次数加上dp[i - 1][j]。

    这样我们就求得了n个骰子的情况下,每个S出现的次数dp[n - 1][j], j = n...6 * n。那么概率就是每个dp[n - 1][j]除以出现的总次数sum(dp[n - 1][j]).

    这里要注意dp的值可能很大,所以要用到long long,否则在有些test case(e.g., n = 15)的情况下,会出现负数答案


    Read full article from Lintcode20 Dices Sum solution 题解 - 简书


    Random Generator · LintCode题解



    Random Generator · LintCode题解

    给一个1到3的random generator,构造一个1到n的random generator。

    +

    Solution

    用3进制数来求解。首先求出n至少需要几位3进制数来表示,假设需要x位。然后利用1到3的random generator来产生依次产生每一位上的随机数(因为3进制每一位上是0到2,所以要将得到的随机数-1)。再将得到的随机数转化为十进制整数。因为x位3进制的数能表示的十进制的数的范围是0~3^x - 1,因此得到的随机数可能比n大。如果得到的结果大于n,则重新产生随机数。

    +

    如果调用这个n random generator很多次,很可能产生很多次重复的随机数。因此,可以将得到的合法3进制的数及其对应的十进制的数保存在一个table里来优化时间。每次产生一个随机数,就和n比较,如果大于n,则重新产生,否则去table寻找其对应的十进制数。如果没有找到,则说明该随机数第一次产生,将该随机数的3进制及其十进制形式保存在table里。


    Read full article from Random Generator · LintCode题解


    Senate GOP has 2018 edge in numbers, struggle for candidates - Business Insider



    Senate GOP has 2018 edge in numbers, struggle for candidates - Business Insider

    × Republicans are struggling to recruit top-tier Senate challengers in states where Trump won Joe Manchin. Zach Gibson/Getty Images DES MOINES, Iowa (AP) — Senate Republicans landed a top-tier candidate in West Virginia but have struggled to recruit well-known GOP challengers in several states where President Donald Trump romped and Democratic incumbents warily face re-election. Two-term Rep. Evan Jenkins on Monday announced his bid against Democratic Sen. Joe Manchin, West Virginia's popular former governor whose conservative record often puts him at odds with his party and made him a possible member of Trump's Cabinet. Jenkins, in a video, said Manchin changed when he got to Washington, spotlighting the senator's unsuccessful effort on gun control with Republican Sen. Pat Toomey of Pennsylvania after the 2012 murders at Sandy Hook school. "West Virginia values, not anymore," Jenkins says in the ad. In Wisconsin, Michigan and other states,

    Read full article from Senate GOP has 2018 edge in numbers, struggle for candidates - Business Insider


    Bill Gates, Warren Buffett on tax reform, ‘Giving Pledge’ [Video]



    Bill Gates, Warren Buffett on tax reform, 'Giving Pledge' [Video]


    Read full article from Bill Gates, Warren Buffett on tax reform, 'Giving Pledge' [Video]


    [LintCode] Subarray Sum & Subarray Sum II - Eason Liu - 博客园



    [LintCode] Subarray Sum & Subarray Sum II - Eason Liu - 博客园

    Given an integer array, find a subarray where the sum of numbers is between two given interval. Your code should return the number of possible answer.

    Example

    Given [1,2,3,4] and interval = [1,3], return 4. The possible answers are:

    [0, 0]  [0, 1]  [1, 1]  [3, 3]

    先求出前缀和,然后枚举求两个前缀和的差。如果差在start与end之间,就给res+1。注意前缀和数组前要插入一个0。


    Read full article from [LintCode] Subarray Sum & Subarray Sum II - Eason Liu - 博客园


    【系统设计】Design Netflix & Design User System & Design Rate Limiter - Road to Glory - SegmentFault



    【系统设计】Design Netflix & Design User System & Design Rate Limiter - Road to Glory - SegmentFault

    Design Rate Limiter

    Requirement

    防止爬虫;例如,Kafka中上层producer产生太快限制其他producer的资源。
    基本限制 QPS limit = 5

    四种算法

    1. 隔离算法 —

    Make sure the gap between two requests >= 1s/5 = 0.2s

    1. 充分满足限制;  2. 但是会误杀很多合理的request,例如0.2 0.4 0.6 0.8 0.9中的0.9         Acquire()  Time now = Time.getCurrentSecond();  if (now - lastReq <= 0.2) return false;  else {      lastReq = now;      return true;  }    

    2. 吊桶算法 — time-bucket

    Acquire()  Time now = Time.getCurrentSecond();  if (counter[now] >= 5) return false;  else {      counter[now]++;      return true;  }      

    Time-bucket with Database: O(1) space

    Acquire()  Time now = Time.getCurrentSecond();  counter = DB.get(now);  if (counter != null && counter >= 5) return false;  else {      DB.increase(s, 1);      DB.expire(s, 1);      return true;  }      

    Time-bucket: one bucket O(1) space

    Acquire()  Time curSecond = Time.getCurrentSecond();  if (curSecond != preSecond) {      counter = 0;      preSecond = curSecond;  }  if (counter >= 5) return false;  else {      counter++;      return true;  }  

    Bad Case: 假设0 - 1s正好5个request,但是0.5s - 1.5s中出现了6个request,bucket无法检测任何一个1s区间内的准确性

    3. Solution: 队列算法 — Algorithm of Request List

    Acquire()  curSecond = getCurrentSecond();  preFifthSecond = requestList.get(requestList.size()-5);  if (curSecond-preFifthSecond < 1) return false; //indicating this is the 6th request in this second  else {      requestList.add(curSecond);      return true;  }      

    还是有问题:如果一秒有很多request,比如说one million, 都要记录在request list吗?
    Nah...
    用一个fixed size(5)的request list + 轮询:只记录最近的5个request

    Acquire()  curSecond = getCurrentSecond();  if (curSecond-requestList.get(index) < 1) return false;  else {      requestList.set(index, curSecond);      index = (index+1)%5;      return true;  }    

    Follow up 1: how to save space with 10^9 queries per hour?

    Batch queries. 损失精度换取空间复杂度。
    对邻近时间的query打包,每个包里有10^6个query,这样,就只需要在request list中存储10^3个query/hr,也就是每3.6秒存储一个。

    Follow up 2: how to support multiple threads?

    Lock.

    Follow up 3: how to support limiter on users?

    <userId, requestList> 每个用户有自己的request list

    Follow up 4: how to support query with different quotas? 不同配额呢

    acquire(quota)

    4. 令牌算法 — Token bucket

    每0.2s产生一个令牌,没有使用的话则累积,供并发请求调用,时间为O(1)


    Read full article from 【系统设计】Design Netflix & Design User System & Design Rate Limiter - Road to Glory - SegmentFault


    Penn State frat's 'grotesque actions' were 'beyond human decency,' Piazza family attorney says - ABC News



    Penn State frat's 'grotesque actions' were 'beyond human decency,' Piazza family attorney says - ABC News

    The attorney for the family of Penn State fraternity pledge Timothy Piazza, who died after falling down stairs during a pledge ceremony at the frat house, called the actions of the fraternity brothers who didn't call for help the "worst possible debauchery and depravity that you could possibly have anywhere, let alone a college campus."

    Piazza, a 19-year-old Penn State sophomore, died on Feb. 4 after he fell down the stairs at Penn State's Beta Theta Pi fraternity the night of Feb. 2. Piazza's blood alcohol content reached 0.28 and 0.36 percent that night. Police were not called to the Beta Theta Pi house -- which has since been barred from Penn State -- until about 12 hours after the initial fall.

    Here are some details from what happened the night of Feb. 2 and early morning hours of Feb. 3 at Beta Theta Pi, according to a grand jury report, which cited evidence including video from surveillance cameras, testimony and phone records.


    Read full article from Penn State frat's 'grotesque actions' were 'beyond human decency,' Piazza family attorney says - ABC News


    Texas governor signs 'sanctuary cities' ban, but law enforcement leaders see problems ahead - LA Times



    Texas governor signs 'sanctuary cities' ban, but law enforcement leaders see problems ahead - LA Times

    LA 90: Texas' SB4 passes Texas passed a bill to ban sanctuary cities. (May 5, 2017) (Sign up for our free video newsletter here http://bit.ly/2n6VKPR ) Texas passed a bill to ban sanctuary cities. (May 5, 2017) (Sign up for our free video newsletter here http://bit.ly/2n6VKPR ) Jenny Jarvie Law enforcement officials across Texas on Monday moved to revise policies after Gov. Greg Abbott signed a "sanctuary cities" ban that allows police to ask about immigration status during routine stops and threatens authorities with jail if they do not cooperate with federal agents. San Antonio Police Chief William McManus said Monday his department would remove a policy that prohibits his nearly 2,400 officers from asking about a person's immigration status. But he warned that the new law, effective in September, could endanger public safety by discouraging immigrants from reporting crimes and interacting with law enforcement officers. "We don't want people to fly under the radar,

    Read full article from Texas governor signs 'sanctuary cities' ban, but law enforcement leaders see problems ahead - LA Times


    LintCode-Maximum Subarray III - LiBlog - 博客园



    LintCode-Maximum Subarray III - LiBlog - 博客园

    LintCode-Maximum Subarray III

    Given an array of integers and a number k, find k non-overlapping subarrays which have the largest sum.

    The number in each subarray should be contiguous.

    Return the largest sum.

    Note

    The subarray should contain at least one number

    Analysis:

    DP. d[i][j] means the maximum sum we can get by selecting j subarrays from the first i elements.

    d[i][j] = max{d[p][j-1]+maxSubArray(p+1,i)}

    we iterate p from i-1 to j-1, so we can record the max subarray we get at current p, this value can be used to calculate the max subarray from p-1 to i when p becomes p-1.


    Read full article from LintCode-Maximum Subarray III - LiBlog - 博客园


    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