Read it Before Code (Algorithm) Interview

Ask how many questions the will ask

Clarify the questions

  • Take time to draw some examples to understand the question
    • all different cases, extreme cases
  • Ask the range of input
  • Duplicate in the data
  • Whether I can change/reuse the input
  • Ask whether I have used all useful info, whether I missed anything

When Write code

  • Extract some functions aggressively
    • Otherwise you may repeat a lot of code
    • Focus the main part first, define what parameters it needs
    • Leave the implementation later, interviewer may just ignore it
  • Add To-Check tag where the code may be trick or error prone
    • < or <=, len or len-1;
  • What states, variables we need
  • How do we change them
  • Leave some spaces (where you think you may need add some code later, and if the white board is big)

Recheck the code carefully

  • First focus on the main logic, error-prone part
  • Also check all code
  • Use different (simple) use cases to find the problem in the code/algorithm

Compare different approaches

  • Always think whether there are better approaches (and say it)
  • The different approaches may be easier to code or have better runtime (or space) complexity
  • When you think you can implement it different ways or have different approaches, make sure it works and you choose the one that’s easier to implement
    • Sometimes, the other approach may be not work


  • Le the interviewer your thinking process, different approaches you are trying

What data structures to use:

  • Stack
  • PriorityQueue
    • Examples: LeetCode 767 - Reorganize String
    MultiChar mc1 = pq.poll(), mc2 = pq.poll();
    if (--mc1.count > 0) pq.add(mc1);
    if (--mc2.count > 0) pq.add(mc2);
  • TreeMap, TreeSet\
    • Use it when need keep some order
    • Need (binary) search the key
    • Examples: Interval
  • TreeMap, sort by start or end

Questions to Ask in an interview

New Hire
How can a new hire fit into the team and contribute quickly?

Internal projects/libraries
How an engineer can learn and use the internal libraries quickly?
Whether there are good documentations?\
  • internal stackoverflow?
  • chat group (slack or hipchat?)
  • or directly send email
Where we can find useful resources/documentation?

For some tasks, we can implement using internal libraries or open source libraries, which one we should use, who makes the decision?
How we can know the common/popular internal projects, is there a list?

How can we ask questions except email or chat, direct talk?
internal stackoverflow?

How related teams work together?
Do they sit close to each other or do they meet often?
How we can know other engineers and learn from them?
How we can learn from other engineers that are not in same team?
  • conference, video of the conference

Interest Group

Development/Delivery Speed
  • How frequently we develop new features?
  • How frequently we deploy them to production?
How do we deploy to production?
  • canary deployment?
Do developers have to stay online and monster during deployment?
How do we rollback if the feature doesn’t work in production?
Is this done automatically?

Is there any QA team responsible for end-to-end integration test?

  • What tools do we use for code management, pr and deployment?
  • What steps we need before we deploy the code to production?

How do we guarantee code quality and the feature?
What tools, what process we use?
  • do we use static analysis tool, is it mandatory?
  • Do we have minimum code coverage?
  • What CI framework do we use?
How we test different versions?
Whether the test covers different versions?

Can we send PR to other teams?
Code review
  • Who?

What technologies?
What features we have done?
Ask deeper, know more

Future, ultimate goal
The present
The interviewer also wants you to know more about the team and you really like the team’s work
How to know whether the team is a good fit or not
Know more about you
  • your interest, strength
Do more search about the job
Be more careful when jump to a different domain, you may like it or don’t

Team match
How much info we can know about the team: code repos, Technologies, plan for the future, team members…
How can we know different teams, how can we know whether the team is a good fit or not.

How to Save Money

Avoid Bank Fee

  • Less checking/saving accounts
  • Share checking/saving account with you spouse
    • Don’t transfer money between different checking account unnecessarily, use the same account to pay all the bills
  • Avoid insufficient funds fee
  • Always leave more money in the account
  • Check your account regularly before 7pm, so if it’s less than 0, so maybe you can transfer money from another account
  • Avoid returned item fee for an unpaid
  • 11:59 PM ET (8:59 PDT) is the bank deadline for a day to transfer money
  • Transferring money or pay credit card during weekend is a trick, try to avoid it

Credit Card

  • Always automatically pay full amount
  • APR is very high - usually more than 15%
    • For the money you have not paid in full, you will have to pay the interest for the whole billing period even only one day late.
    • You may request reverse the interest charge
If money is tight:
  • Pay minimum in advance which can avoid the late fee
