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

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

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

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

Related:
http://lifelongprogrammer.blogspot.com/2009/01/lesson-learned-from-investing.html

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 (== N-1 || ca[i] != ca[i+1]) {//\\ 
        sb.append(ca[i]);
        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.


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
- Asking a question should not modify the answer
- Separating methods into queries and commands

SOLID
- Liskov Substitution Principle

Resources

Labels

adsense (5) Algorithm (69) Algorithm Series (35) Android (7) ANT (6) bat (8) Big Data (7) Blogger (14) Bugs (6) Cache (5) Chrome (19) Code Example (29) Code Quality (7) Coding Skills (5) Database (7) Debug (16) Design (5) Dev Tips (63) Eclipse (32) Git (5) Google (33) Guava (7) How to (9) Http Client (8) IDE (7) Interview (88) J2EE (13) J2SE (49) Java (186) JavaScript (27) JSON (7) Learning code (9) Lesson Learned (6) Linux (26) Lucene-Solr (112) Mac (10) Maven (8) Network (9) Nutch2 (18) Performance (9) PowerShell (11) Problem Solving (11) Programmer Skills (6) regex (5) Scala (6) Security (9) Soft Skills (38) Spring (22) System Design (11) Testing (7) Text Mining (14) Tips (17) Tools (24) Troubleshooting (29) UIMA (9) Web Development (19) Windows (21) xml (5)