Category Archives: algorithm

@JsonIgnoreProperties

@JsonIgnoreProperties is used in jackson deserialization. When a json file is deserialized to a class, it is ok that field is missing. For example, we have class A: @Data @Builder @NoArgsConstructor @AllArgsConstructor public class A { @JsonProperty int a; @JsonProperty int b; }   It is ok to deserialize {“a”:1}, which misses field b. But it… Read More »

lc 654 Maximum Binary Tree

We are given the root node of a maximum tree: a tree where every node has a value greater than any other value in its subtree. Just as in the previous problem, the given tree was constructed from an list A (root = Construct(A)) recursively with the following Construct(A) routine: If A is empty, return null. Otherwise, let A[i] be the largest element of A.  Create a root node with value A[i]. The left… Read More »

Local/Instance/Class variable

Local variable, variable defined inside method, constructor or block. Instance variable, a variable inside class. It can be instantiated. Class variable, inside class, but outside method. Must be static. Only one copy per class. public class MyTest { static String str = “abcd”; // classs variable, only one copy private String a = “123”; //… Read More »

Vector Clock better than Lamport Clock

Lamport clock. Algorithms: ts = max(local stamp, msg timestamp) + 1. Problem, “So Lamport Clocks are great for making sure we know when there’s a causal dependency between records. But there is a problem. Because Lamport Clocks induce a total ordering over all records, they actually imply more dependencies than truly exist. If two records… Read More »

synchronized and synchronized static

Below are 2 code snippets. doSomething() in first one is synchronized. doSomething() in second one is synchronized static. For synchronized: When calling doSomething() within 2 different instances at the same time, it can be concurrent. When calling doSomething() within same instance at the same tim, it can’t be concurrent. For synchronized static: When calling doSomething()… Read More »

Performance Test

When talking about the performance of a web service, it is intended to think about 2 metrics. 1. TPS 2. Latency 3. TP50, TP90, TP99 etc. single thread test for base line. One thread tests for a period of time. This tests the ideal response latency. Find the peak TPS Test the web service TPS… Read More »

TLS, HTTPS

SSL/TLS are the protocols that aim to provide privacy and data integrity between two parties. HTTPS is HTTP protocols over SSL or TLS protocols. It requires the SSL/TLS establish first, then HTTP is exchanged over SSL/TLS protocols. In TLS, Certificate contains the public key that server sends out. Publish key will be used to encrypt… Read More »

Jump Game II

Given an array of non-negative integers, you are initially positioned at the first index of the array. Each element in the array represents your maximum jump length at that position. Your goal is to reach the last index in the minimum number of jumps. For example: Given array A = [2,3,1,1,4] The minimum number of… Read More »

First Missing Number

leetcode 41. Given an unsorted integer array, find the first missing positive integer. For example, Given [1,2,0] return 3, and [3,4,-1,1] return 2. Your algorithm should run in O(n) time and uses constant space. Solution. I learned the solution from here. The idea is try as much as possible to rearrange array like [1, 2,… Read More »

Sudoku

I came across the sudoku problem in leetcode 37. Here I wrote a page javascript version to solve this problem. Check my code on github.