### Read it Before Code (Algorithm) Interview

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

#### Communication

• 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();

• TreeMap, TreeSet\
• Use it when need keep some order
• Need (binary) search the key
• Examples: Interval
##### 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
Documentation/Resources
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?

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

Social
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?

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

Code
• 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?

Team
What technologies?
What features we have done?

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

#### Shopping

• 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

#### Misc

• Cancel unused service early
• 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

#### Tax

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:

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

• 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

Due to some misunderstanding, on Ubuntu, one guy adds two files named utils.py and Utils.py 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\Utils.py.svn-base':

This problem is because windows file system is case-insensitive.
And I use command 'svn rename utils.py CopyResourceUtils.py' 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

Arrays.stream(wrapperArray).collect(Collectors.toSet())
Arrays.stream(primitiveArray).boxed().collect(Collectors.toSet())

count.put(word, count.getOrDefault(word, 0) + 1);

Map<String, Long> counted = list.stream()
.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();


Character.isLetter/isWhitespace

Arrays.toString(array)

https://leetcode.com/problems/expressive-words/solution/

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


### Be a Lazy Programmer -- Windows Script

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

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.

StartWork.bat

@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")

OffWork.bat

@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

Generic
KISS (Keep It Simple Stupid)
YAGNI
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

Inter-Module/Class
Minimise Coupling
Composition Over Inheritance
Orthogonality
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

Module/Class
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