Interview Questions | Learn for Master - Part 5
  • Leetcode Expression Add Operators (Java)

    Given a string that contains only digits 0-9 and a target value, return all possibilities to add binary operators (not unary) +, -, or *between the digits so they evaluate to the target value.



    This problem can be solved using DFS algorithm. For example, given the input “123456“, suppose we encounter the last digit “6”, at which we already have the result of solve(“12345“). Then there are three cases:

    solve(“123456”) = solve(“12345”) + 6

    solve(“123456”) = solve(“12345”) – 6

    solve(“123456”) = cal( solve(“12345”) ,

    [Read More...]
  • Random ID Generator

    Random ID Generator


    Let’s continue our system design interview questions discussion. If you are new to this series, you can check our previous posts. Basically, each week we are going to pick several interesting interview questions and provide in-depth analysis.

    It’s worth to note that the post is not about giving you something like a standard answer. Instead, we focus more on analyzing the problem and how to come up with reasonable approaches. This is even more true for system design interviews because the question can be extremely open-ended.

    [Read More...]
  • Design a Cache System

    Design a Cache System


    Similar to our previous posts, we would like to select system design interview questions that are popular and practical so that not only can you get ideas about how to analyze problems in an interview, but learn something interesting at the same time.

    If you have no idea about system design interviews, I’d recommend you read this tutorial first. In this post, we are addressing the problem – how to design a cache system. Topics covered by this post include:

    • LRU cache
    • Eviction policy,
    [Read More...]
  • Design Facebook Chat Function

    Design Facebook Chat Function

    One of the most interesting parts of preparing system design interview is that you can get to know a lot of details about how existing systems are built.

    To make the weekly post more helpful, I’d like to cover a wide range of topics. We’ve been talking about stuff like recommendation, ranking a lot in the past few weeks, this time I want to cover something different.


    It starts with a very simple question – how to design Facebook chat function?

    With great news like Facebook buys Whatsapp for $19B and Facebook messenger gets really popular recently,

    [Read More...]
  • Design News Feed System


    Design News Feed System (Part 1)


    If you have followed our previous posts on system design interview questions, you might be surprised at how common news feed system is.

    No matter whether you are building Twitter, Instagram or Facebook, you will need some sort of news feed systems to display updates from follows/friends.

    In fact, there are a bunch of interesting details about news feed like how to rank feeds, how to optimize publishing etc.. So in this post, I’ll cover this popular question – design news feed system.

    [Read More...]
  • How to Design Twitter

    How to Design Twitter (Part 1)


    From last week’s survey, most of our subscribers want to know more about system design interview.

    It’s hard to provide tips without any example, that’s why in this post I’ll use a very popular system design question to show you how to solve it.

    It’s also worth to note that system design interview question can be extremely open-ended, thus there’s no such thing as a standard answer. Even for the same question, you’ll have a totally different discussion with different interviewers for sure.

    [Read More...]
  • System Design Interview Questions


    System Design Interview Questions


    Design a Garbage Collection System (Part I)

    Our system design interview series gets a lot of feedback in the past couple of months. I’m glad to know that our readers find it helpful.

    One advice I always give is that don’t take these articles as standard answers. System design interview questions are usually open-ended and it’s all about analysis and communication. Any point in the discussion can go deeper based on interviewers’ preferences.

    This week, the question is slightly different as it’s a little low-level but at the same times quite useful – garbage collection system.

    [Read More...]
  • Leetcode Symmetric Tree

    Given a binary tree, check whether it is a mirror of itself (ie, symmetric around its center).

    For example, this binary tree [1,2,2,3,4,4,3] is symmetric:

    But the following [1,2,2,null,3,null,3] is not:

    Bonus points if you could solve it both recursively and iteratively.

    This problem can be easily solved using a recursive algorithm.  We defined a method with the following signature:
    equal(left, right)

    then we recursively call equal(left.left, right.right) and equal(left.right, right.left). 

    The method returns false as long as only one of the two nodes is null,

    [Read More...]
  • Leetcode Remove Linked List Elements

    Remove all elements from a linked list of integers that have value val.

    Given: 1 –> 2 –> 6 –> 3 –> 4 –> 5 –> 6, val = 6
    Return: 1 –> 2 –> 3 –> 4 –> 5


    To solve this problem, we keep two pointers pre and cur when scanning the LinkedList. Once the current node’s value equals to the target value, we remove the cur node by set =;

    To make the implementation easier,

    [Read More...]
  • Leetcode Intersection of Two Arrays

    Intersection of Two unsorted Arrays

    Given two arrays, write a function to compute their intersection.

    Given nums1 = [1, 2, 2, 1], nums2 = [2, 2], return [2].


    • Each element in the result must be unique.
    • The result can be in any order.


    Since the two arrays are unsorted, we can use HashSet to solve the problem easily.

    We can also solve the problem by first sorting the two arrays, and using the algorithm of finding intersection of two sorted arrays

    [Read More...]
Page 5 of 11« First...34567...10...Last »