Cancel auto pay temporarily
  • Otherwise bank will charge you “returned item fee for an unpaid” - $34.

  • Pay as much as you can, as early as you can Utilize 0% APR in limited time for new credit card

  • You can only schedule one payment to credit card each day, but you can cancel the existing one and create a new one.

Walmart credit card
  • It does have online chat, just ignore the virtual assistant: can I talk with a person?
Costco Citi
  • Only have grace period if paid full in last 2 Billing Periods. (sucks)
Cash Reward Credit Card
  • 2% cash back:
    • Paypal credit card Citi Double Cash Card (hard to get approved)
  • 5% rotating cash return
    • Chase freedom
    • Use all 5% cash back


  • Return not-really-needed things
  • Use google search, but also check store deals
  • Target deals sometimes: 10 off over 50 or 25 off over 100


  • Cancel unused service early
  • Buy less, buy things needed in near future
  • Do more (re)search before buying
    • Make sure it’s worth, useful
  • Surprise
    • Money may arrive earlier, or …
    • So if you did something recently, check it before 8:59 PDT
  • Make careful/deliberate decision when related with money
    • ce: fusion


Prepare tax as early as possible

  • So you know how much you owe Leave enough more for the tax
  • Be very careful to put the money in stock at this time Put max in 401k Withhold enough each paycheck
  • to avoid penalty if your withhold is lesser than 90%. Prefer Long Term Stock
  • much lower tax 15%, compared with income tax which may be 30% or higher Paying tax with credit card if absolutely needed
  • It can accept 2 payments per year, so use the service that charges you less to pay as much as you.
  • You can only make 2 payments within 24 hours when using irs direct pay. State tax charges much more for credit card
  • So try to pay state tax with direct pay. Check more at Lesson Learned from Investing


Life Dos and Don'ts for 2009

Life Dos and Don'ts for 2009

      Life Dos and Don'ts for 2009:

  • English is important for career success, practice and speak English everyday.

  • Be brave, don't fear. Do not be afraid to show yourself and stand out.

  • Don't waste your time, do useful things.

  • Improve communication skills.

  • Be active, do more, and learn more.

  • Respond quickly, take action and responsibility.

  • Never give up, and believe yourself, you can do it much better.

  • Observe others and learn from them.

  • Develop good habits, abandon bad habits.

  • Make weekly plan and to-do-list, and follow it strictly.

Subversion and CVS Checkout Error due to case insensitive in Windows

Subversion and CVS Checkout Error due to case insensitive in Windows

Due to some misunderstanding, on Ubuntu, one guy adds two files named and to our project's SVN repository.
later I check out this project to windows, it reports the following error:

Error: In directory '%path%'
Error: Can't open file
Error: '%path%\.svn\text-base\':

This problem is because windows file system is case-insensitive.
And I use command 'svn rename' to rename one file of the two, and this problem resolved.

The same problem occurs for CVS. and because CVS can not remove directories from the repository, if two directories differ only in capitalisation,

In one project, because of wrong operation, there are two same directories which differ only in capitalisation are committed to CVS repository(It seems that somebody checked out the project to windows, and later re-factored the java package from upper case to lower case).
To avoid possible future issue, I need remove the redundant directory. and because CVS can not remove directories from the repository, we have to go to the repository dir, that is /var/lib/cvsroot in our project, and to /var/lib/cvsroot/project/, and delete one directory of the two.

Code Snippet for Interview

Prefer concise code

  • less code, faster to write,
  • reduce the chance to make mistake

Array to set
count.put(word, count.getOrDefault(word, 0) + 1);
Map<String, Long> counted =
  .collect(Collectors.groupingBy(Function.identity(), Collectors.counting()));
Map<Character, Long>  astring.chars().mapToObj(ch -> (char) ch)
  .collect(Collectors.groupingBy(Function.identity(), Collectors.counting()));

char[] to Stream

Stream<Character> stream = CharBuffer.wrap(list).chars().mapToObj(ch -> (char)ch);
Stream.of(int1, int2, ...).min(Integer::compare).get();



