open-menu closeme
Engineering
github linkedin rss
  • Monotonicity: Find 1-3-2 Pattern

    calendar Oct 14, 2024 · 3 min read · Algorithms Interview  ·
    Share on: twitter copy

    Given an array of numbers A, find out whether it contains a 1-3-2 pattern. A 1-3-2 pattern is a subsequence of three numbers, A[i], A[j] and A[k] such that i < j < k and A[i] < A[k] < A[j]. For clarity, let's call the 1-3-2 pattern the Bronze-Gold-Silver pattern. If A[j] is Gold, then we should consider the …


    Read More
  • Hoare Partition, one of the simplest and most beautiful algorithms

    calendar Jun 17, 2024 · 4 min read · Algorithms  ·
    Share on: twitter copy

    Tony Hoare invented QuickSort in 1961. At the time of its publication, the best comparison-based sorting algorithm was merge sort. Merge sort divides an unordered array into two equally sized subarrays, sorts each subarray, and then merge the two subarrays to produce a sorted array. Merge sort is simple to understand. …


    Read More
  • Monotonic Stack: Steps to Make Array Non-decreasing

    calendar Jan 28, 2024 · 3 min read · Interview Algorithms  ·
    Share on: twitter copy

    Problem Given an integer array A, in one step, remove all elements A[i] where A[i-1] > A[i]. Return the number of steps performed until A becomes a non-decreasing array. See examples at LeetCode 2289. Solution The naive approach executes steps one by one. Store integers in a Linked List. At each step, find all …


    Read More
  • Maglev Hash: Consistent Hash with Guaranteed Even Distribution

    calendar Jan 7, 2024 · 5 min read · Distributed System Algorithms  ·
    Share on: twitter copy

    In distributed systems, because there are too many requests to be handled by a single server reliably, requests are handled by a cluster of servers. In order to get high availability, the technique of distributing requests to servers needs to satisfy the following three requirements. Even distribution. Each backend …


    Read More
  • Monotonicity: Sliding Window

    calendar Nov 27, 2023 · 5 min read · Algorithms Interview  ·
    Share on: twitter copy

    A function is monotonic if it preserves the order of its arguments, i.e., if $x \le y$, then $f(x) \le f(y)$. In this post, we examine a class of problems where the argument is an interval. By identifying monotonic functions, we can reduce the number of intervals to enumerate by an order of magnitude, from $O(n^2)$ to …


    Read More
  • Monotonicity: Find Largest Subarrays for Each Array Element

    calendar Nov 23, 2023 · 6 min read · Algorithms Interview  ·
    Share on: twitter copy

    Given an array of numbers $A$, for each number $A[i]$, find the largest subarray that contains $A[i]$ and $A[i]$ is the minimum of the subarray. For example, for $A=[2, 0, 3, 5, 1, 1, 0, 2 1]$, the largest subarray for $A[4]$ is $[3,5,1,1]$. Let's represent the subarray for $A[i]$ as the left boundary $l[i]$ and right …


    Read More
  • Monotonicity: Find the K-th number in two sorted arrays

    calendar Oct 10, 2023 · 4 min read · Algorithms Interview  ·
    Share on: twitter copy

    Given two sorted arrays of integers, $A$ and $B$, find the $K$-th smallest integer from A and B in $O(\min(\log{N}, \log{M}))$ time. $N$ and $M$ are the size of $A$ and $B$ respectively. Without loss of generality, we can assume A and B are of the same length N. Because both A and B are sorted, we can merge A and B …


    Read More
  • Priority Map: A hash map with access of the minimum value

    calendar Oct 9, 2023 · 4 min read · Go Algorithms  ·
    Share on: twitter copy

    I implemented a job scheduler at work recently. Each job has a unique ID and an expiration time. The job ID is immutable while the expiration time may change. The job scheduler schedules the job of the earliest expiration time. Go comes with heap.Interface and map. My first implementation uses a hashmap and a slice …


    Read More

Peng Zhang

Software Engineer

Recent Posts

  • Page-cache thrashing on EC2: kill the tenant before it takes the host down
  • Pre-load container images on the Bottlerocket read-only root filesystem
  • Leaked empty directories exhaust inodes
  • Share one client per service
  • Debugging zero disk reads after moving to Bottlerocket
  • When sync.Cond is a better primitive than channels: lessons from Go's HTTP/2 client
  • Mysterious boot hang on Graviton: mitigated but never root-caused
  • What is an ABI? Break one to find out

Tags

LINUX 29 GO 23 BOTTLEROCKET 11 CONTAINER 9 ALGORITHMS 8 INTERVIEW 7 CONCURRENCY 4 SYSTEMD 4 DISTRIBUTED SYSTEM 3 GUIDE 3 AWS 2 CONTAINERS 2 EC2 2 SELINUX 2
All Tags
ALGORITHMS8 AWS2 BOTTLEROCKET11 CONCURRENCY4 CONTAINER9 CONTAINERS2 CRYPTOGRAPHY1 DATABASES1 DISTRIBUTED SYSTEM3 DNS1 DOCKER1 EC22 GO23 GUIDE3 INTERVIEW7 LINUX29 NETWORK1 SELINUX2 SHELL1 SYSTEMD4 TESTING1 WEB2
[A~Z][0~9]
Peng Zhang

Copyright 2022-  PENG ZHANG. All Rights Reserved

to-top