2019年10月12日 星期六

[Leetcode] 1170. Compare Strings by Frequency of the Smallest Character

1. Pre-calculated on words.

2. Counting sort and built-in quick-sort (need to know the average/worst time complexity of quick sort.)

3. Binary search of time complexity O(log(n)). Stick on single implementation.
  • left-closed and right-open interval. Same as for loop.
  • < in while loop.
  • mid = lower + (upper - lower) / 2 to avoid overflow.
  • return lower.
You can develop other various implementations based on this one.



Source code:

class Solution {
    public int[] numSmallerByFrequency(String[] queries, String[] words) {
        int[] sorted = new int[words.length];
        for (int i = 0; i < words.length; i++) {
            sorted[i] = calculate(words[i]);
        }
        Arrays.sort(sorted);

        int[] nums = new int[queries.length];
        for (int i = 0; i < queries.length; i++) {
            int target = calculate(queries[i]);
            int lower = 0;
            int upper = words.length;
            while (lower < upper) {
                int mid = lower + (upper - lower) / 2;
                if (sorted[mid] <= target) {
                    lower = mid + 1;
                } else {
                    upper = mid;
                }
            }
            nums[i] = words.length - lower;
        }
        return nums;
    }
    
    private int calculate(String word) {
        int[] counting = new int[26];
        for (char c : word.toCharArray()) {
            counting[c - 'a']++;
        }
        for (int i = 0; i < 26; i++) {
            if (counting[i] > 0) {
                return counting[i];
            }
        }
        return 0;
    }
}

2019年4月24日 星期三

Notes on Google interview

Recommended video: How to: Work at Google — Example Coding/Engineering Interview [link].

How Google hire: https://careers.google.com/how-we-hire/
  • Apply
    • Show your resume in LinkedIn. (Excellent suggestion from my ex-director.)
    • Internal referral.
  • Interview
    • 到龍山寺拜文昌帝君
    • Practice LeetCode problems systematically.
    • Try to get any feedback after any interview. It will make you better and better.
  • Decide
    • 文昌帝君會托夢給 hiring committee. 

2019年3月14日 星期四

2019年3月13日 星期三

[Books] Programming Pearls (2nd Edition)


Bought a Chinese translation of Programming Pearls (2nd Edition).



Super recommend to read!



Quote from this book:

Q: It seems that most columns emphasize the design process. Can you summarize your advice on that topic?
  • Work on the right problem.
  • Explore the design space of solutions.
  • Look at the data.
  • Use the back of the envelope.
  • Exploit symmetry.
  • Design with components.
  • Build prototypes.
  • Make tradeoffs when you have to.
  • Keep it simple.
  • Strive for elegance.

Also check this for designing machine learning systems: Hidden Technical Debt in Machine Learning Systems [paper]. 

2019年3月4日 星期一

Notes on System Design

Warning: All materials are prepared for Facebook onsite interview but I failed.


Case Study:
  • Netflix (mysterious)
    • Learning a Personalized Homepage – Netflix TechBlog – Medium (2015): Article
    • The Netflix Recommender System: Algorithms, Business Value, and Innovation (2016): Paper
    • Benchmarking Cassandra Scalability on AWS — Over a million writes per second (2011): Article
    • A Multi-Armed Bandit Framework for Recommendations at Netflix | DataEngConf SF '18 (2018): YouTube
  • Google
    • Building Software Systems at Google and Lessons Learned (2010): Slide | YouTube
    • Google Production Environment (2018): YouTube
    • The Google File System - Research (2003): Paper
    • MapReduce: Simplified Data Processing on Large Clusters (2004): Paper
    • Bigtable: A Distributed Storage System for Structured Data (2006): Paper
    • Differential Synchronization (2009): Paper | YouTube
    • The Paxos Algorithm (2018): YouTube
  • Yahoo
    • The Hadoop Distributed File System (2010): Paper
    • Analyzing Google File System and Hadoop Distributed File System (2016): Article 
  • Youtube
    • Deep Neural Networks for YouTube Recommendations (2016): Paper
    • RecSys 2016: Paper Session 6 - Deep Neural Networks for YouTube Recommendations (2016): YouTube
  • Facebook
    • Balancing Multi-Tenancy and Isolation at 4 Billion QPS (2015): YouTube
    • TAO: Facebook's Distributed Data Store for the Social Graph - Usenix (2013): Paper
    • Finding a needle in Haystack: Facebook's photo storage - Usenix (2010): Paper
    • Cassandra - A Decentralized Structured Storage System (2009): Paper
  • Instagram
    • Scaling Instagram (QCon London 2017): YouTube
  • Amazon
    • Dynamo: Amazon's Highly Available Key-value Store (2007): Paper
  • Slack
    • How Slack Works (QCon San Francisco 2016): YouTube
  • Uber
    • Project Mezzanine: The Great Migration (2015): Article
    • Designing Schemaless, Uber Engineering’s Scalable Datastore Using MySQL (2016): Article Part 1 & Part2 & Part3
    • The Uber Engineering Tech Stack, Part I: The Foundation (2016): Article
    • The Uber Engineering Tech Stack, Part II: The Edge and Beyond (2016): Article
    • How Uber Scales Their Real-Time Market Platform (2015): Article


Interview Practices:
  • URL shortener system design | tinyurl system design | bitly system design (2018): YouTube
  • NETFLIX System design | software architecture for netflix (2018): YouTube
  • UBER System design | OLA system design | uber architecture | amazon interview question (2018): YouTube
  • Twitter system design | twitter Software architecture | twitter interview questions (2018): YouTube
  • Whatsapp System design or software architecture (2018): YouTube