for (int i = 0; i < N; ++i) {
    if (== N-1 || ca[i] != ca[i+1]) {//\\ 
        counts.add(- prev);
        prev = i;

Be a Lazy Programmer -- Windows Script

Be a Lazy Programmer -- Windows Script

As a lazy programmer, I want to automate our daily affairs as much as possible.

Task One:

Every morning, when I get to the office, I have to first start some programs, and exit these programs and hibernate my laptop when I get off work.

It is boring. So today I write two very simple scripts to automate these operation, to automate start and exit these processes.


@echo off
echo Begin the day's work
start "" "C:\Program Files\Namoroka 3.6 Alpha 1\firefox.exe"
start ""  C:\notes\notes.exe
tasklist /FI "IMAGENAME eq sametime.exe" | find /I /N "sametime.exe" >NUL
if "%ERRORLEVEL%" neq "0" (echo "sametime is not running";
start ""  "C:\Program Files\IBM\Sametime Connect\sametime.exe") else (echo "sametime is already running")


@echo off

echo end of the day's work

taskkill /F /fi "ImageName eq notes.exe"

taskkill /F /fi "ImageName eq sametime75.exe"

rem command to shut down other programmes

taskkill /F /fi "ImageName eq firefox.exe"

Programming Principles

KISS (Keep It Simple Stupid)
Do The Simplest Thing That Could Possibly Work
Separation of Concerns
Keep Things DRY
Code For The Maintainer
Avoid Premature Optimization
Boy-Scout Rule
- Leave the campground cleaner than you found it

Minimise Coupling
Composition Over Inheritance
Robustness Principle
Be conservative in what you do, be liberal in what you accept from others
Inversion of Control
- Don’t call us, we’ll call you

Maximise Cohesion
Liskov Substitution Principle
Open/Closed Principle

Single Responsibility Principle
- A class should never have more than one reason to change.

Hide Implementation Details
Curly’s Law
Encapsulate What Changes

Interface Segregation Principle
- Reduce fat interfaces into multiple smaller and more specific client specific interfaces.

Command Query Separation
- Asking a question should not modify the answer
- Separating methods into queries and commands

- Liskov Substitution Principle



Java (162) Lucene-Solr (112) Interview (63) J2SE (53) Algorithm (45) Soft Skills (39) Eclipse (32) Code Example (31) Troubleshooting (27) JavaScript (23) Linux (22) Spring (22) Tools (22) Windows (22) Web Development (20) Nutch2 (18) Bugs (17) Dev Tips (17) Debug (16) Defects (14) Text Mining (14) J2EE (13) Network (13) PowerShell (11) Chrome (10) Problem Solving (10) Google (9) How to (9) Learning code (9) Performance (9) Security (9) UIMA (9) html (9) Design (8) Http Client (8) Maven (8) bat (8) blogger (8) Big Data (7) Database (7) Guava (7) JSON (7) Shell (7) System Design (7) ANT (6) Coding Skills (6) Lesson Learned (6) Programmer Skills (6) Scala (6) css (6) Algorithm Series (5) Cache (5) Continuous Integration (5) IDE (5) Testing (5) adsense (5) xml (5) AIX (4) Become a Better You (4) Code Quality (4) Concurrency (4) GAE (4) Git (4) Good Programming Practices (4) Jackson (4) Life (4) Memory Usage (4) Miscs (4) OpenNLP (4) Project Managment (4) Review (4) Spark (4) ads (4) regular-expression (4) Android (3) Apache Spark (3) Distributed (3) Dynamic Languages (3) Eclipse RCP (3) English (3) Happy Hacking (3) IBM (3) J2SE Knowledge Series (3) JAX-RS (3) Jetty (3) Mac (3) Python (3) Restful Web Service (3) Script (3) regex (3) seo (3) .Net (2) Android Studio (2) Apache (2) Apache Procrun (2) Architecture (2) Batch (2) Bit Operation (2) Build (2) Building Scalable Web Sites (2) C# (2) C/C++ (2) CSV (2) Career (2) Cassandra (2) Fiddler (2) Google Drive (2) Gson (2) How to Interview (2) Html Parser (2) Http (2) Image Tools (2) JQuery (2) Jersey (2) LDAP (2) Logging (2) Software Issues (2) Storage (2) Text Search (2) xml parser (2) AOP (1) Application Design (1) AspectJ (1) Chrome DevTools (1) Cloud (1) Codility (1) Data Mining (1) Data Structure (1) ExceptionUtils (1) Exif (1) Feature Request (1) FindBugs (1) Firefox (1) Greasemonkey (1) HTML5 (1) Httpd (1) I18N (1) IBM Java Thread Dump Analyzer (1) Invest (1) JDK Source Code (1) JDK8 (1) JMX (1) Lazy Developer (1) Machine Learning (1) Mobile (1) My Plan for 2010 (1) Netbeans (1) Notes (1) Operating System (1) Perl (1) Problems (1) Product Architecture (1) Programming Life (1) Quality (1) Redhat (1) Redis (1) RxJava (1) Solutions logs (1) Team Management (1) Thread Dump Analyzer (1) Tips (1) Visualization (1) boilerpipe (1) htm (1) ongoing (1) procrun (1) rss (1)

Popular Posts