Algorithm LC 716, 155: Stack design's variant 1. Min Stack Use 2 stacks: - s: to store value of designing stack - m: to store maximum value so far e.g: s = 4, 2, 3, 1, 9, 0 m = 4,

Algorithm A note on Detecting cycle - Floyd algorithm Problem Detect the cycle in a Linked list, return the starting Node of the cycle if any, otherwise return NULL. E.g: return Node 2 in following linked list: Algorithm Let fast and

Algorithm Graph Algorithms for Coding Interview Apart from the well-known BFS and DFS algorithms, I find the following algorithms useful for Coding Interview.Topology sort & circle check Given directed graph, sort the nodes in graph so that, if

Algorithm A note on an interesting technique: Range addition Assume you have an array of length n initialized with all 0's and are given k update operations. Each operation is represented as a triplet: [startIndex, endIndex, inc] which increments each element of

Algorithm LC 683: K Empty Slots https://leetcode.com/problems/k-empty-slots/Solution We can come up with a naive solution: let a is array store the state of bulks, a[i] = 1/0 ie bulk i is on/off

Algorithm LC 855: Exam Room https://leetcode.com/problems/exam-room/Solution For each new student, there are 3 cases: seat at 0: distance = distance to first seated student seat at n-1: distance = distance to last seated student seat

Algorithm LC 9: Palindrome Number https://leetcode.com/problems/palindrome-number/Solution The easiest way is to convert n to string s, and compare s to the reverse(s) bool isPalindrome(int x) { string s = to_string(s); string

Algorithm LC 5: Longest Palindromic Substring https://leetcode.com/problems/longest-palindromic-substring/Solution Dynamic programming: bool fx[i][j] = true if s[i..j] is palindromic else false fx[i][i] = true fx[i][i+1] = (s[i] == s[i+

Algorithm LC 3: Longest Substring Without Repeating Characters https://leetcode.com/problems/longest-substring-without-repeating-characters/Solution 2 pointers - snake technique int lengthOfLongestSubstring(string s) { int n = s.size(); if (n == 0) return 0; int res = 1; map<char, int> count;

Algorithm LC 206: Reverse Linked List https://leetcode.com/problems/reverse-linked-list/Solution Let prev and cur be 2 continuous items of the list: prev -> cur We cannot just assign cur->next = prev, because we will lose

Algorithm LC 445: Add Two Numbers II https://leetcode.com/problems/add-two-numbers-ii/Different from LC 2, in this problem, the most significant digit comes first in the list. One easy solution is to reverse 2 lists and apply the algorithm

Algorithm LC 2: Add Two Numbers https://leetcode.com/problems/add-two-numbers/Solution As the head of list is the last digit of the number, we can add 2 lists by iterating from heads of 2 lists. The only thing

Algorithm LC 1: Two Sum https://leetcode.com/problems/two-sum/Solution For each item i in the given array, we need to know whether there is an item j (j < i) such that a[i] + a[j]

A note on problem's series in LeetCode In this note, I category problems in LeetCode into groups that can be solved by one common technique/ algorithm. By technique and algorithm, I mean a specific and particular method, not a common

Algorithm A note on a technique of Two Pointers algorithm The pattern of question can be solved by Two Pointers algorithms is Return the length of the longest contiguous subarray [u,v] of array A that [u,v] meets the requirement X. With

DevOps Spring Boot app CI/CD on GCP Compute Engine In the last post, I introduced about how to deploy a Spring Boot app to a GCP Compute engine using Jenkins. This procedure automated some tasks to simplify the deployment process such as

DevOps Set up a Jenkins server on GCP Compute Engine in 5 minutes 1. Create a GCP Compute Engine Configuration: Remember to Allow Http and Https traffic and enter the following script to install Jenkins: sudo apt update sudo apt install openjdk-8-jdk -y wget -q -O

CS A note on VPN, HTTPS, and Proxy VPN - Virtual Private Network is a private network that allows you to communiate over Internet privately. it is like your home/ office private network, where you can transfer data between computers accross

DevOps A note on DevOps terminologies At the first time I study DevOps, I am overwhelmed by the myriad number of terminologies, buzzwords and tools in DevOps world. So, this is a note to make clear-cut definitions of each

DevOps Build and deploy Spring Boot app to GCP Compute Engine using Jenkin Target Using Jenkin: Build a Spring Boot app to Jar file. Source code is on Github. Upload Jar file to a GCP Compute engine and run. In Jenkin job, can select the branch

A note on React Component unit test Recently, I was assigned a couple of tasks to write unit test (UT) for a frontend project written in React/Redux, which is not really my expertise. This note is for future reference

bigquery Analyse USA Name Data using BigQuery This public dataset was created by the Social Security Administration and contains all names from Social Security card applications for births that occurred in the United States after 1879.I used BigQuery to

CORS A note on CORS, SOP and JSONP SOP - Same Origin Policy What is Origin? Two URLs have the same origin if they have the same protocol port host Example:http://example.com/index.html Same origin: http://example.com/