<?xml version="1.0" encoding="utf-8" standalone="yes"?>
<rss version="2.0" xmlns:atom="http://www.w3.org/2005/Atom">
  <channel>
    <title>Home on Ruoke Zhang</title>
    <link>https://ruokezhang.github.io/en/</link>
    <description>Recent content in Home on Ruoke Zhang</description>
    <generator>Hugo</generator>
    <language>en</language>
    <lastBuildDate>Sun, 31 May 2026 00:00:00 +0000</lastBuildDate>
    <atom:link href="https://ruokezhang.github.io/en/rss.xml" rel="self" type="application/rss+xml" />
    <item>
      <title>Text-to-Image System Design</title>
      <link>https://ruokezhang.github.io/en/post/system_design/text_to_image/</link>
      <pubDate>Sun, 31 May 2026 00:00:00 +0000</pubDate>
      <guid>https://ruokezhang.github.io/en/post/system_design/text_to_image/</guid>
      <description>&lt;p&gt;&lt;a href=&#34;https://medium.com/pinterest-engineering/building-pinterest-canvas-a-text-to-image-foundation-model-aa34965e84d9&#34;&gt;https://medium.com/pinterest-engineering/building-pinterest-canvas-a-text-to-image-foundation-model-aa34965e84d9&lt;/a&gt;&lt;/p&gt;&#xA;&lt;p&gt;&lt;a href=&#34;https://arxiv.org/abs/2603.06453?utm_source=chatgpt.com&#34;&gt;https://arxiv.org/abs/2603.06453?utm_source=chatgpt.com&lt;/a&gt;&lt;/p&gt;&#xA;&lt;p&gt;&lt;a href=&#34;https://github.com/junfanz1/Awesome-AI-Review/blob/main/System%20Design/GenAI%20System%20Design.md#5-text-to-image&#34;&gt;https://github.com/junfanz1/Awesome-AI-Review/blob/main/System%20Design/GenAI%20System%20Design.md#5-text-to-image&lt;/a&gt;&lt;/p&gt;&#xA;&lt;h2 id=&#34;pinterest-canvas&#34;&gt;Pinterest Canvas&lt;/h2&gt;&#xA;&lt;h3 id=&#34;text-to-image&#34;&gt;Text-To-Image&lt;/h3&gt;&#xA;&lt;p&gt;Generate images conditioned on both &lt;strong&gt;text prompts&lt;/strong&gt; and &lt;strong&gt;reference images&lt;/strong&gt;.&lt;/p&gt;&#xA;&lt;h4 id=&#34;1-text-to-image&#34;&gt;1. text-to-image&lt;/h4&gt;&#xA;&lt;ul&gt;&#xA;&lt;li&gt;Inference&#xA;&lt;ol&gt;&#xA;&lt;li&gt;Embed the text prompt to obtain the text embedding&lt;/li&gt;&#xA;&lt;li&gt;Feed the noisy target latent and the text embedding into the DiT together to obtain the clean target latent&lt;/li&gt;&#xA;&lt;li&gt;The clean target latent passes through the VAE decoder to produce the image&lt;/li&gt;&#xA;&lt;/ol&gt;&#xA;&lt;/li&gt;&#xA;&lt;li&gt;Training&#xA;&lt;ul&gt;&#xA;&lt;li&gt;Training data: (text prompt, real image)&lt;/li&gt;&#xA;&lt;li&gt;Only the DiT is trained. Both the text encoder and the VAE use pretrained weights, and are then frozen&lt;/li&gt;&#xA;&lt;li&gt;The real image passes through the VAE encoder to obtain the real latent. During training, x_t is generated from the real latent&lt;/li&gt;&#xA;&lt;/ul&gt;&#xA;&lt;/li&gt;&#xA;&lt;/ul&gt;&#xA;&lt;h4 id=&#34;2-multimodal-image-editing-tasks&#34;&gt;2. multimodal image editing tasks&lt;/h4&gt;&#xA;&lt;p&gt;Stage 2 starts from the trained Stage 1 text-to-image model.&lt;/p&gt;</description>
    </item>
    <item>
      <title>Visual Search</title>
      <link>https://ruokezhang.github.io/en/post/system_design/visual_search/</link>
      <pubDate>Wed, 27 May 2026 00:00:00 +0000</pubDate>
      <guid>https://ruokezhang.github.io/en/post/system_design/visual_search/</guid>
      <description>&lt;p&gt;&lt;a href=&#34;https://bytebytego.com/courses/machine-learning-system-design-interview/visual-search-system&#34;&gt;bytebytego tutorial&lt;/a&gt;&lt;/p&gt;&#xA;&lt;h2 id=&#34;dataset&#34;&gt;dataset&lt;/h2&gt;&#xA;&lt;ul&gt;&#xA;&lt;li&gt;A query image&lt;/li&gt;&#xA;&lt;li&gt;(n-1) negative images&lt;/li&gt;&#xA;&lt;li&gt;A positive image, i.e., the image most similar to the query image.&lt;/li&gt;&#xA;&lt;li&gt;The index label of the positive image among all the images.&lt;/li&gt;&#xA;&lt;/ul&gt;&#xA;&lt;h3 id=&#34;build-dataset&#34;&gt;build dataset&lt;/h3&gt;&#xA;&lt;ul&gt;&#xA;&lt;li&gt;human judgement: humans annotate the most similar image&lt;/li&gt;&#xA;&lt;li&gt;user interaction&#xA;&lt;ul&gt;&#xA;&lt;li&gt;noisy&lt;/li&gt;&#xA;&lt;li&gt;sparse: may not have click data available for lots of the images&lt;/li&gt;&#xA;&lt;/ul&gt;&#xA;&lt;/li&gt;&#xA;&lt;li&gt;generate similar images&lt;/li&gt;&#xA;&lt;/ul&gt;&#xA;&lt;h2 id=&#34;offline-metrics&#34;&gt;Offline metrics&lt;/h2&gt;&#xA;&lt;h3 id=&#34;mean-reciprocal-rank-mrr&#34;&gt;Mean reciprocal rank (MRR)&lt;/h3&gt;&#xA;&lt;p&gt;MRR=1/m * sum(1/rank_i)&lt;/p&gt;&#xA;&lt;p&gt;downside&lt;/p&gt;</description>
    </item>
    <item>
      <title>Deep Learning</title>
      <link>https://ruokezhang.github.io/en/ai/deep_learning/</link>
      <pubDate>Mon, 25 May 2026 00:00:00 +0000</pubDate>
      <guid>https://ruokezhang.github.io/en/ai/deep_learning/</guid>
      <description>&lt;h2 id=&#34;neural-network&#34;&gt;Neural Network&lt;/h2&gt;&#xA;&lt;h3 id=&#34;terminology&#34;&gt;terminology&lt;/h3&gt;&#xA;&lt;p&gt;For example, suppose there are 10,000 samples with a batch size of 100:&lt;/p&gt;&#xA;&lt;ul&gt;&#xA;&lt;li&gt;&#xA;&lt;p&gt;epoch: all 10,000 samples go through forward + back prop once. After every epoch, the data should be shuffled to make sure each batch is made up of a different combination of samples each time.&lt;/p&gt;&#xA;&lt;/li&gt;&#xA;&lt;li&gt;&#xA;&lt;p&gt;iteration: one iteration means 100 samples go through one forward pass (computing the loss) + backpropagation (computing the gradients), and then optimizer.step() updates the weights.&lt;/p&gt;</description>
    </item>
    <item>
      <title>AI Models</title>
      <link>https://ruokezhang.github.io/en/ai/models/</link>
      <pubDate>Sun, 24 May 2026 00:00:00 +0000</pubDate>
      <guid>https://ruokezhang.github.io/en/ai/models/</guid>
      <description>&lt;h2 id=&#34;clip&#34;&gt;CLIP&lt;/h2&gt;&#xA;&lt;p&gt;&lt;a href=&#34;https://arxiv.org/pdf/2103.00020&#34;&gt;paper&lt;/a&gt;&lt;/p&gt;&#xA;&lt;div class=&#34;highlight&#34;&gt;&lt;div style=&#34;color:#4c4f69;background-color:#eff1f5;-moz-tab-size:2;-o-tab-size:2;tab-size:2;&#34;&gt;&#xA;&lt;table style=&#34;border-spacing:0;padding:0;margin:0;border:0;&#34;&gt;&lt;tr&gt;&lt;td style=&#34;vertical-align:top;padding:0;margin:0;border:0;&#34;&gt;&#xA;&lt;pre tabindex=&#34;0&#34; style=&#34;color:#4c4f69;background-color:#eff1f5;-moz-tab-size:2;-o-tab-size:2;tab-size:2;&#34;&gt;&lt;code&gt;&lt;span style=&#34;white-space:pre;-webkit-user-select:none;user-select:none;margin-right:0.4em;padding:0 0.4em 0 0.4em;color:#8c8fa1&#34;&gt; 1&#xA;&lt;/span&gt;&lt;span style=&#34;white-space:pre;-webkit-user-select:none;user-select:none;margin-right:0.4em;padding:0 0.4em 0 0.4em;color:#8c8fa1&#34;&gt; 2&#xA;&lt;/span&gt;&lt;span style=&#34;white-space:pre;-webkit-user-select:none;user-select:none;margin-right:0.4em;padding:0 0.4em 0 0.4em;color:#8c8fa1&#34;&gt; 3&#xA;&lt;/span&gt;&lt;span style=&#34;white-space:pre;-webkit-user-select:none;user-select:none;margin-right:0.4em;padding:0 0.4em 0 0.4em;color:#8c8fa1&#34;&gt; 4&#xA;&lt;/span&gt;&lt;span style=&#34;white-space:pre;-webkit-user-select:none;user-select:none;margin-right:0.4em;padding:0 0.4em 0 0.4em;color:#8c8fa1&#34;&gt; 5&#xA;&lt;/span&gt;&lt;span style=&#34;white-space:pre;-webkit-user-select:none;user-select:none;margin-right:0.4em;padding:0 0.4em 0 0.4em;color:#8c8fa1&#34;&gt; 6&#xA;&lt;/span&gt;&lt;span style=&#34;white-space:pre;-webkit-user-select:none;user-select:none;margin-right:0.4em;padding:0 0.4em 0 0.4em;color:#8c8fa1&#34;&gt; 7&#xA;&lt;/span&gt;&lt;span style=&#34;white-space:pre;-webkit-user-select:none;user-select:none;margin-right:0.4em;padding:0 0.4em 0 0.4em;color:#8c8fa1&#34;&gt; 8&#xA;&lt;/span&gt;&lt;span style=&#34;white-space:pre;-webkit-user-select:none;user-select:none;margin-right:0.4em;padding:0 0.4em 0 0.4em;color:#8c8fa1&#34;&gt; 9&#xA;&lt;/span&gt;&lt;span style=&#34;white-space:pre;-webkit-user-select:none;user-select:none;margin-right:0.4em;padding:0 0.4em 0 0.4em;color:#8c8fa1&#34;&gt;10&#xA;&lt;/span&gt;&lt;span style=&#34;white-space:pre;-webkit-user-select:none;user-select:none;margin-right:0.4em;padding:0 0.4em 0 0.4em;color:#8c8fa1&#34;&gt;11&#xA;&lt;/span&gt;&lt;span style=&#34;white-space:pre;-webkit-user-select:none;user-select:none;margin-right:0.4em;padding:0 0.4em 0 0.4em;color:#8c8fa1&#34;&gt;12&#xA;&lt;/span&gt;&lt;span style=&#34;white-space:pre;-webkit-user-select:none;user-select:none;margin-right:0.4em;padding:0 0.4em 0 0.4em;color:#8c8fa1&#34;&gt;13&#xA;&lt;/span&gt;&lt;span style=&#34;white-space:pre;-webkit-user-select:none;user-select:none;margin-right:0.4em;padding:0 0.4em 0 0.4em;color:#8c8fa1&#34;&gt;14&#xA;&lt;/span&gt;&lt;span style=&#34;white-space:pre;-webkit-user-select:none;user-select:none;margin-right:0.4em;padding:0 0.4em 0 0.4em;color:#8c8fa1&#34;&gt;15&#xA;&lt;/span&gt;&lt;span style=&#34;white-space:pre;-webkit-user-select:none;user-select:none;margin-right:0.4em;padding:0 0.4em 0 0.4em;color:#8c8fa1&#34;&gt;16&#xA;&lt;/span&gt;&lt;span style=&#34;white-space:pre;-webkit-user-select:none;user-select:none;margin-right:0.4em;padding:0 0.4em 0 0.4em;color:#8c8fa1&#34;&gt;17&#xA;&lt;/span&gt;&lt;span style=&#34;white-space:pre;-webkit-user-select:none;user-select:none;margin-right:0.4em;padding:0 0.4em 0 0.4em;color:#8c8fa1&#34;&gt;18&#xA;&lt;/span&gt;&lt;span style=&#34;white-space:pre;-webkit-user-select:none;user-select:none;margin-right:0.4em;padding:0 0.4em 0 0.4em;color:#8c8fa1&#34;&gt;19&#xA;&lt;/span&gt;&lt;span style=&#34;white-space:pre;-webkit-user-select:none;user-select:none;margin-right:0.4em;padding:0 0.4em 0 0.4em;color:#8c8fa1&#34;&gt;20&#xA;&lt;/span&gt;&lt;/code&gt;&lt;/pre&gt;&lt;/td&gt;&#xA;&lt;td style=&#34;vertical-align:top;padding:0;margin:0;border:0;;width:100%&#34;&gt;&#xA;&lt;pre tabindex=&#34;0&#34; style=&#34;color:#4c4f69;background-color:#eff1f5;-moz-tab-size:2;-o-tab-size:2;tab-size:2;&#34;&gt;&lt;code class=&#34;language-py&#34; data-lang=&#34;py&#34;&gt;&lt;span style=&#34;display:flex;&#34;&gt;&lt;span&gt;&lt;span style=&#34;color:#9ca0b0;font-style:italic&#34;&gt;# image_encoder - ResNet or Vision Transformer&lt;/span&gt;&#xA;&lt;/span&gt;&lt;/span&gt;&lt;span style=&#34;display:flex;&#34;&gt;&lt;span&gt;&lt;span style=&#34;color:#9ca0b0;font-style:italic&#34;&gt;# text_encoder - CBOW or Text Transformer&lt;/span&gt;&#xA;&lt;/span&gt;&lt;/span&gt;&lt;span style=&#34;display:flex;&#34;&gt;&lt;span&gt;&lt;span style=&#34;color:#9ca0b0;font-style:italic&#34;&gt;# I[n, h, w, c] - minibatch of aligned images&lt;/span&gt;&#xA;&lt;/span&gt;&lt;/span&gt;&lt;span style=&#34;display:flex;&#34;&gt;&lt;span&gt;&lt;span style=&#34;color:#9ca0b0;font-style:italic&#34;&gt;# T[n, l] - minibatch of aligned texts&lt;/span&gt;&#xA;&lt;/span&gt;&lt;/span&gt;&lt;span style=&#34;display:flex;&#34;&gt;&lt;span&gt;&lt;span style=&#34;color:#9ca0b0;font-style:italic&#34;&gt;# W_i[d_i, d_e] - learned proj of image to embed&lt;/span&gt;&#xA;&lt;/span&gt;&lt;/span&gt;&lt;span style=&#34;display:flex;&#34;&gt;&lt;span&gt;&lt;span style=&#34;color:#9ca0b0;font-style:italic&#34;&gt;# W_t[d_t, d_e] - learned proj of text to embed&lt;/span&gt;&#xA;&lt;/span&gt;&lt;/span&gt;&lt;span style=&#34;display:flex;&#34;&gt;&lt;span&gt;&lt;span style=&#34;color:#9ca0b0;font-style:italic&#34;&gt;# t - learned temperature parameter&lt;/span&gt;&#xA;&lt;/span&gt;&lt;/span&gt;&lt;span style=&#34;display:flex;&#34;&gt;&lt;span&gt;&lt;span style=&#34;color:#9ca0b0;font-style:italic&#34;&gt;# extract feature representations of each modality&lt;/span&gt;&#xA;&lt;/span&gt;&lt;/span&gt;&lt;span style=&#34;display:flex;&#34;&gt;&lt;span&gt;I_f &lt;span style=&#34;color:#04a5e5;font-weight:bold&#34;&gt;=&lt;/span&gt; image_encoder(I) &lt;span style=&#34;color:#9ca0b0;font-style:italic&#34;&gt;#[n, d_i]&lt;/span&gt;&#xA;&lt;/span&gt;&lt;/span&gt;&lt;span style=&#34;display:flex;&#34;&gt;&lt;span&gt;T_f &lt;span style=&#34;color:#04a5e5;font-weight:bold&#34;&gt;=&lt;/span&gt; text_encoder(T) &lt;span style=&#34;color:#9ca0b0;font-style:italic&#34;&gt;#[n, d_t]&lt;/span&gt;&#xA;&lt;/span&gt;&lt;/span&gt;&lt;span style=&#34;display:flex;&#34;&gt;&lt;span&gt;&lt;span style=&#34;color:#9ca0b0;font-style:italic&#34;&gt;# joint multimodal embedding [n, d_e]&lt;/span&gt;&#xA;&lt;/span&gt;&lt;/span&gt;&lt;span style=&#34;display:flex;&#34;&gt;&lt;span&gt;I_e &lt;span style=&#34;color:#04a5e5;font-weight:bold&#34;&gt;=&lt;/span&gt; l2_normalize(np&lt;span style=&#34;color:#04a5e5;font-weight:bold&#34;&gt;.&lt;/span&gt;dot(I_f, W_i), axis&lt;span style=&#34;color:#04a5e5;font-weight:bold&#34;&gt;=&lt;/span&gt;&lt;span style=&#34;color:#fe640b&#34;&gt;1&lt;/span&gt;) &lt;span style=&#34;color:#9ca0b0;font-style:italic&#34;&gt;#[n, d_e]&lt;/span&gt;&#xA;&lt;/span&gt;&lt;/span&gt;&lt;span style=&#34;display:flex;&#34;&gt;&lt;span&gt;T_e &lt;span style=&#34;color:#04a5e5;font-weight:bold&#34;&gt;=&lt;/span&gt; l2_normalize(np&lt;span style=&#34;color:#04a5e5;font-weight:bold&#34;&gt;.&lt;/span&gt;dot(T_f, W_t), axis&lt;span style=&#34;color:#04a5e5;font-weight:bold&#34;&gt;=&lt;/span&gt;&lt;span style=&#34;color:#fe640b&#34;&gt;1&lt;/span&gt;) &lt;span style=&#34;color:#9ca0b0;font-style:italic&#34;&gt;#[n, n]&lt;/span&gt;&#xA;&lt;/span&gt;&lt;/span&gt;&lt;span style=&#34;display:flex;&#34;&gt;&lt;span&gt;&lt;span style=&#34;color:#9ca0b0;font-style:italic&#34;&gt;# scaled pairwise cosine similarities [n, n]&lt;/span&gt;&#xA;&lt;/span&gt;&lt;/span&gt;&lt;span style=&#34;display:flex;&#34;&gt;&lt;span&gt;logits &lt;span style=&#34;color:#04a5e5;font-weight:bold&#34;&gt;=&lt;/span&gt; np&lt;span style=&#34;color:#04a5e5;font-weight:bold&#34;&gt;.&lt;/span&gt;dot(I_e, T_e&lt;span style=&#34;color:#04a5e5;font-weight:bold&#34;&gt;.&lt;/span&gt;T) &lt;span style=&#34;color:#04a5e5;font-weight:bold&#34;&gt;*&lt;/span&gt; np&lt;span style=&#34;color:#04a5e5;font-weight:bold&#34;&gt;.&lt;/span&gt;exp(t)&#xA;&lt;/span&gt;&lt;/span&gt;&lt;span style=&#34;display:flex;&#34;&gt;&lt;span&gt;&lt;span style=&#34;color:#9ca0b0;font-style:italic&#34;&gt;# symmetric loss function&lt;/span&gt;&#xA;&lt;/span&gt;&lt;/span&gt;&lt;span style=&#34;display:flex;&#34;&gt;&lt;span&gt;labels &lt;span style=&#34;color:#04a5e5;font-weight:bold&#34;&gt;=&lt;/span&gt; np&lt;span style=&#34;color:#04a5e5;font-weight:bold&#34;&gt;.&lt;/span&gt;arange(n)&#xA;&lt;/span&gt;&lt;/span&gt;&lt;span style=&#34;display:flex;&#34;&gt;&lt;span&gt;loss_i &lt;span style=&#34;color:#04a5e5;font-weight:bold&#34;&gt;=&lt;/span&gt; cross_entropy_loss(logits, labels, axis&lt;span style=&#34;color:#04a5e5;font-weight:bold&#34;&gt;=&lt;/span&gt;&lt;span style=&#34;color:#fe640b&#34;&gt;1&lt;/span&gt;) &lt;span style=&#34;color:#9ca0b0;font-style:italic&#34;&gt;# image-to-text loss&lt;/span&gt;&#xA;&lt;/span&gt;&lt;/span&gt;&lt;span style=&#34;display:flex;&#34;&gt;&lt;span&gt;loss_t &lt;span style=&#34;color:#04a5e5;font-weight:bold&#34;&gt;=&lt;/span&gt; cross_entropy_loss(logits, labels, axis&lt;span style=&#34;color:#04a5e5;font-weight:bold&#34;&gt;=&lt;/span&gt;&lt;span style=&#34;color:#fe640b&#34;&gt;0&lt;/span&gt;)&#xA;&lt;/span&gt;&lt;/span&gt;&lt;span style=&#34;display:flex;&#34;&gt;&lt;span&gt;loss &lt;span style=&#34;color:#04a5e5;font-weight:bold&#34;&gt;=&lt;/span&gt; (loss_i &lt;span style=&#34;color:#04a5e5;font-weight:bold&#34;&gt;+&lt;/span&gt; loss_t)&lt;span style=&#34;color:#04a5e5;font-weight:bold&#34;&gt;/&lt;/span&gt;&lt;span style=&#34;color:#fe640b&#34;&gt;2&lt;/span&gt;&#xA;&lt;/span&gt;&lt;/span&gt;&lt;/code&gt;&lt;/pre&gt;&lt;/td&gt;&lt;/tr&gt;&lt;/table&gt;&#xA;&lt;/div&gt;&#xA;&lt;/div&gt;&lt;h3 id=&#34;architecture&#34;&gt;architecture&lt;/h3&gt;&#xA;&lt;h4 id=&#34;image-encoder&#34;&gt;image encoder&lt;/h4&gt;&#xA;&lt;h5 id=&#34;visiontransformer&#34;&gt;VisionTransformer&lt;/h5&gt;&#xA;&lt;ul&gt;&#xA;&lt;li&gt;Input: [B,3,H,W]&lt;/li&gt;&#xA;&lt;li&gt;Output: [B,output_dim]&lt;/li&gt;&#xA;&lt;/ul&gt;&#xA;&lt;div class=&#34;highlight&#34;&gt;&lt;div style=&#34;color:#4c4f69;background-color:#eff1f5;-moz-tab-size:2;-o-tab-size:2;tab-size:2;&#34;&gt;&#xA;&lt;table style=&#34;border-spacing:0;padding:0;margin:0;border:0;&#34;&gt;&lt;tr&gt;&lt;td style=&#34;vertical-align:top;padding:0;margin:0;border:0;&#34;&gt;&#xA;&lt;pre tabindex=&#34;0&#34; style=&#34;color:#4c4f69;background-color:#eff1f5;-moz-tab-size:2;-o-tab-size:2;tab-size:2;&#34;&gt;&lt;code&gt;&lt;span style=&#34;white-space:pre;-webkit-user-select:none;user-select:none;margin-right:0.4em;padding:0 0.4em 0 0.4em;color:#8c8fa1&#34;&gt; 1&#xA;&lt;/span&gt;&lt;span style=&#34;white-space:pre;-webkit-user-select:none;user-select:none;margin-right:0.4em;padding:0 0.4em 0 0.4em;color:#8c8fa1&#34;&gt; 2&#xA;&lt;/span&gt;&lt;span style=&#34;white-space:pre;-webkit-user-select:none;user-select:none;margin-right:0.4em;padding:0 0.4em 0 0.4em;color:#8c8fa1&#34;&gt; 3&#xA;&lt;/span&gt;&lt;span style=&#34;white-space:pre;-webkit-user-select:none;user-select:none;margin-right:0.4em;padding:0 0.4em 0 0.4em;color:#8c8fa1&#34;&gt; 4&#xA;&lt;/span&gt;&lt;span style=&#34;white-space:pre;-webkit-user-select:none;user-select:none;margin-right:0.4em;padding:0 0.4em 0 0.4em;color:#8c8fa1&#34;&gt; 5&#xA;&lt;/span&gt;&lt;span style=&#34;white-space:pre;-webkit-user-select:none;user-select:none;margin-right:0.4em;padding:0 0.4em 0 0.4em;color:#8c8fa1&#34;&gt; 6&#xA;&lt;/span&gt;&lt;span style=&#34;white-space:pre;-webkit-user-select:none;user-select:none;margin-right:0.4em;padding:0 0.4em 0 0.4em;color:#8c8fa1&#34;&gt; 7&#xA;&lt;/span&gt;&lt;span style=&#34;white-space:pre;-webkit-user-select:none;user-select:none;margin-right:0.4em;padding:0 0.4em 0 0.4em;color:#8c8fa1&#34;&gt; 8&#xA;&lt;/span&gt;&lt;span style=&#34;white-space:pre;-webkit-user-select:none;user-select:none;margin-right:0.4em;padding:0 0.4em 0 0.4em;color:#8c8fa1&#34;&gt; 9&#xA;&lt;/span&gt;&lt;span style=&#34;white-space:pre;-webkit-user-select:none;user-select:none;margin-right:0.4em;padding:0 0.4em 0 0.4em;color:#8c8fa1&#34;&gt;10&#xA;&lt;/span&gt;&lt;span style=&#34;white-space:pre;-webkit-user-select:none;user-select:none;margin-right:0.4em;padding:0 0.4em 0 0.4em;color:#8c8fa1&#34;&gt;11&#xA;&lt;/span&gt;&lt;span style=&#34;white-space:pre;-webkit-user-select:none;user-select:none;margin-right:0.4em;padding:0 0.4em 0 0.4em;color:#8c8fa1&#34;&gt;12&#xA;&lt;/span&gt;&lt;span style=&#34;white-space:pre;-webkit-user-select:none;user-select:none;margin-right:0.4em;padding:0 0.4em 0 0.4em;color:#8c8fa1&#34;&gt;13&#xA;&lt;/span&gt;&lt;span style=&#34;white-space:pre;-webkit-user-select:none;user-select:none;margin-right:0.4em;padding:0 0.4em 0 0.4em;color:#8c8fa1&#34;&gt;14&#xA;&lt;/span&gt;&lt;span style=&#34;white-space:pre;-webkit-user-select:none;user-select:none;margin-right:0.4em;padding:0 0.4em 0 0.4em;color:#8c8fa1&#34;&gt;15&#xA;&lt;/span&gt;&lt;span style=&#34;white-space:pre;-webkit-user-select:none;user-select:none;margin-right:0.4em;padding:0 0.4em 0 0.4em;color:#8c8fa1&#34;&gt;16&#xA;&lt;/span&gt;&lt;span style=&#34;white-space:pre;-webkit-user-select:none;user-select:none;margin-right:0.4em;padding:0 0.4em 0 0.4em;color:#8c8fa1&#34;&gt;17&#xA;&lt;/span&gt;&lt;span style=&#34;white-space:pre;-webkit-user-select:none;user-select:none;margin-right:0.4em;padding:0 0.4em 0 0.4em;color:#8c8fa1&#34;&gt;18&#xA;&lt;/span&gt;&lt;span style=&#34;white-space:pre;-webkit-user-select:none;user-select:none;margin-right:0.4em;padding:0 0.4em 0 0.4em;color:#8c8fa1&#34;&gt;19&#xA;&lt;/span&gt;&lt;span style=&#34;white-space:pre;-webkit-user-select:none;user-select:none;margin-right:0.4em;padding:0 0.4em 0 0.4em;color:#8c8fa1&#34;&gt;20&#xA;&lt;/span&gt;&lt;span style=&#34;white-space:pre;-webkit-user-select:none;user-select:none;margin-right:0.4em;padding:0 0.4em 0 0.4em;color:#8c8fa1&#34;&gt;21&#xA;&lt;/span&gt;&lt;span style=&#34;white-space:pre;-webkit-user-select:none;user-select:none;margin-right:0.4em;padding:0 0.4em 0 0.4em;color:#8c8fa1&#34;&gt;22&#xA;&lt;/span&gt;&lt;span style=&#34;white-space:pre;-webkit-user-select:none;user-select:none;margin-right:0.4em;padding:0 0.4em 0 0.4em;color:#8c8fa1&#34;&gt;23&#xA;&lt;/span&gt;&lt;span style=&#34;white-space:pre;-webkit-user-select:none;user-select:none;margin-right:0.4em;padding:0 0.4em 0 0.4em;color:#8c8fa1&#34;&gt;24&#xA;&lt;/span&gt;&lt;span style=&#34;white-space:pre;-webkit-user-select:none;user-select:none;margin-right:0.4em;padding:0 0.4em 0 0.4em;color:#8c8fa1&#34;&gt;25&#xA;&lt;/span&gt;&lt;span style=&#34;white-space:pre;-webkit-user-select:none;user-select:none;margin-right:0.4em;padding:0 0.4em 0 0.4em;color:#8c8fa1&#34;&gt;26&#xA;&lt;/span&gt;&lt;span style=&#34;white-space:pre;-webkit-user-select:none;user-select:none;margin-right:0.4em;padding:0 0.4em 0 0.4em;color:#8c8fa1&#34;&gt;27&#xA;&lt;/span&gt;&lt;span style=&#34;white-space:pre;-webkit-user-select:none;user-select:none;margin-right:0.4em;padding:0 0.4em 0 0.4em;color:#8c8fa1&#34;&gt;28&#xA;&lt;/span&gt;&lt;span style=&#34;white-space:pre;-webkit-user-select:none;user-select:none;margin-right:0.4em;padding:0 0.4em 0 0.4em;color:#8c8fa1&#34;&gt;29&#xA;&lt;/span&gt;&lt;span style=&#34;white-space:pre;-webkit-user-select:none;user-select:none;margin-right:0.4em;padding:0 0.4em 0 0.4em;color:#8c8fa1&#34;&gt;30&#xA;&lt;/span&gt;&lt;span style=&#34;white-space:pre;-webkit-user-select:none;user-select:none;margin-right:0.4em;padding:0 0.4em 0 0.4em;color:#8c8fa1&#34;&gt;31&#xA;&lt;/span&gt;&lt;span style=&#34;white-space:pre;-webkit-user-select:none;user-select:none;margin-right:0.4em;padding:0 0.4em 0 0.4em;color:#8c8fa1&#34;&gt;32&#xA;&lt;/span&gt;&lt;span style=&#34;white-space:pre;-webkit-user-select:none;user-select:none;margin-right:0.4em;padding:0 0.4em 0 0.4em;color:#8c8fa1&#34;&gt;33&#xA;&lt;/span&gt;&lt;span style=&#34;white-space:pre;-webkit-user-select:none;user-select:none;margin-right:0.4em;padding:0 0.4em 0 0.4em;color:#8c8fa1&#34;&gt;34&#xA;&lt;/span&gt;&lt;span style=&#34;white-space:pre;-webkit-user-select:none;user-select:none;margin-right:0.4em;padding:0 0.4em 0 0.4em;color:#8c8fa1&#34;&gt;35&#xA;&lt;/span&gt;&lt;span style=&#34;white-space:pre;-webkit-user-select:none;user-select:none;margin-right:0.4em;padding:0 0.4em 0 0.4em;color:#8c8fa1&#34;&gt;36&#xA;&lt;/span&gt;&lt;/code&gt;&lt;/pre&gt;&lt;/td&gt;&#xA;&lt;td style=&#34;vertical-align:top;padding:0;margin:0;border:0;;width:100%&#34;&gt;&#xA;&lt;pre tabindex=&#34;0&#34; style=&#34;color:#4c4f69;background-color:#eff1f5;-moz-tab-size:2;-o-tab-size:2;tab-size:2;&#34;&gt;&lt;code class=&#34;language-py&#34; data-lang=&#34;py&#34;&gt;&lt;span style=&#34;display:flex;&#34;&gt;&lt;span&gt;&lt;span style=&#34;color:#8839ef&#34;&gt;class&lt;/span&gt; &lt;span style=&#34;color:#df8e1d&#34;&gt;VisionTransformer&lt;/span&gt;(nn&lt;span style=&#34;color:#04a5e5;font-weight:bold&#34;&gt;.&lt;/span&gt;Module):&#xA;&lt;/span&gt;&lt;/span&gt;&lt;span style=&#34;display:flex;&#34;&gt;&lt;span&gt;    &lt;span style=&#34;color:#8839ef&#34;&gt;def&lt;/span&gt; &lt;span style=&#34;color:#1e66f5&#34;&gt;__init__&lt;/span&gt;(&lt;span style=&#34;color:#04a5e5&#34;&gt;self&lt;/span&gt;, input_resolution: &lt;span style=&#34;color:#04a5e5&#34;&gt;int&lt;/span&gt;, patch_size: &lt;span style=&#34;color:#04a5e5&#34;&gt;int&lt;/span&gt;, width: &lt;span style=&#34;color:#04a5e5&#34;&gt;int&lt;/span&gt;, layers: &lt;span style=&#34;color:#04a5e5&#34;&gt;int&lt;/span&gt;, heads: &lt;span style=&#34;color:#04a5e5&#34;&gt;int&lt;/span&gt;, output_dim: &lt;span style=&#34;color:#04a5e5&#34;&gt;int&lt;/span&gt;):&#xA;&lt;/span&gt;&lt;/span&gt;&lt;span style=&#34;display:flex;&#34;&gt;&lt;span&gt;        &lt;span style=&#34;color:#04a5e5&#34;&gt;super&lt;/span&gt;()&lt;span style=&#34;color:#04a5e5;font-weight:bold&#34;&gt;.&lt;/span&gt;&lt;span style=&#34;color:#1e66f5&#34;&gt;__init__&lt;/span&gt;()&#xA;&lt;/span&gt;&lt;/span&gt;&lt;span style=&#34;display:flex;&#34;&gt;&lt;span&gt;        &lt;span style=&#34;color:#04a5e5&#34;&gt;self&lt;/span&gt;&lt;span style=&#34;color:#04a5e5;font-weight:bold&#34;&gt;.&lt;/span&gt;input_resolution &lt;span style=&#34;color:#04a5e5;font-weight:bold&#34;&gt;=&lt;/span&gt; input_resolution&#xA;&lt;/span&gt;&lt;/span&gt;&lt;span style=&#34;display:flex;&#34;&gt;&lt;span&gt;        &lt;span style=&#34;color:#04a5e5&#34;&gt;self&lt;/span&gt;&lt;span style=&#34;color:#04a5e5;font-weight:bold&#34;&gt;.&lt;/span&gt;output_dim &lt;span style=&#34;color:#04a5e5;font-weight:bold&#34;&gt;=&lt;/span&gt; output_dim&#xA;&lt;/span&gt;&lt;/span&gt;&lt;span style=&#34;display:flex;&#34;&gt;&lt;span&gt;        &lt;span style=&#34;color:#04a5e5&#34;&gt;self&lt;/span&gt;&lt;span style=&#34;color:#04a5e5;font-weight:bold&#34;&gt;.&lt;/span&gt;conv1 &lt;span style=&#34;color:#04a5e5;font-weight:bold&#34;&gt;=&lt;/span&gt; nn&lt;span style=&#34;color:#04a5e5;font-weight:bold&#34;&gt;.&lt;/span&gt;Conv2d(in_channels&lt;span style=&#34;color:#04a5e5;font-weight:bold&#34;&gt;=&lt;/span&gt;&lt;span style=&#34;color:#fe640b&#34;&gt;3&lt;/span&gt;, out_channels&lt;span style=&#34;color:#04a5e5;font-weight:bold&#34;&gt;=&lt;/span&gt;width, kernel_size&lt;span style=&#34;color:#04a5e5;font-weight:bold&#34;&gt;=&lt;/span&gt;patch_size, stride&lt;span style=&#34;color:#04a5e5;font-weight:bold&#34;&gt;=&lt;/span&gt;patch_size, bias&lt;span style=&#34;color:#04a5e5;font-weight:bold&#34;&gt;=&lt;/span&gt;&lt;span style=&#34;color:#fe640b&#34;&gt;False&lt;/span&gt;) &lt;span style=&#34;color:#9ca0b0;font-style:italic&#34;&gt;#width is the hidden dimension of each token in the Transformer.&lt;/span&gt;&#xA;&lt;/span&gt;&lt;/span&gt;&lt;span style=&#34;display:flex;&#34;&gt;&lt;span&gt;        &lt;span style=&#34;color:#9ca0b0;font-style:italic&#34;&gt;# grid=input_resolution/patch_size&lt;/span&gt;&#xA;&lt;/span&gt;&lt;/span&gt;&lt;span style=&#34;display:flex;&#34;&gt;&lt;span&gt;        &lt;span style=&#34;color:#9ca0b0;font-style:italic&#34;&gt;# after conv1, becomes [B, width, grid, grid]&lt;/span&gt;&#xA;&lt;/span&gt;&lt;/span&gt;&lt;span style=&#34;display:flex;&#34;&gt;&lt;span&gt;        scale &lt;span style=&#34;color:#04a5e5;font-weight:bold&#34;&gt;=&lt;/span&gt; width &lt;span style=&#34;color:#04a5e5;font-weight:bold&#34;&gt;**&lt;/span&gt; &lt;span style=&#34;color:#04a5e5;font-weight:bold&#34;&gt;-&lt;/span&gt;&lt;span style=&#34;color:#fe640b&#34;&gt;0.5&lt;/span&gt;&#xA;&lt;/span&gt;&lt;/span&gt;&lt;span style=&#34;display:flex;&#34;&gt;&lt;span&gt;        &lt;span style=&#34;color:#04a5e5&#34;&gt;self&lt;/span&gt;&lt;span style=&#34;color:#04a5e5;font-weight:bold&#34;&gt;.&lt;/span&gt;class_embedding &lt;span style=&#34;color:#04a5e5;font-weight:bold&#34;&gt;=&lt;/span&gt; nn&lt;span style=&#34;color:#04a5e5;font-weight:bold&#34;&gt;.&lt;/span&gt;Parameter(scale &lt;span style=&#34;color:#04a5e5;font-weight:bold&#34;&gt;*&lt;/span&gt; torch&lt;span style=&#34;color:#04a5e5;font-weight:bold&#34;&gt;.&lt;/span&gt;randn(width)) &lt;span style=&#34;color:#9ca0b0;font-style:italic&#34;&gt;#class token, a special token dedicated to &amp;#34;collecting information from the whole image&amp;#34;&lt;/span&gt;&#xA;&lt;/span&gt;&lt;/span&gt;&lt;span style=&#34;display:flex;&#34;&gt;&lt;span&gt;        &lt;span style=&#34;color:#04a5e5&#34;&gt;self&lt;/span&gt;&lt;span style=&#34;color:#04a5e5;font-weight:bold&#34;&gt;.&lt;/span&gt;positional_embedding &lt;span style=&#34;color:#04a5e5;font-weight:bold&#34;&gt;=&lt;/span&gt; nn&lt;span style=&#34;color:#04a5e5;font-weight:bold&#34;&gt;.&lt;/span&gt;Parameter(scale &lt;span style=&#34;color:#04a5e5;font-weight:bold&#34;&gt;*&lt;/span&gt; torch&lt;span style=&#34;color:#04a5e5;font-weight:bold&#34;&gt;.&lt;/span&gt;randn((input_resolution &lt;span style=&#34;color:#04a5e5;font-weight:bold&#34;&gt;//&lt;/span&gt; patch_size) &lt;span style=&#34;color:#04a5e5;font-weight:bold&#34;&gt;**&lt;/span&gt; &lt;span style=&#34;color:#fe640b&#34;&gt;2&lt;/span&gt; &lt;span style=&#34;color:#04a5e5;font-weight:bold&#34;&gt;+&lt;/span&gt; &lt;span style=&#34;color:#fe640b&#34;&gt;1&lt;/span&gt;, width)) &lt;span style=&#34;color:#9ca0b0;font-style:italic&#34;&gt;# [(input_resolution // patch_size) ** 2 + 1, width]&lt;/span&gt;&#xA;&lt;/span&gt;&lt;/span&gt;&lt;span style=&#34;display:flex;&#34;&gt;&lt;span&gt;        &lt;span style=&#34;color:#04a5e5&#34;&gt;self&lt;/span&gt;&lt;span style=&#34;color:#04a5e5;font-weight:bold&#34;&gt;.&lt;/span&gt;ln_pre &lt;span style=&#34;color:#04a5e5;font-weight:bold&#34;&gt;=&lt;/span&gt; LayerNorm(width)&#xA;&lt;/span&gt;&lt;/span&gt;&lt;span style=&#34;display:flex;&#34;&gt;&lt;span&gt;&#xA;&lt;/span&gt;&lt;/span&gt;&lt;span style=&#34;display:flex;&#34;&gt;&lt;span&gt;        &lt;span style=&#34;color:#04a5e5&#34;&gt;self&lt;/span&gt;&lt;span style=&#34;color:#04a5e5;font-weight:bold&#34;&gt;.&lt;/span&gt;transformer &lt;span style=&#34;color:#04a5e5;font-weight:bold&#34;&gt;=&lt;/span&gt; Transformer(width, layers, heads)&#xA;&lt;/span&gt;&lt;/span&gt;&lt;span style=&#34;display:flex;&#34;&gt;&lt;span&gt;&#xA;&lt;/span&gt;&lt;/span&gt;&lt;span style=&#34;display:flex;&#34;&gt;&lt;span&gt;        &lt;span style=&#34;color:#04a5e5&#34;&gt;self&lt;/span&gt;&lt;span style=&#34;color:#04a5e5;font-weight:bold&#34;&gt;.&lt;/span&gt;ln_post &lt;span style=&#34;color:#04a5e5;font-weight:bold&#34;&gt;=&lt;/span&gt; LayerNorm(width)&#xA;&lt;/span&gt;&lt;/span&gt;&lt;span style=&#34;display:flex;&#34;&gt;&lt;span&gt;        &lt;span style=&#34;color:#04a5e5&#34;&gt;self&lt;/span&gt;&lt;span style=&#34;color:#04a5e5;font-weight:bold&#34;&gt;.&lt;/span&gt;proj &lt;span style=&#34;color:#04a5e5;font-weight:bold&#34;&gt;=&lt;/span&gt; nn&lt;span style=&#34;color:#04a5e5;font-weight:bold&#34;&gt;.&lt;/span&gt;Parameter(scale &lt;span style=&#34;color:#04a5e5;font-weight:bold&#34;&gt;*&lt;/span&gt; torch&lt;span style=&#34;color:#04a5e5;font-weight:bold&#34;&gt;.&lt;/span&gt;randn(width, output_dim))&#xA;&lt;/span&gt;&lt;/span&gt;&lt;span style=&#34;display:flex;&#34;&gt;&lt;span&gt;&#xA;&lt;/span&gt;&lt;/span&gt;&lt;span style=&#34;display:flex;&#34;&gt;&lt;span&gt;    &lt;span style=&#34;color:#8839ef&#34;&gt;def&lt;/span&gt; &lt;span style=&#34;color:#1e66f5&#34;&gt;forward&lt;/span&gt;(&lt;span style=&#34;color:#04a5e5&#34;&gt;self&lt;/span&gt;, x: torch&lt;span style=&#34;color:#04a5e5;font-weight:bold&#34;&gt;.&lt;/span&gt;Tensor):&#xA;&lt;/span&gt;&lt;/span&gt;&lt;span style=&#34;display:flex;&#34;&gt;&lt;span&gt;        x &lt;span style=&#34;color:#04a5e5;font-weight:bold&#34;&gt;=&lt;/span&gt; &lt;span style=&#34;color:#04a5e5&#34;&gt;self&lt;/span&gt;&lt;span style=&#34;color:#04a5e5;font-weight:bold&#34;&gt;.&lt;/span&gt;conv1(x)  &lt;span style=&#34;color:#9ca0b0;font-style:italic&#34;&gt;# shape = [*, width, grid, grid]&lt;/span&gt;&#xA;&lt;/span&gt;&lt;/span&gt;&lt;span style=&#34;display:flex;&#34;&gt;&lt;span&gt;        x &lt;span style=&#34;color:#04a5e5;font-weight:bold&#34;&gt;=&lt;/span&gt; x&lt;span style=&#34;color:#04a5e5;font-weight:bold&#34;&gt;.&lt;/span&gt;reshape(x&lt;span style=&#34;color:#04a5e5;font-weight:bold&#34;&gt;.&lt;/span&gt;shape[&lt;span style=&#34;color:#fe640b&#34;&gt;0&lt;/span&gt;], x&lt;span style=&#34;color:#04a5e5;font-weight:bold&#34;&gt;.&lt;/span&gt;shape[&lt;span style=&#34;color:#fe640b&#34;&gt;1&lt;/span&gt;], &lt;span style=&#34;color:#04a5e5;font-weight:bold&#34;&gt;-&lt;/span&gt;&lt;span style=&#34;color:#fe640b&#34;&gt;1&lt;/span&gt;)  &lt;span style=&#34;color:#9ca0b0;font-style:italic&#34;&gt;# shape = [*, width, grid ** 2]&lt;/span&gt;&#xA;&lt;/span&gt;&lt;/span&gt;&lt;span style=&#34;display:flex;&#34;&gt;&lt;span&gt;        x &lt;span style=&#34;color:#04a5e5;font-weight:bold&#34;&gt;=&lt;/span&gt; x&lt;span style=&#34;color:#04a5e5;font-weight:bold&#34;&gt;.&lt;/span&gt;permute(&lt;span style=&#34;color:#fe640b&#34;&gt;0&lt;/span&gt;, &lt;span style=&#34;color:#fe640b&#34;&gt;2&lt;/span&gt;, &lt;span style=&#34;color:#fe640b&#34;&gt;1&lt;/span&gt;)  &lt;span style=&#34;color:#9ca0b0;font-style:italic&#34;&gt;# shape = [*, grid ** 2, width]&lt;/span&gt;&#xA;&lt;/span&gt;&lt;/span&gt;&lt;span style=&#34;display:flex;&#34;&gt;&lt;span&gt;        x &lt;span style=&#34;color:#04a5e5;font-weight:bold&#34;&gt;=&lt;/span&gt; torch&lt;span style=&#34;color:#04a5e5;font-weight:bold&#34;&gt;.&lt;/span&gt;cat([&lt;span style=&#34;color:#04a5e5&#34;&gt;self&lt;/span&gt;&lt;span style=&#34;color:#04a5e5;font-weight:bold&#34;&gt;.&lt;/span&gt;class_embedding&lt;span style=&#34;color:#04a5e5;font-weight:bold&#34;&gt;.&lt;/span&gt;to(x&lt;span style=&#34;color:#04a5e5;font-weight:bold&#34;&gt;.&lt;/span&gt;dtype) &lt;span style=&#34;color:#04a5e5;font-weight:bold&#34;&gt;+&lt;/span&gt; torch&lt;span style=&#34;color:#04a5e5;font-weight:bold&#34;&gt;.&lt;/span&gt;zeros(x&lt;span style=&#34;color:#04a5e5;font-weight:bold&#34;&gt;.&lt;/span&gt;shape[&lt;span style=&#34;color:#fe640b&#34;&gt;0&lt;/span&gt;], &lt;span style=&#34;color:#fe640b&#34;&gt;1&lt;/span&gt;, x&lt;span style=&#34;color:#04a5e5;font-weight:bold&#34;&gt;.&lt;/span&gt;shape[&lt;span style=&#34;color:#04a5e5;font-weight:bold&#34;&gt;-&lt;/span&gt;&lt;span style=&#34;color:#fe640b&#34;&gt;1&lt;/span&gt;], dtype&lt;span style=&#34;color:#04a5e5;font-weight:bold&#34;&gt;=&lt;/span&gt;x&lt;span style=&#34;color:#04a5e5;font-weight:bold&#34;&gt;.&lt;/span&gt;dtype, device&lt;span style=&#34;color:#04a5e5;font-weight:bold&#34;&gt;=&lt;/span&gt;x&lt;span style=&#34;color:#04a5e5;font-weight:bold&#34;&gt;.&lt;/span&gt;device), x], dim&lt;span style=&#34;color:#04a5e5;font-weight:bold&#34;&gt;=&lt;/span&gt;&lt;span style=&#34;color:#fe640b&#34;&gt;1&lt;/span&gt;)  &lt;span style=&#34;color:#9ca0b0;font-style:italic&#34;&gt;# shape = [*, grid ** 2 + 1, width]&lt;/span&gt;&#xA;&lt;/span&gt;&lt;/span&gt;&lt;span style=&#34;display:flex;&#34;&gt;&lt;span&gt;        x &lt;span style=&#34;color:#04a5e5;font-weight:bold&#34;&gt;=&lt;/span&gt; x &lt;span style=&#34;color:#04a5e5;font-weight:bold&#34;&gt;+&lt;/span&gt; &lt;span style=&#34;color:#04a5e5&#34;&gt;self&lt;/span&gt;&lt;span style=&#34;color:#04a5e5;font-weight:bold&#34;&gt;.&lt;/span&gt;positional_embedding&lt;span style=&#34;color:#04a5e5;font-weight:bold&#34;&gt;.&lt;/span&gt;to(x&lt;span style=&#34;color:#04a5e5;font-weight:bold&#34;&gt;.&lt;/span&gt;dtype)&#xA;&lt;/span&gt;&lt;/span&gt;&lt;span style=&#34;display:flex;&#34;&gt;&lt;span&gt;        x &lt;span style=&#34;color:#04a5e5;font-weight:bold&#34;&gt;=&lt;/span&gt; &lt;span style=&#34;color:#04a5e5&#34;&gt;self&lt;/span&gt;&lt;span style=&#34;color:#04a5e5;font-weight:bold&#34;&gt;.&lt;/span&gt;ln_pre(x)&#xA;&lt;/span&gt;&lt;/span&gt;&lt;span style=&#34;display:flex;&#34;&gt;&lt;span&gt;&#xA;&lt;/span&gt;&lt;/span&gt;&lt;span style=&#34;display:flex;&#34;&gt;&lt;span&gt;        x &lt;span style=&#34;color:#04a5e5;font-weight:bold&#34;&gt;=&lt;/span&gt; x&lt;span style=&#34;color:#04a5e5;font-weight:bold&#34;&gt;.&lt;/span&gt;permute(&lt;span style=&#34;color:#fe640b&#34;&gt;1&lt;/span&gt;, &lt;span style=&#34;color:#fe640b&#34;&gt;0&lt;/span&gt;, &lt;span style=&#34;color:#fe640b&#34;&gt;2&lt;/span&gt;)  &lt;span style=&#34;color:#9ca0b0;font-style:italic&#34;&gt;# NLD -&amp;gt; LND&lt;/span&gt;&#xA;&lt;/span&gt;&lt;/span&gt;&lt;span style=&#34;display:flex;&#34;&gt;&lt;span&gt;        x &lt;span style=&#34;color:#04a5e5;font-weight:bold&#34;&gt;=&lt;/span&gt; &lt;span style=&#34;color:#04a5e5&#34;&gt;self&lt;/span&gt;&lt;span style=&#34;color:#04a5e5;font-weight:bold&#34;&gt;.&lt;/span&gt;transformer(x)&#xA;&lt;/span&gt;&lt;/span&gt;&lt;span style=&#34;display:flex;&#34;&gt;&lt;span&gt;        x &lt;span style=&#34;color:#04a5e5;font-weight:bold&#34;&gt;=&lt;/span&gt; x&lt;span style=&#34;color:#04a5e5;font-weight:bold&#34;&gt;.&lt;/span&gt;permute(&lt;span style=&#34;color:#fe640b&#34;&gt;1&lt;/span&gt;, &lt;span style=&#34;color:#fe640b&#34;&gt;0&lt;/span&gt;, &lt;span style=&#34;color:#fe640b&#34;&gt;2&lt;/span&gt;)  &lt;span style=&#34;color:#9ca0b0;font-style:italic&#34;&gt;# LND -&amp;gt; NLD&lt;/span&gt;&#xA;&lt;/span&gt;&lt;/span&gt;&lt;span style=&#34;display:flex;&#34;&gt;&lt;span&gt;&#xA;&lt;/span&gt;&lt;/span&gt;&lt;span style=&#34;display:flex;&#34;&gt;&lt;span&gt;        x &lt;span style=&#34;color:#04a5e5;font-weight:bold&#34;&gt;=&lt;/span&gt; &lt;span style=&#34;color:#04a5e5&#34;&gt;self&lt;/span&gt;&lt;span style=&#34;color:#04a5e5;font-weight:bold&#34;&gt;.&lt;/span&gt;ln_post(x[:, &lt;span style=&#34;color:#fe640b&#34;&gt;0&lt;/span&gt;, :])&#xA;&lt;/span&gt;&lt;/span&gt;&lt;span style=&#34;display:flex;&#34;&gt;&lt;span&gt;&#xA;&lt;/span&gt;&lt;/span&gt;&lt;span style=&#34;display:flex;&#34;&gt;&lt;span&gt;        &lt;span style=&#34;color:#8839ef&#34;&gt;if&lt;/span&gt; &lt;span style=&#34;color:#04a5e5&#34;&gt;self&lt;/span&gt;&lt;span style=&#34;color:#04a5e5;font-weight:bold&#34;&gt;.&lt;/span&gt;proj &lt;span style=&#34;color:#04a5e5;font-weight:bold&#34;&gt;is&lt;/span&gt; &lt;span style=&#34;color:#04a5e5;font-weight:bold&#34;&gt;not&lt;/span&gt; &lt;span style=&#34;color:#fe640b&#34;&gt;None&lt;/span&gt;:&#xA;&lt;/span&gt;&lt;/span&gt;&lt;span style=&#34;display:flex;&#34;&gt;&lt;span&gt;            x &lt;span style=&#34;color:#04a5e5;font-weight:bold&#34;&gt;=&lt;/span&gt; x &lt;span style=&#34;color:#04a5e5;font-weight:bold&#34;&gt;@&lt;/span&gt; &lt;span style=&#34;color:#04a5e5&#34;&gt;self&lt;/span&gt;&lt;span style=&#34;color:#04a5e5;font-weight:bold&#34;&gt;.&lt;/span&gt;proj&#xA;&lt;/span&gt;&lt;/span&gt;&lt;span style=&#34;display:flex;&#34;&gt;&lt;span&gt;&#xA;&lt;/span&gt;&lt;/span&gt;&lt;span style=&#34;display:flex;&#34;&gt;&lt;span&gt;        &lt;span style=&#34;color:#8839ef&#34;&gt;return&lt;/span&gt; x&#xA;&lt;/span&gt;&lt;/span&gt;&lt;/code&gt;&lt;/pre&gt;&lt;/td&gt;&lt;/tr&gt;&lt;/table&gt;&#xA;&lt;/div&gt;&#xA;&lt;/div&gt;&lt;h4 id=&#34;text-encoder&#34;&gt;text encoder&lt;/h4&gt;&#xA;&lt;h4 id=&#34;embedding-space&#34;&gt;embedding space&lt;/h4&gt;</description>
    </item>
    <item>
      <title>Computer Vision</title>
      <link>https://ruokezhang.github.io/en/ai/computer_vision/</link>
      <pubDate>Sun, 24 May 2026 00:00:00 +0000</pubDate>
      <guid>https://ruokezhang.github.io/en/ai/computer_vision/</guid>
      <description>&lt;h2 id=&#34;vit&#34;&gt;ViT&lt;/h2&gt;&#xA;&lt;h3 id=&#34;funnel-vit&#34;&gt;Funnel ViT&lt;/h3&gt;&#xA;&lt;p&gt;&lt;a href=&#34;https://proceedings.neurips.cc/paper_files/paper/2020/file/2cd2915e69546904e4e5d4a2ac9e1652-Paper.pdf&#34;&gt;paper&lt;/a&gt;&lt;/p&gt;&#xA;&lt;h2 id=&#34;object-detection&#34;&gt;Object Detection&lt;/h2&gt;&#xA;&lt;p&gt;&lt;a href=&#34;https://cs231n.stanford.edu/slides/2026/lecture_9.pdf&#34;&gt;slides&lt;/a&gt;&lt;/p&gt;&#xA;&lt;h3 id=&#34;single-object&#34;&gt;Single Object&lt;/h3&gt;&#xA;&lt;p&gt;&lt;img src=&#34;https://blog-ruoke.oss-cn-hongkong.aliyuncs.com/blog/images/zh-cn/AI/single_object.png&#34; alt=&#34;alt text&#34;&gt;&lt;/p&gt;&#xA;&lt;ul&gt;&#xA;&lt;li&gt;The label is: Cat + (x&amp;rsquo;, y&amp;rsquo;, w&amp;rsquo;, h&#39;)&lt;/li&gt;&#xA;&lt;li&gt;x, y = the position of the box&amp;rsquo;s top-left corner, w = box width, h = box height; these are manually annotated&lt;/li&gt;&#xA;&lt;li&gt;The CNN turns the image into a 4096-dim vector&#xA;&lt;ul&gt;&#xA;&lt;li&gt;classification head: Fully connected, 4096 -&amp;gt; 1000, outputs scores for 1000 classes, then softmax&lt;/li&gt;&#xA;&lt;li&gt;localization head: Fully connected: 4096 -&amp;gt; 4, outputs predicted box = (x, y, w, h); these are &lt;strong&gt;continuous values&lt;/strong&gt;, using &lt;strong&gt;L2 loss&lt;/strong&gt;&lt;/li&gt;&#xA;&lt;li&gt;Total Loss = Softmax Loss + L2 Loss&lt;/li&gt;&#xA;&lt;/ul&gt;&#xA;&lt;/li&gt;&#xA;&lt;/ul&gt;&#xA;&lt;h3 id=&#34;r-cnn&#34;&gt;R-CNN&lt;/h3&gt;&#xA;&lt;p&gt;R-CNN uses &lt;strong&gt;Selective Search&lt;/strong&gt; to generate around 2000 &lt;strong&gt;region proposals&lt;/strong&gt;, warps each proposal to a fixed 224×224 image, then runs a CNN on each region to classify it and later refine the box.&lt;/p&gt;</description>
    </item>
    <item>
      <title>Machine Learning Basics</title>
      <link>https://ruokezhang.github.io/en/ai/ml_basic/</link>
      <pubDate>Wed, 20 May 2026 00:00:00 +0000</pubDate>
      <guid>https://ruokezhang.github.io/en/ai/ml_basic/</guid>
      <description>&lt;p&gt;&lt;a href=&#34;https://github.com/andrewekhalel/MLQuestions&#34;&gt;https://github.com/andrewekhalel/MLQuestions&lt;/a&gt;&#xA;&lt;a href=&#34;https://www.1point3acres.com/bbs/forum.php?mod=viewthread&amp;amp;tid=998257&amp;amp;page=1&amp;amp;extra=&#34;&gt;https://www.1point3acres.com/bbs/forum.php?mod=viewthread&amp;tid=998257&amp;page=1&amp;extra=&lt;/a&gt;&#xA;&lt;a href=&#34;https://longxingtan.gitbook.io/mle-interview/02_ml&#34;&gt;https://longxingtan.gitbook.io/mle-interview/02_ml&lt;/a&gt;&lt;/p&gt;&#xA;&lt;h2 id=&#34;supervised-learning&#34;&gt;supervised learning&lt;/h2&gt;&#xA;&lt;p&gt;training data includes both the input features and corresponding target labels&lt;/p&gt;&#xA;&lt;h3 id=&#34;classification&#34;&gt;classification&lt;/h3&gt;&#xA;&lt;h4 id=&#34;logistic-regression&#34;&gt;Logistic Regression&lt;/h4&gt;&#xA;&lt;p&gt;linear classification, binary classification&#xA;loss function: Binary Cross-Entropy Loss&lt;/p&gt;&#xA;&lt;p&gt;&lt;img src=&#34;https://blog-ruoke.oss-cn-hongkong.aliyuncs.com/blog/images/zh-cn/post/interview/images/logistic_regression.png&#34; alt=&#34;alt text&#34;&gt;&#xA;&lt;img src=&#34;https://blog-ruoke.oss-cn-hongkong.aliyuncs.com/blog/images/zh-cn/post/interview/images/logistic_regression_loss.png&#34; alt=&#34;alt text&#34;&gt;&lt;/p&gt;&#xA;&lt;blockquote&gt;&#xA;&lt;p&gt;Does logistic regression have a closed-form solution?&lt;/p&gt;&lt;/blockquote&gt;&#xA;&lt;p&gt;No, there is no closed-form solution. Although the loss function is convex, taking its derivative yields a &lt;strong&gt;nonlinear equation&lt;/strong&gt; containing an exponential term, so we cannot set the derivative to 0 and solve for closed-form expressions of w and b; we can only use gradient descent.&lt;/p&gt;</description>
    </item>
    <item>
      <title>PyTorch</title>
      <link>https://ruokezhang.github.io/en/ai/pytorch/</link>
      <pubDate>Sun, 12 Apr 2026 00:00:00 +0000</pubDate>
      <guid>https://ruokezhang.github.io/en/ai/pytorch/</guid>
      <description>&lt;h2 id=&#34;module&#34;&gt;Module&lt;/h2&gt;&#xA;&lt;p&gt;The parent class of all models; every network inherits from it&lt;/p&gt;&#xA;&lt;ul&gt;&#xA;&lt;li&gt;init(self)&lt;/li&gt;&#xA;&lt;li&gt;forward(self, x)&lt;/li&gt;&#xA;&lt;/ul&gt;&#xA;&lt;h2 id=&#34;conv&#34;&gt;conv&lt;/h2&gt;&#xA;&lt;p&gt;&lt;a href=&#34;https://www.bilibili.com/video/BV1hE411t7RN?spm_id_from=333.788.videopod.episodes&amp;amp;vd_source=512bb0b359ea7a5e16733b06bbe10478&amp;amp;p=18&#34;&gt;Bilibili&lt;/a&gt;&lt;/p&gt;&#xA;&lt;div class=&#34;highlight&#34;&gt;&lt;div style=&#34;color:#4c4f69;background-color:#eff1f5;-moz-tab-size:2;-o-tab-size:2;tab-size:2;&#34;&gt;&#xA;&lt;table style=&#34;border-spacing:0;padding:0;margin:0;border:0;&#34;&gt;&lt;tr&gt;&lt;td style=&#34;vertical-align:top;padding:0;margin:0;border:0;&#34;&gt;&#xA;&lt;pre tabindex=&#34;0&#34; style=&#34;color:#4c4f69;background-color:#eff1f5;-moz-tab-size:2;-o-tab-size:2;tab-size:2;&#34;&gt;&lt;code&gt;&lt;span style=&#34;white-space:pre;-webkit-user-select:none;user-select:none;margin-right:0.4em;padding:0 0.4em 0 0.4em;color:#8c8fa1&#34;&gt;1&#xA;&lt;/span&gt;&lt;/code&gt;&lt;/pre&gt;&lt;/td&gt;&#xA;&lt;td style=&#34;vertical-align:top;padding:0;margin:0;border:0;;width:100%&#34;&gt;&#xA;&lt;pre tabindex=&#34;0&#34; style=&#34;color:#4c4f69;background-color:#eff1f5;-moz-tab-size:2;-o-tab-size:2;tab-size:2;&#34;&gt;&lt;code class=&#34;language-py&#34; data-lang=&#34;py&#34;&gt;&lt;span style=&#34;display:flex;&#34;&gt;&lt;span&gt;output&lt;span style=&#34;color:#04a5e5;font-weight:bold&#34;&gt;=&lt;/span&gt;F&lt;span style=&#34;color:#04a5e5;font-weight:bold&#34;&gt;.&lt;/span&gt;conv2d(&lt;span style=&#34;color:#04a5e5&#34;&gt;input&lt;/span&gt;, kernel, stride&lt;span style=&#34;color:#04a5e5;font-weight:bold&#34;&gt;=&lt;/span&gt;&lt;span style=&#34;color:#fe640b&#34;&gt;1&lt;/span&gt;) &lt;span style=&#34;color:#9ca0b0;font-style:italic&#34;&gt;# performs the convolution computation, producing the feature matrix&lt;/span&gt;&#xA;&lt;/span&gt;&lt;/span&gt;&lt;/code&gt;&lt;/pre&gt;&lt;/td&gt;&lt;/tr&gt;&lt;/table&gt;&#xA;&lt;/div&gt;&#xA;&lt;/div&gt;&lt;p&gt;Conv2d&lt;/p&gt;&#xA;&lt;div class=&#34;highlight&#34;&gt;&lt;div style=&#34;color:#4c4f69;background-color:#eff1f5;-moz-tab-size:2;-o-tab-size:2;tab-size:2;&#34;&gt;&#xA;&lt;table style=&#34;border-spacing:0;padding:0;margin:0;border:0;&#34;&gt;&lt;tr&gt;&lt;td style=&#34;vertical-align:top;padding:0;margin:0;border:0;&#34;&gt;&#xA;&lt;pre tabindex=&#34;0&#34; style=&#34;color:#4c4f69;background-color:#eff1f5;-moz-tab-size:2;-o-tab-size:2;tab-size:2;&#34;&gt;&lt;code&gt;&lt;span style=&#34;white-space:pre;-webkit-user-select:none;user-select:none;margin-right:0.4em;padding:0 0.4em 0 0.4em;color:#8c8fa1&#34;&gt; 1&#xA;&lt;/span&gt;&lt;span style=&#34;white-space:pre;-webkit-user-select:none;user-select:none;margin-right:0.4em;padding:0 0.4em 0 0.4em;color:#8c8fa1&#34;&gt; 2&#xA;&lt;/span&gt;&lt;span style=&#34;white-space:pre;-webkit-user-select:none;user-select:none;margin-right:0.4em;padding:0 0.4em 0 0.4em;color:#8c8fa1&#34;&gt; 3&#xA;&lt;/span&gt;&lt;span style=&#34;white-space:pre;-webkit-user-select:none;user-select:none;margin-right:0.4em;padding:0 0.4em 0 0.4em;color:#8c8fa1&#34;&gt; 4&#xA;&lt;/span&gt;&lt;span style=&#34;white-space:pre;-webkit-user-select:none;user-select:none;margin-right:0.4em;padding:0 0.4em 0 0.4em;color:#8c8fa1&#34;&gt; 5&#xA;&lt;/span&gt;&lt;span style=&#34;white-space:pre;-webkit-user-select:none;user-select:none;margin-right:0.4em;padding:0 0.4em 0 0.4em;color:#8c8fa1&#34;&gt; 6&#xA;&lt;/span&gt;&lt;span style=&#34;white-space:pre;-webkit-user-select:none;user-select:none;margin-right:0.4em;padding:0 0.4em 0 0.4em;color:#8c8fa1&#34;&gt; 7&#xA;&lt;/span&gt;&lt;span style=&#34;white-space:pre;-webkit-user-select:none;user-select:none;margin-right:0.4em;padding:0 0.4em 0 0.4em;color:#8c8fa1&#34;&gt; 8&#xA;&lt;/span&gt;&lt;span style=&#34;white-space:pre;-webkit-user-select:none;user-select:none;margin-right:0.4em;padding:0 0.4em 0 0.4em;color:#8c8fa1&#34;&gt; 9&#xA;&lt;/span&gt;&lt;span style=&#34;white-space:pre;-webkit-user-select:none;user-select:none;margin-right:0.4em;padding:0 0.4em 0 0.4em;color:#8c8fa1&#34;&gt;10&#xA;&lt;/span&gt;&lt;span style=&#34;white-space:pre;-webkit-user-select:none;user-select:none;margin-right:0.4em;padding:0 0.4em 0 0.4em;color:#8c8fa1&#34;&gt;11&#xA;&lt;/span&gt;&lt;span style=&#34;white-space:pre;-webkit-user-select:none;user-select:none;margin-right:0.4em;padding:0 0.4em 0 0.4em;color:#8c8fa1&#34;&gt;12&#xA;&lt;/span&gt;&lt;span style=&#34;white-space:pre;-webkit-user-select:none;user-select:none;margin-right:0.4em;padding:0 0.4em 0 0.4em;color:#8c8fa1&#34;&gt;13&#xA;&lt;/span&gt;&lt;span style=&#34;white-space:pre;-webkit-user-select:none;user-select:none;margin-right:0.4em;padding:0 0.4em 0 0.4em;color:#8c8fa1&#34;&gt;14&#xA;&lt;/span&gt;&lt;span style=&#34;white-space:pre;-webkit-user-select:none;user-select:none;margin-right:0.4em;padding:0 0.4em 0 0.4em;color:#8c8fa1&#34;&gt;15&#xA;&lt;/span&gt;&lt;span style=&#34;white-space:pre;-webkit-user-select:none;user-select:none;margin-right:0.4em;padding:0 0.4em 0 0.4em;color:#8c8fa1&#34;&gt;16&#xA;&lt;/span&gt;&lt;span style=&#34;white-space:pre;-webkit-user-select:none;user-select:none;margin-right:0.4em;padding:0 0.4em 0 0.4em;color:#8c8fa1&#34;&gt;17&#xA;&lt;/span&gt;&lt;span style=&#34;white-space:pre;-webkit-user-select:none;user-select:none;margin-right:0.4em;padding:0 0.4em 0 0.4em;color:#8c8fa1&#34;&gt;18&#xA;&lt;/span&gt;&lt;span style=&#34;white-space:pre;-webkit-user-select:none;user-select:none;margin-right:0.4em;padding:0 0.4em 0 0.4em;color:#8c8fa1&#34;&gt;19&#xA;&lt;/span&gt;&lt;span style=&#34;white-space:pre;-webkit-user-select:none;user-select:none;margin-right:0.4em;padding:0 0.4em 0 0.4em;color:#8c8fa1&#34;&gt;20&#xA;&lt;/span&gt;&lt;span style=&#34;white-space:pre;-webkit-user-select:none;user-select:none;margin-right:0.4em;padding:0 0.4em 0 0.4em;color:#8c8fa1&#34;&gt;21&#xA;&lt;/span&gt;&lt;span style=&#34;white-space:pre;-webkit-user-select:none;user-select:none;margin-right:0.4em;padding:0 0.4em 0 0.4em;color:#8c8fa1&#34;&gt;22&#xA;&lt;/span&gt;&lt;span style=&#34;white-space:pre;-webkit-user-select:none;user-select:none;margin-right:0.4em;padding:0 0.4em 0 0.4em;color:#8c8fa1&#34;&gt;23&#xA;&lt;/span&gt;&lt;span style=&#34;white-space:pre;-webkit-user-select:none;user-select:none;margin-right:0.4em;padding:0 0.4em 0 0.4em;color:#8c8fa1&#34;&gt;24&#xA;&lt;/span&gt;&lt;span style=&#34;white-space:pre;-webkit-user-select:none;user-select:none;margin-right:0.4em;padding:0 0.4em 0 0.4em;color:#8c8fa1&#34;&gt;25&#xA;&lt;/span&gt;&lt;span style=&#34;white-space:pre;-webkit-user-select:none;user-select:none;margin-right:0.4em;padding:0 0.4em 0 0.4em;color:#8c8fa1&#34;&gt;26&#xA;&lt;/span&gt;&lt;span style=&#34;white-space:pre;-webkit-user-select:none;user-select:none;margin-right:0.4em;padding:0 0.4em 0 0.4em;color:#8c8fa1&#34;&gt;27&#xA;&lt;/span&gt;&lt;span style=&#34;white-space:pre;-webkit-user-select:none;user-select:none;margin-right:0.4em;padding:0 0.4em 0 0.4em;color:#8c8fa1&#34;&gt;28&#xA;&lt;/span&gt;&lt;/code&gt;&lt;/pre&gt;&lt;/td&gt;&#xA;&lt;td style=&#34;vertical-align:top;padding:0;margin:0;border:0;;width:100%&#34;&gt;&#xA;&lt;pre tabindex=&#34;0&#34; style=&#34;color:#4c4f69;background-color:#eff1f5;-moz-tab-size:2;-o-tab-size:2;tab-size:2;&#34;&gt;&lt;code class=&#34;language-py&#34; data-lang=&#34;py&#34;&gt;&lt;span style=&#34;display:flex;&#34;&gt;&lt;span&gt;&lt;span style=&#34;color:#179299&#34;&gt;import&lt;/span&gt; &lt;span style=&#34;color:#fe640b&#34;&gt;torch&lt;/span&gt;&#xA;&lt;/span&gt;&lt;/span&gt;&lt;span style=&#34;display:flex;&#34;&gt;&lt;span&gt;&lt;span style=&#34;color:#179299&#34;&gt;import&lt;/span&gt; &lt;span style=&#34;color:#fe640b&#34;&gt;torch.nn&lt;/span&gt; &lt;span style=&#34;color:#8839ef&#34;&gt;as&lt;/span&gt; &lt;span style=&#34;color:#fe640b&#34;&gt;nn&lt;/span&gt;&#xA;&lt;/span&gt;&lt;/span&gt;&lt;span style=&#34;display:flex;&#34;&gt;&lt;span&gt;&#xA;&lt;/span&gt;&lt;/span&gt;&lt;span style=&#34;display:flex;&#34;&gt;&lt;span&gt;&lt;span style=&#34;color:#8839ef&#34;&gt;class&lt;/span&gt; &lt;span style=&#34;color:#df8e1d&#34;&gt;CNN&lt;/span&gt;(nn&lt;span style=&#34;color:#04a5e5;font-weight:bold&#34;&gt;.&lt;/span&gt;Module):&#xA;&lt;/span&gt;&lt;/span&gt;&lt;span style=&#34;display:flex;&#34;&gt;&lt;span&gt;    &lt;span style=&#34;color:#8839ef&#34;&gt;def&lt;/span&gt; &lt;span style=&#34;color:#1e66f5&#34;&gt;__init__&lt;/span&gt;(&lt;span style=&#34;color:#04a5e5&#34;&gt;self&lt;/span&gt;):&#xA;&lt;/span&gt;&lt;/span&gt;&lt;span style=&#34;display:flex;&#34;&gt;&lt;span&gt;        &lt;span style=&#34;color:#04a5e5&#34;&gt;super&lt;/span&gt;()&lt;span style=&#34;color:#04a5e5;font-weight:bold&#34;&gt;.&lt;/span&gt;&lt;span style=&#34;color:#1e66f5&#34;&gt;__init__&lt;/span&gt;()&#xA;&lt;/span&gt;&lt;/span&gt;&lt;span style=&#34;display:flex;&#34;&gt;&lt;span&gt;&#xA;&lt;/span&gt;&lt;/span&gt;&lt;span style=&#34;display:flex;&#34;&gt;&lt;span&gt;        &lt;span style=&#34;color:#04a5e5&#34;&gt;self&lt;/span&gt;&lt;span style=&#34;color:#04a5e5;font-weight:bold&#34;&gt;.&lt;/span&gt;conv1 &lt;span style=&#34;color:#04a5e5;font-weight:bold&#34;&gt;=&lt;/span&gt; nn&lt;span style=&#34;color:#04a5e5;font-weight:bold&#34;&gt;.&lt;/span&gt;Conv2d(&#xA;&lt;/span&gt;&lt;/span&gt;&lt;span style=&#34;display:flex;&#34;&gt;&lt;span&gt;            in_channels&lt;span style=&#34;color:#04a5e5;font-weight:bold&#34;&gt;=&lt;/span&gt;&lt;span style=&#34;color:#fe640b&#34;&gt;3&lt;/span&gt;,&#xA;&lt;/span&gt;&lt;/span&gt;&lt;span style=&#34;display:flex;&#34;&gt;&lt;span&gt;            out_channels&lt;span style=&#34;color:#04a5e5;font-weight:bold&#34;&gt;=&lt;/span&gt;&lt;span style=&#34;color:#fe640b&#34;&gt;6&lt;/span&gt;,&#xA;&lt;/span&gt;&lt;/span&gt;&lt;span style=&#34;display:flex;&#34;&gt;&lt;span&gt;            kernel_size&lt;span style=&#34;color:#04a5e5;font-weight:bold&#34;&gt;=&lt;/span&gt;&lt;span style=&#34;color:#fe640b&#34;&gt;3&lt;/span&gt;,&#xA;&lt;/span&gt;&lt;/span&gt;&lt;span style=&#34;display:flex;&#34;&gt;&lt;span&gt;            stride&lt;span style=&#34;color:#04a5e5;font-weight:bold&#34;&gt;=&lt;/span&gt;&lt;span style=&#34;color:#fe640b&#34;&gt;1&lt;/span&gt;,&#xA;&lt;/span&gt;&lt;/span&gt;&lt;span style=&#34;display:flex;&#34;&gt;&lt;span&gt;            padding&lt;span style=&#34;color:#04a5e5;font-weight:bold&#34;&gt;=&lt;/span&gt;&lt;span style=&#34;color:#fe640b&#34;&gt;0&lt;/span&gt;&#xA;&lt;/span&gt;&lt;/span&gt;&lt;span style=&#34;display:flex;&#34;&gt;&lt;span&gt;        )&#xA;&lt;/span&gt;&lt;/span&gt;&lt;span style=&#34;display:flex;&#34;&gt;&lt;span&gt;&#xA;&lt;/span&gt;&lt;/span&gt;&lt;span style=&#34;display:flex;&#34;&gt;&lt;span&gt;        &lt;span style=&#34;color:#04a5e5&#34;&gt;self&lt;/span&gt;&lt;span style=&#34;color:#04a5e5;font-weight:bold&#34;&gt;.&lt;/span&gt;maxpool1 &lt;span style=&#34;color:#04a5e5;font-weight:bold&#34;&gt;=&lt;/span&gt; nn&lt;span style=&#34;color:#04a5e5;font-weight:bold&#34;&gt;.&lt;/span&gt;MaxPool2d(&#xA;&lt;/span&gt;&lt;/span&gt;&lt;span style=&#34;display:flex;&#34;&gt;&lt;span&gt;            kernel_size&lt;span style=&#34;color:#04a5e5;font-weight:bold&#34;&gt;=&lt;/span&gt;&lt;span style=&#34;color:#fe640b&#34;&gt;3&lt;/span&gt;,  &lt;span style=&#34;color:#9ca0b0;font-style:italic&#34;&gt;# Pooling window size: 3×3&lt;/span&gt;&#xA;&lt;/span&gt;&lt;/span&gt;&lt;span style=&#34;display:flex;&#34;&gt;&lt;span&gt;            ceil_mode&lt;span style=&#34;color:#04a5e5;font-weight:bold&#34;&gt;=&lt;/span&gt;&lt;span style=&#34;color:#fe640b&#34;&gt;True&lt;/span&gt;  &lt;span style=&#34;color:#9ca0b0;font-style:italic&#34;&gt;# Ceiling mode, keeps incomplete edge windows&lt;/span&gt;&#xA;&lt;/span&gt;&lt;/span&gt;&lt;span style=&#34;display:flex;&#34;&gt;&lt;span&gt;            &lt;span style=&#34;color:#9ca0b0;font-style:italic&#34;&gt;# stride defaults to kernel_size=3; you can also explicitly write stride=3, with exactly the same effect&lt;/span&gt;&#xA;&lt;/span&gt;&lt;/span&gt;&lt;span style=&#34;display:flex;&#34;&gt;&lt;span&gt;        )&#xA;&lt;/span&gt;&lt;/span&gt;&lt;span style=&#34;display:flex;&#34;&gt;&lt;span&gt;&#xA;&lt;/span&gt;&lt;/span&gt;&lt;span style=&#34;display:flex;&#34;&gt;&lt;span&gt;    &lt;span style=&#34;color:#8839ef&#34;&gt;def&lt;/span&gt; &lt;span style=&#34;color:#1e66f5&#34;&gt;forward&lt;/span&gt;(&lt;span style=&#34;color:#04a5e5&#34;&gt;self&lt;/span&gt;, x):&#xA;&lt;/span&gt;&lt;/span&gt;&lt;span style=&#34;display:flex;&#34;&gt;&lt;span&gt;        &lt;span style=&#34;color:#9ca0b0;font-style:italic&#34;&gt;# Forward pass: **first convolve to extract features, then pool to downsample** (standard CNN order)&lt;/span&gt;&#xA;&lt;/span&gt;&lt;/span&gt;&lt;span style=&#34;display:flex;&#34;&gt;&lt;span&gt;        &lt;span style=&#34;color:#9ca0b0;font-style:italic&#34;&gt;# x: [b, 3, h, w]&lt;/span&gt;&#xA;&lt;/span&gt;&lt;/span&gt;&lt;span style=&#34;display:flex;&#34;&gt;&lt;span&gt;        x &lt;span style=&#34;color:#04a5e5;font-weight:bold&#34;&gt;=&lt;/span&gt; &lt;span style=&#34;color:#04a5e5&#34;&gt;self&lt;/span&gt;&lt;span style=&#34;color:#04a5e5;font-weight:bold&#34;&gt;.&lt;/span&gt;conv1(x)       &lt;span style=&#34;color:#9ca0b0;font-style:italic&#34;&gt;# Step 1: pass through the conv layer, producing a 6-channel feature map, [b, 6, h&amp;#39;, w&amp;#39;]&lt;/span&gt;&#xA;&lt;/span&gt;&lt;/span&gt;&lt;span style=&#34;display:flex;&#34;&gt;&lt;span&gt;        &lt;span style=&#34;color:#9ca0b0;font-style:italic&#34;&gt;# h&amp;#39;=(h+2*p-k)/s+1&lt;/span&gt;&#xA;&lt;/span&gt;&lt;/span&gt;&lt;span style=&#34;display:flex;&#34;&gt;&lt;span&gt;        x &lt;span style=&#34;color:#04a5e5;font-weight:bold&#34;&gt;=&lt;/span&gt; &lt;span style=&#34;color:#04a5e5&#34;&gt;self&lt;/span&gt;&lt;span style=&#34;color:#04a5e5;font-weight:bold&#34;&gt;.&lt;/span&gt;maxpool1(x)    &lt;span style=&#34;color:#9ca0b0;font-style:italic&#34;&gt;# Step 2: pass through the pooling layer, downsampling the feature map&lt;/span&gt;&#xA;&lt;/span&gt;&lt;/span&gt;&lt;span style=&#34;display:flex;&#34;&gt;&lt;span&gt;        &lt;span style=&#34;color:#8839ef&#34;&gt;return&lt;/span&gt; x&#xA;&lt;/span&gt;&lt;/span&gt;&lt;/code&gt;&lt;/pre&gt;&lt;/td&gt;&lt;/tr&gt;&lt;/table&gt;&#xA;&lt;/div&gt;&#xA;&lt;/div&gt;&lt;h2 id=&#34;linear&#34;&gt;Linear&lt;/h2&gt;&#xA;&lt;div class=&#34;highlight&#34;&gt;&lt;div style=&#34;color:#4c4f69;background-color:#eff1f5;-moz-tab-size:2;-o-tab-size:2;tab-size:2;&#34;&gt;&#xA;&lt;table style=&#34;border-spacing:0;padding:0;margin:0;border:0;&#34;&gt;&lt;tr&gt;&lt;td style=&#34;vertical-align:top;padding:0;margin:0;border:0;&#34;&gt;&#xA;&lt;pre tabindex=&#34;0&#34; style=&#34;color:#4c4f69;background-color:#eff1f5;-moz-tab-size:2;-o-tab-size:2;tab-size:2;&#34;&gt;&lt;code&gt;&lt;span style=&#34;white-space:pre;-webkit-user-select:none;user-select:none;margin-right:0.4em;padding:0 0.4em 0 0.4em;color:#8c8fa1&#34;&gt;1&#xA;&lt;/span&gt;&lt;span style=&#34;white-space:pre;-webkit-user-select:none;user-select:none;margin-right:0.4em;padding:0 0.4em 0 0.4em;color:#8c8fa1&#34;&gt;2&#xA;&lt;/span&gt;&lt;span style=&#34;white-space:pre;-webkit-user-select:none;user-select:none;margin-right:0.4em;padding:0 0.4em 0 0.4em;color:#8c8fa1&#34;&gt;3&#xA;&lt;/span&gt;&lt;span style=&#34;white-space:pre;-webkit-user-select:none;user-select:none;margin-right:0.4em;padding:0 0.4em 0 0.4em;color:#8c8fa1&#34;&gt;4&#xA;&lt;/span&gt;&lt;span style=&#34;white-space:pre;-webkit-user-select:none;user-select:none;margin-right:0.4em;padding:0 0.4em 0 0.4em;color:#8c8fa1&#34;&gt;5&#xA;&lt;/span&gt;&lt;/code&gt;&lt;/pre&gt;&lt;/td&gt;&#xA;&lt;td style=&#34;vertical-align:top;padding:0;margin:0;border:0;;width:100%&#34;&gt;&#xA;&lt;pre tabindex=&#34;0&#34; style=&#34;color:#4c4f69;background-color:#eff1f5;-moz-tab-size:2;-o-tab-size:2;tab-size:2;&#34;&gt;&lt;code class=&#34;language-py&#34; data-lang=&#34;py&#34;&gt;&lt;span style=&#34;display:flex;&#34;&gt;&lt;span&gt;&lt;span style=&#34;color:#04a5e5&#34;&gt;self&lt;/span&gt;&lt;span style=&#34;color:#04a5e5;font-weight:bold&#34;&gt;.&lt;/span&gt;linear &lt;span style=&#34;color:#04a5e5;font-weight:bold&#34;&gt;=&lt;/span&gt; nn&lt;span style=&#34;color:#04a5e5;font-weight:bold&#34;&gt;.&lt;/span&gt;Linear(&#xA;&lt;/span&gt;&lt;/span&gt;&lt;span style=&#34;display:flex;&#34;&gt;&lt;span&gt;    in_features&lt;span style=&#34;color:#04a5e5;font-weight:bold&#34;&gt;=&lt;/span&gt;&lt;span style=&#34;color:#fe640b&#34;&gt;1024&lt;/span&gt;,&#xA;&lt;/span&gt;&lt;/span&gt;&lt;span style=&#34;display:flex;&#34;&gt;&lt;span&gt;    out_features&lt;span style=&#34;color:#04a5e5;font-weight:bold&#34;&gt;=&lt;/span&gt;&lt;span style=&#34;color:#fe640b&#34;&gt;512&lt;/span&gt;,&#xA;&lt;/span&gt;&lt;/span&gt;&lt;span style=&#34;display:flex;&#34;&gt;&lt;span&gt;    bias&lt;span style=&#34;color:#04a5e5;font-weight:bold&#34;&gt;=&lt;/span&gt;&lt;span style=&#34;color:#fe640b&#34;&gt;True&lt;/span&gt;        &lt;span style=&#34;color:#9ca0b0;font-style:italic&#34;&gt;# Default True; whether to add the bias b&lt;/span&gt;&#xA;&lt;/span&gt;&lt;/span&gt;&lt;span style=&#34;display:flex;&#34;&gt;&lt;span&gt;)&#xA;&lt;/span&gt;&lt;/span&gt;&lt;/code&gt;&lt;/pre&gt;&lt;/td&gt;&lt;/tr&gt;&lt;/table&gt;&#xA;&lt;/div&gt;&#xA;&lt;/div&gt;&lt;p&gt;weight = (512, 1024)&#xA;bias = (512)&#xA;y = x @ W.T + b&lt;/p&gt;</description>
    </item>
    <item>
      <title>Distributed Systems</title>
      <link>https://ruokezhang.github.io/en/post/course_notes/distributed_systems/</link>
      <pubDate>Thu, 08 Jan 2026 00:00:00 +0000</pubDate>
      <guid>https://ruokezhang.github.io/en/post/course_notes/distributed_systems/</guid>
      <description>&lt;h2 id=&#34;rpc-basics&#34;&gt;RPC Basics&lt;/h2&gt;&#xA;&lt;p&gt;protobuf IDL&lt;/p&gt;&#xA;&lt;ol&gt;&#xA;&lt;li&gt;Define the &lt;code&gt;.proto&lt;/code&gt; file: define Request/Response formats and function signatures.&lt;/li&gt;&#xA;&lt;li&gt;Protobuf generates &lt;code&gt;CalculatorStub&lt;/code&gt; automatically.&#xA;&lt;div class=&#34;highlight&#34;&gt;&lt;div style=&#34;color:#4c4f69;background-color:#eff1f5;-moz-tab-size:2;-o-tab-size:2;tab-size:2;&#34;&gt;&#xA;&lt;table style=&#34;border-spacing:0;padding:0;margin:0;border:0;&#34;&gt;&lt;tr&gt;&lt;td style=&#34;vertical-align:top;padding:0;margin:0;border:0;&#34;&gt;&#xA;&lt;pre tabindex=&#34;0&#34; style=&#34;color:#4c4f69;background-color:#eff1f5;-moz-tab-size:2;-o-tab-size:2;tab-size:2;&#34;&gt;&lt;code&gt;&lt;span style=&#34;white-space:pre;-webkit-user-select:none;user-select:none;margin-right:0.4em;padding:0 0.4em 0 0.4em;color:#8c8fa1&#34;&gt;1&#xA;&lt;/span&gt;&lt;span style=&#34;white-space:pre;-webkit-user-select:none;user-select:none;margin-right:0.4em;padding:0 0.4em 0 0.4em;color:#8c8fa1&#34;&gt;2&#xA;&lt;/span&gt;&lt;span style=&#34;white-space:pre;-webkit-user-select:none;user-select:none;margin-right:0.4em;padding:0 0.4em 0 0.4em;color:#8c8fa1&#34;&gt;3&#xA;&lt;/span&gt;&lt;span style=&#34;white-space:pre;-webkit-user-select:none;user-select:none;margin-right:0.4em;padding:0 0.4em 0 0.4em;color:#8c8fa1&#34;&gt;4&#xA;&lt;/span&gt;&lt;span style=&#34;white-space:pre;-webkit-user-select:none;user-select:none;margin-right:0.4em;padding:0 0.4em 0 0.4em;color:#8c8fa1&#34;&gt;5&#xA;&lt;/span&gt;&lt;span style=&#34;white-space:pre;-webkit-user-select:none;user-select:none;margin-right:0.4em;padding:0 0.4em 0 0.4em;color:#8c8fa1&#34;&gt;6&#xA;&lt;/span&gt;&lt;span style=&#34;white-space:pre;-webkit-user-select:none;user-select:none;margin-right:0.4em;padding:0 0.4em 0 0.4em;color:#8c8fa1&#34;&gt;7&#xA;&lt;/span&gt;&lt;span style=&#34;white-space:pre;-webkit-user-select:none;user-select:none;margin-right:0.4em;padding:0 0.4em 0 0.4em;color:#8c8fa1&#34;&gt;8&#xA;&lt;/span&gt;&lt;/code&gt;&lt;/pre&gt;&lt;/td&gt;&#xA;&lt;td style=&#34;vertical-align:top;padding:0;margin:0;border:0;;width:100%&#34;&gt;&#xA;&lt;pre tabindex=&#34;0&#34; style=&#34;color:#4c4f69;background-color:#eff1f5;-moz-tab-size:2;-o-tab-size:2;tab-size:2;&#34;&gt;&lt;code class=&#34;language-java&#34; data-lang=&#34;java&#34;&gt;&lt;span style=&#34;display:flex;&#34;&gt;&lt;span&gt;channel &lt;span style=&#34;color:#04a5e5;font-weight:bold&#34;&gt;=&lt;/span&gt; grpc.&lt;span style=&#34;color:#1e66f5&#34;&gt;insecure_channel&lt;/span&gt;(&lt;span style=&#34;color:#40a02b&#34;&gt;&amp;#34;server-ip:port&amp;#34;&lt;/span&gt;)&#xA;&lt;/span&gt;&lt;/span&gt;&lt;span style=&#34;display:flex;&#34;&gt;&lt;span&gt;&#xA;&lt;/span&gt;&lt;/span&gt;&lt;span style=&#34;display:flex;&#34;&gt;&lt;span&gt;&lt;span style=&#34;color:#d20f39&#34;&gt;#&lt;/span&gt; Client &lt;span style=&#34;color:#1e66f5&#34;&gt;stub&lt;/span&gt; (a local proxy &lt;span style=&#34;color:#8839ef&#34;&gt;for&lt;/span&gt; server&lt;span style=&#34;color:#04a5e5;font-weight:bold&#34;&gt;-&lt;/span&gt;side methods)&#xA;&lt;/span&gt;&lt;/span&gt;&lt;span style=&#34;display:flex;&#34;&gt;&lt;span&gt;stub &lt;span style=&#34;color:#04a5e5;font-weight:bold&#34;&gt;=&lt;/span&gt; CalculatorStub(channel)&#xA;&lt;/span&gt;&lt;/span&gt;&lt;span style=&#34;display:flex;&#34;&gt;&lt;span&gt;&#xA;&lt;/span&gt;&lt;/span&gt;&lt;span style=&#34;display:flex;&#34;&gt;&lt;span&gt;&lt;span style=&#34;color:#d20f39&#34;&gt;#&lt;/span&gt; Call Stub.&lt;span style=&#34;color:#1e66f5&#34;&gt;Add&lt;/span&gt; as &lt;span style=&#34;color:#8839ef&#34;&gt;if&lt;/span&gt; it were a local function&#xA;&lt;/span&gt;&lt;/span&gt;&lt;span style=&#34;display:flex;&#34;&gt;&lt;span&gt;request &lt;span style=&#34;color:#04a5e5;font-weight:bold&#34;&gt;=&lt;/span&gt; AddRequest(num1&lt;span style=&#34;color:#04a5e5;font-weight:bold&#34;&gt;=&lt;/span&gt;2, num2&lt;span style=&#34;color:#04a5e5;font-weight:bold&#34;&gt;=&lt;/span&gt;3)&#xA;&lt;/span&gt;&lt;/span&gt;&lt;span style=&#34;display:flex;&#34;&gt;&lt;span&gt;response &lt;span style=&#34;color:#04a5e5;font-weight:bold&#34;&gt;=&lt;/span&gt; stub.&lt;span style=&#34;color:#1e66f5&#34;&gt;Add&lt;/span&gt;(request)&#xA;&lt;/span&gt;&lt;/span&gt;&lt;/code&gt;&lt;/pre&gt;&lt;/td&gt;&lt;/tr&gt;&lt;/table&gt;&#xA;&lt;/div&gt;&#xA;&lt;/div&gt;&lt;/li&gt;&#xA;&lt;li&gt;Implement the actual logic for &lt;code&gt;add&lt;/code&gt; on the server side.&lt;/li&gt;&#xA;&lt;/ol&gt;&#xA;&lt;h3 id=&#34;semantics&#34;&gt;Semantics&lt;/h3&gt;&#xA;&lt;p&gt;At most once&lt;/p&gt;</description>
    </item>
    <item>
      <title>File Systems and I/O Models</title>
      <link>https://ruokezhang.github.io/en/post/os/file_system/</link>
      <pubDate>Mon, 05 Jan 2026 00:00:00 +0000</pubDate>
      <guid>https://ruokezhang.github.io/en/post/os/file_system/</guid>
      <description>&lt;h2 id=&#34;file-systems&#34;&gt;File Systems&lt;/h2&gt;&#xA;&lt;h3 id=&#34;inodes&#34;&gt;Inodes&lt;/h3&gt;&#xA;&lt;p&gt;An inode identifies a file within one file system. It stores metadata such as:&lt;/p&gt;&#xA;&lt;ul&gt;&#xA;&lt;li&gt;Permissions, owner UID, and group GID&lt;/li&gt;&#xA;&lt;li&gt;File size and timestamps: &lt;code&gt;ctime&lt;/code&gt; for metadata changes, &lt;code&gt;mtime&lt;/code&gt; for content changes, and &lt;code&gt;atime&lt;/code&gt; for access&lt;/li&gt;&#xA;&lt;li&gt;Pointers to data blocks&lt;/li&gt;&#xA;&lt;li&gt;A link count, which tracks hard links to the inode&lt;/li&gt;&#xA;&lt;/ul&gt;&#xA;&lt;p&gt;To read a regular file, the OS resolves each component of its path through directory entries, finds the file&amp;rsquo;s inode, and uses its block pointers to locate the data. A symbolic link has its own inode and contains a target path, which the OS resolves in turn.&lt;/p&gt;</description>
    </item>
    <item>
      <title>Java RPC: Transport, Discovery, and Reliability</title>
      <link>https://ruokezhang.github.io/en/post/personal_projects/java_rpc/</link>
      <pubDate>Tue, 30 Dec 2025 00:00:00 +0000</pubDate>
      <guid>https://ruokezhang.github.io/en/post/personal_projects/java_rpc/</guid>
      <description>&lt;h2 id=&#34;rpc-and-http&#34;&gt;RPC and HTTP&lt;/h2&gt;&#xA;&lt;p&gt;In this project, the RPC protocol uses a small, customizable message header. Providers register themselves when they start, and consumers discover their addresses through a registry. The client handles load balancing, retries, and circuit breaking; the server applies rate limiting.&lt;/p&gt;&#xA;&lt;h2 id=&#34;serialization&#34;&gt;Serialization&lt;/h2&gt;&#xA;&lt;h3 id=&#34;kryo&#34;&gt;Kryo&lt;/h3&gt;&#xA;&lt;p&gt;Kryo serializes Java objects compactly and quickly, but a Kryo instance is not thread-safe. Registering a class assigns it an ID, so a serialized message can refer to that ID rather than repeatedly writing the full class name:&lt;/p&gt;</description>
    </item>
    <item>
      <title>About</title>
      <link>https://ruokezhang.github.io/en/about/</link>
      <pubDate>Sun, 07 Sep 2025 00:00:00 +0000</pubDate>
      <guid>https://ruokezhang.github.io/en/about/</guid>
      <description>&lt;h1 id=&#34;about-me&#34;&gt;About Me&lt;/h1&gt;&#xA;&lt;p&gt;I am transitioning from software engineering to machine learning.&lt;/p&gt;&#xA;&lt;ul&gt;&#xA;&lt;li&gt;&lt;strong&gt;Current interest:&lt;/strong&gt; Agentic AI&lt;/li&gt;&#xA;&lt;li&gt;I enjoy learning on my own and exploring new tools.&lt;/li&gt;&#xA;&lt;/ul&gt;&#xA;&lt;p&gt;2025-2027: Master of Science, Electrical and Computer Engineering, University of Washington&lt;/p&gt;&#xA;&lt;p&gt;2021-2024: Dual Bachelor of Science in Mathematics and Computer Science, The Ohio State University&lt;/p&gt;&#xA;&lt;p&gt;2019-2021: B.S. in Mathematics (transferred out), Hefei University of Technology&lt;/p&gt;&#xA;&lt;p&gt;2016-2019: Wuhan Foreign Languages School&lt;/p&gt;&#xA;&lt;h2 id=&#34;contact&#34;&gt;Contact&lt;/h2&gt;&#xA;&lt;ul&gt;&#xA;&lt;li&gt;GitHub: &lt;a href=&#34;https://github.com/RuokeZhang&#34;&gt;RuokeZhang&lt;/a&gt;&lt;/li&gt;&#xA;&lt;li&gt;LinkedIn: &lt;a href=&#34;https://www.linkedin.com/in/ruoke027/&#34;&gt;Ruoke Zhang&lt;/a&gt;&lt;/li&gt;&#xA;&lt;/ul&gt;</description>
    </item>
    <item>
      <title>Bit Manipulation</title>
      <link>https://ruokezhang.github.io/en/post/leetcode/bit_manipulation/</link>
      <pubDate>Fri, 05 Sep 2025 00:00:00 +0000</pubDate>
      <guid>https://ruokezhang.github.io/en/post/leetcode/bit_manipulation/</guid>
      <description>&lt;h2 id=&#34;common-operations&#34;&gt;Common Operations&lt;/h2&gt;&#xA;&lt;p&gt;x.bit_count(): Returns the number of 1s in the binary representation of x. Can also be interpreted as the minimum number of powers of 2 needed to represent x.&lt;/p&gt;&#xA;&lt;h2 id=&#34;brain-teasers&#34;&gt;Brain Teasers&lt;/h2&gt;&#xA;&lt;h4 id=&#34;2749-minimum-operations-to-make-the-integer-zero&#34;&gt;2749. Minimum Operations to Make the Integer Zero&lt;/h4&gt;&#xA;&lt;p&gt;Let x = num1 - k * num2, then the problem transforms to: Can x be represented using k powers of 2 (duplicates allowed)?&lt;/p&gt;&#xA;&lt;p&gt;Find the upper and lower bounds of x and enumerate. Plot x = num1 - k * num2 with k as x-axis and x as y-axis. The answer lies in some points on this line in the first quadrant. Analyze the equation x=2^(i1)+&amp;hellip;2^(ik) to find possible x values.&lt;/p&gt;</description>
    </item>
    <item>
      <title>Math</title>
      <link>https://ruokezhang.github.io/en/post/leetcode/math/</link>
      <pubDate>Mon, 01 Sep 2025 00:00:00 +0000</pubDate>
      <guid>https://ruokezhang.github.io/en/post/leetcode/math/</guid>
      <description>&lt;h2 id=&#34;prime-numbers&#34;&gt;Prime Numbers&lt;/h2&gt;&#xA;&lt;h3 id=&#34;sieve-of-eratosthenes&#34;&gt;Sieve of Eratosthenes&lt;/h3&gt;&#xA;&lt;div class=&#34;highlight&#34;&gt;&lt;div style=&#34;color:#4c4f69;background-color:#eff1f5;-moz-tab-size:2;-o-tab-size:2;tab-size:2;&#34;&gt;&#xA;&lt;table style=&#34;border-spacing:0;padding:0;margin:0;border:0;&#34;&gt;&lt;tr&gt;&lt;td style=&#34;vertical-align:top;padding:0;margin:0;border:0;&#34;&gt;&#xA;&lt;pre tabindex=&#34;0&#34; style=&#34;color:#4c4f69;background-color:#eff1f5;-moz-tab-size:2;-o-tab-size:2;tab-size:2;&#34;&gt;&lt;code&gt;&lt;span style=&#34;white-space:pre;-webkit-user-select:none;user-select:none;margin-right:0.4em;padding:0 0.4em 0 0.4em;color:#8c8fa1&#34;&gt;1&#xA;&lt;/span&gt;&lt;span style=&#34;white-space:pre;-webkit-user-select:none;user-select:none;margin-right:0.4em;padding:0 0.4em 0 0.4em;color:#8c8fa1&#34;&gt;2&#xA;&lt;/span&gt;&lt;span style=&#34;white-space:pre;-webkit-user-select:none;user-select:none;margin-right:0.4em;padding:0 0.4em 0 0.4em;color:#8c8fa1&#34;&gt;3&#xA;&lt;/span&gt;&lt;span style=&#34;white-space:pre;-webkit-user-select:none;user-select:none;margin-right:0.4em;padding:0 0.4em 0 0.4em;color:#8c8fa1&#34;&gt;4&#xA;&lt;/span&gt;&lt;span style=&#34;white-space:pre;-webkit-user-select:none;user-select:none;margin-right:0.4em;padding:0 0.4em 0 0.4em;color:#8c8fa1&#34;&gt;5&#xA;&lt;/span&gt;&lt;span style=&#34;white-space:pre;-webkit-user-select:none;user-select:none;margin-right:0.4em;padding:0 0.4em 0 0.4em;color:#8c8fa1&#34;&gt;6&#xA;&lt;/span&gt;&lt;span style=&#34;white-space:pre;-webkit-user-select:none;user-select:none;margin-right:0.4em;padding:0 0.4em 0 0.4em;color:#8c8fa1&#34;&gt;7&#xA;&lt;/span&gt;&lt;span style=&#34;white-space:pre;-webkit-user-select:none;user-select:none;margin-right:0.4em;padding:0 0.4em 0 0.4em;color:#8c8fa1&#34;&gt;8&#xA;&lt;/span&gt;&lt;span style=&#34;white-space:pre;-webkit-user-select:none;user-select:none;margin-right:0.4em;padding:0 0.4em 0 0.4em;color:#8c8fa1&#34;&gt;9&#xA;&lt;/span&gt;&lt;/code&gt;&lt;/pre&gt;&lt;/td&gt;&#xA;&lt;td style=&#34;vertical-align:top;padding:0;margin:0;border:0;;width:100%&#34;&gt;&#xA;&lt;pre tabindex=&#34;0&#34; style=&#34;color:#4c4f69;background-color:#eff1f5;-moz-tab-size:2;-o-tab-size:2;tab-size:2;&#34;&gt;&lt;code class=&#34;language-python&#34; data-lang=&#34;python&#34;&gt;&lt;span style=&#34;display:flex;&#34;&gt;&lt;span&gt;&lt;span style=&#34;color:#9ca0b0;font-style:italic&#34;&gt;# Time complexity O(MX * log log MX)&lt;/span&gt;&#xA;&lt;/span&gt;&lt;/span&gt;&lt;span style=&#34;display:flex;&#34;&gt;&lt;span&gt;MX &lt;span style=&#34;color:#04a5e5;font-weight:bold&#34;&gt;=&lt;/span&gt; &lt;span style=&#34;color:#fe640b&#34;&gt;1_000_001&lt;/span&gt;&#xA;&lt;/span&gt;&lt;/span&gt;&lt;span style=&#34;display:flex;&#34;&gt;&lt;span&gt;is_prime &lt;span style=&#34;color:#04a5e5;font-weight:bold&#34;&gt;=&lt;/span&gt; [&lt;span style=&#34;color:#fe640b&#34;&gt;False&lt;/span&gt;] &lt;span style=&#34;color:#04a5e5;font-weight:bold&#34;&gt;*&lt;/span&gt; &lt;span style=&#34;color:#fe640b&#34;&gt;2&lt;/span&gt; &lt;span style=&#34;color:#04a5e5;font-weight:bold&#34;&gt;+&lt;/span&gt; [&lt;span style=&#34;color:#fe640b&#34;&gt;True&lt;/span&gt;] &lt;span style=&#34;color:#04a5e5;font-weight:bold&#34;&gt;*&lt;/span&gt; (MX &lt;span style=&#34;color:#04a5e5;font-weight:bold&#34;&gt;-&lt;/span&gt; &lt;span style=&#34;color:#fe640b&#34;&gt;2&lt;/span&gt;)  &lt;span style=&#34;color:#9ca0b0;font-style:italic&#34;&gt;# 0 and 1 are not prime&lt;/span&gt;&#xA;&lt;/span&gt;&lt;/span&gt;&lt;span style=&#34;display:flex;&#34;&gt;&lt;span&gt;primes &lt;span style=&#34;color:#04a5e5;font-weight:bold&#34;&gt;=&lt;/span&gt; []&#xA;&lt;/span&gt;&lt;/span&gt;&lt;span style=&#34;display:flex;&#34;&gt;&lt;span&gt;&lt;span style=&#34;color:#8839ef&#34;&gt;for&lt;/span&gt; i &lt;span style=&#34;color:#04a5e5;font-weight:bold&#34;&gt;in&lt;/span&gt; &lt;span style=&#34;color:#04a5e5&#34;&gt;range&lt;/span&gt;(&lt;span style=&#34;color:#fe640b&#34;&gt;2&lt;/span&gt;, MX):&#xA;&lt;/span&gt;&lt;/span&gt;&lt;span style=&#34;display:flex;&#34;&gt;&lt;span&gt;    &lt;span style=&#34;color:#8839ef&#34;&gt;if&lt;/span&gt; is_prime[i]:&#xA;&lt;/span&gt;&lt;/span&gt;&lt;span style=&#34;display:flex;&#34;&gt;&lt;span&gt;        primes&lt;span style=&#34;color:#04a5e5;font-weight:bold&#34;&gt;.&lt;/span&gt;append(i)&#xA;&lt;/span&gt;&lt;/span&gt;&lt;span style=&#34;display:flex;&#34;&gt;&lt;span&gt;        &lt;span style=&#34;color:#8839ef&#34;&gt;for&lt;/span&gt; j &lt;span style=&#34;color:#04a5e5;font-weight:bold&#34;&gt;in&lt;/span&gt; &lt;span style=&#34;color:#04a5e5&#34;&gt;range&lt;/span&gt;(i &lt;span style=&#34;color:#04a5e5;font-weight:bold&#34;&gt;*&lt;/span&gt; i, MX, i):&#xA;&lt;/span&gt;&lt;/span&gt;&lt;span style=&#34;display:flex;&#34;&gt;&lt;span&gt;            is_prime[j] &lt;span style=&#34;color:#04a5e5;font-weight:bold&#34;&gt;=&lt;/span&gt; &lt;span style=&#34;color:#fe640b&#34;&gt;False&lt;/span&gt;  &lt;span style=&#34;color:#9ca0b0;font-style:italic&#34;&gt;# j is a multiple of prime i&lt;/span&gt;&#xA;&lt;/span&gt;&lt;/span&gt;&lt;/code&gt;&lt;/pre&gt;&lt;/td&gt;&lt;/tr&gt;&lt;/table&gt;&#xA;&lt;/div&gt;&#xA;&lt;/div&gt;&lt;h4 id=&#34;204-count-primes&#34;&gt;204. Count Primes&lt;/h4&gt;&#xA;&lt;p&gt;p[i] represents the number of primes less than or equal to i. Starting from i=2, p[i]==0 &amp;lt;=&amp;gt; i is prime. Then, starting from i&lt;em&gt;i, mark multiples of i as composite (by setting p[i&lt;/em&gt;k]=-1). And, p[i] is assigned p[i-1]+1.&lt;/p&gt;</description>
    </item>
    <item>
      <title>String</title>
      <link>https://ruokezhang.github.io/en/post/leetcode/string/</link>
      <pubDate>Mon, 18 Aug 2025 00:00:00 +0000</pubDate>
      <guid>https://ruokezhang.github.io/en/post/leetcode/string/</guid>
      <description>&lt;h3 id=&#34;kmp&#34;&gt;KMP&lt;/h3&gt;&#xA;&lt;p&gt;&lt;a href=&#34;https://www.zhihu.com/question/21923021/answer/37475572&#34;&gt;https://www.zhihu.com/question/21923021/answer/37475572&lt;/a&gt;&lt;/p&gt;&#xA;&lt;h4 id=&#34;28-find-the-index-of-the-first-occurrence-in-a-string&#34;&gt;28. Find the Index of the First Occurrence in a String&lt;/h4&gt;&#xA;&lt;p&gt;Pattern: abababzababab&lt;/p&gt;&#xA;&lt;p&gt;Step 1: Construct next array while traversing pattern.&lt;/p&gt;&#xA;&lt;ul&gt;&#xA;&lt;li&gt;next[i] represents &lt;strong&gt;maximum&lt;/strong&gt; common prefix-suffix length for s[0:i+1]&lt;/li&gt;&#xA;&lt;li&gt;Initialize j=0, i traverses from 1 to n-1. j position indicates current common prefix-suffix s[:j]&lt;/li&gt;&#xA;&lt;li&gt;During traversal, if &lt;strong&gt;common prefix-suffix exists&lt;/strong&gt;, continuously compare s[i] and s[j]. If different, &lt;strong&gt;in loop backtrack j until s[:j] becomes common prefix-suffix&lt;/strong&gt;. Backtrack to &lt;strong&gt;second longest common prefix-suffix&lt;/strong&gt;, move j to next[j-1]&lt;/li&gt;&#xA;&lt;li&gt;Compare s[i] and s[j] again. If same, move j and assign next[i]&lt;/li&gt;&#xA;&lt;/ul&gt;&#xA;&lt;p&gt;Step 2: Compare two strings&#xA;abeababeabf&#xA;abeabf&lt;/p&gt;</description>
    </item>
    <item>
      <title>Network</title>
      <link>https://ruokezhang.github.io/en/post/network/</link>
      <pubDate>Sat, 29 Mar 2025 00:00:00 +0000</pubDate>
      <guid>https://ruokezhang.github.io/en/post/network/</guid>
      <description>&lt;p&gt;&lt;img src=&#34;image.png&#34; alt=&#34;Alt text&#34;&gt;&lt;/p&gt;&#xA;&lt;h2 id=&#34;tcp-retransmission&#34;&gt;TCP Retransmission&lt;/h2&gt;&#xA;&lt;ol&gt;&#xA;&lt;li&gt;&lt;strong&gt;Timeout Retransmission&lt;/strong&gt;: A timer is set, which should be slightly longer than the Round-Trip Time (RTT). If the timer expires before an ACK is received, the segment is immediately retransmitted.&lt;/li&gt;&#xA;&lt;li&gt;&lt;strong&gt;Fast Retransmission&lt;/strong&gt;: When three consecutive duplicate ACKs are received, the segment is retransmitted immediately.&lt;/li&gt;&#xA;&lt;li&gt;&lt;strong&gt;SACK (Selective Acknowledgment)&lt;/strong&gt;: The receiver can inform the sender which segments have been received and which are missing.&lt;/li&gt;&#xA;&lt;li&gt;&lt;strong&gt;DSACK (Duplicate SACK)&lt;/strong&gt;: If the receiver gets two identical segments (e.g., two 2s), it uses DSACK to inform the sender that it has received duplicates, preventing unnecessary retransmissions due to network latency.&lt;/li&gt;&#xA;&lt;/ol&gt;&#xA;&lt;h2 id=&#34;tcp-flow-control&#34;&gt;TCP Flow Control&lt;/h2&gt;&#xA;&lt;h3 id=&#34;slow-start&#34;&gt;Slow Start&lt;/h3&gt;&#xA;&lt;p&gt;When transmission begins, the sender doubles its congestion window for each ACK received (exponential growth). The initial window size is 1.&lt;/p&gt;</description>
    </item>
    <item>
      <title>Greedy</title>
      <link>https://ruokezhang.github.io/en/post/leetcode/greedy/</link>
      <pubDate>Fri, 28 Mar 2025 00:00:00 +0000</pubDate>
      <guid>https://ruokezhang.github.io/en/post/leetcode/greedy/</guid>
      <description>&lt;p&gt;&lt;a href=&#34;https://leetcode.cn/discuss/post/g6KTKL/&#34;&gt;Ling Shen Problem List&lt;/a&gt;&lt;/p&gt;&#xA;&lt;h4 id=&#34;300-longest-increasing-subsequence&#34;&gt;300. Longest Increasing Subsequence&lt;/h4&gt;&#xA;&lt;p&gt;&lt;a href=&#34;https://www.bilibili.com/video/BV1ub411Q7sB/?vd_source=3417d90294dd8bcb1cc2b3dc8bc1ef3c&#34;&gt;Ling Shen Video&lt;/a&gt;&lt;/p&gt;&#xA;&lt;p&gt;Define g[i] as the minimum end element of an increasing subsequence of length i+1.&lt;/p&gt;&#xA;&lt;p&gt;Proof by contradiction: g is a strictly increasing array.&lt;/p&gt;&#xA;&lt;h4 id=&#34;659-split-array-into-consecutive-subsequences&#34;&gt;659. Split Array into Consecutive Subsequences&lt;/h4&gt;&#xA;&lt;p&gt;tail[i] is used to represent the number of subsequences ending with i. This way, when i+1 is encountered, it can be placed.&lt;/p&gt;&#xA;&lt;p&gt;If it cannot be placed, open a new sequence and check if cnt[i+1]&amp;gt;0 and cnt[i+2]&amp;gt;2. If not satisfied, return False.&lt;/p&gt;</description>
    </item>
    <item>
      <title>MySQL Logs</title>
      <link>https://ruokezhang.github.io/en/post/mysql-logs/</link>
      <pubDate>Wed, 26 Mar 2025 00:00:00 +0000</pubDate>
      <guid>https://ruokezhang.github.io/en/post/mysql-logs/</guid>
      <description>&lt;p&gt;All DML operations (INSERT/UPDATE/DELETE) are first completed in the Buffer Pool&lt;/p&gt;&#xA;&lt;h2 id=&#34;redo-log&#34;&gt;redo log&lt;/h2&gt;&#xA;&lt;p&gt;&lt;a href=&#34;https://www.bilibili.com/video/BV1Dr4y197ai/?spm_id_from=333.1391.0.0&amp;amp;vd_source=3417d90294dd8bcb1cc2b3dc8bc1ef3c&#34;&gt;Video Explanation&lt;/a&gt;&#xA;&lt;img src=&#34;https://blog-ruoke.oss-cn-hongkong.aliyuncs.com/static/redoLog.png&#34; alt=&#34;Alt text&#34;&gt;&lt;/p&gt;&#xA;&lt;ol&gt;&#xA;&lt;li&gt;Implements transaction durability. redo log is flushed to disk first, then dirty pages are flushed to disk&lt;/li&gt;&#xA;&lt;/ol&gt;&#xA;&lt;h3 id=&#34;physical-storage-characteristics&#34;&gt;Physical Storage Characteristics&lt;/h3&gt;&#xA;&lt;ol&gt;&#xA;&lt;li&gt;&#xA;&lt;p&gt;&lt;strong&gt;File Structure&lt;/strong&gt;&lt;/p&gt;&#xA;&lt;ul&gt;&#xA;&lt;li&gt;Composed of fixed-size files (such as &lt;code&gt;ib_logfile0&lt;/code&gt;, &lt;code&gt;ib_logfile1&lt;/code&gt;)&lt;/li&gt;&#xA;&lt;li&gt;Circular write (ring buffer) design&lt;/li&gt;&#xA;&lt;li&gt;&lt;strong&gt;Physical writes are always appended to the end of the file&lt;/strong&gt;&lt;/li&gt;&#xA;&lt;/ul&gt;&#xA;&lt;/li&gt;&#xA;&lt;li&gt;&#xA;&lt;p&gt;&lt;strong&gt;Write Mode&lt;/strong&gt;&lt;/p&gt;&#xA;&lt;/li&gt;&#xA;&lt;/ol&gt;&#xA;&lt;div class=&#34;highlight&#34;&gt;&lt;div style=&#34;color:#4c4f69;background-color:#eff1f5;-moz-tab-size:2;-o-tab-size:2;tab-size:2;&#34;&gt;&#xA;&lt;table style=&#34;border-spacing:0;padding:0;margin:0;border:0;&#34;&gt;&lt;tr&gt;&lt;td style=&#34;vertical-align:top;padding:0;margin:0;border:0;&#34;&gt;&#xA;&lt;pre tabindex=&#34;0&#34; style=&#34;color:#4c4f69;background-color:#eff1f5;-moz-tab-size:2;-o-tab-size:2;tab-size:2;&#34;&gt;&lt;code&gt;&lt;span style=&#34;white-space:pre;-webkit-user-select:none;user-select:none;margin-right:0.4em;padding:0 0.4em 0 0.4em;color:#8c8fa1&#34;&gt;1&#xA;&lt;/span&gt;&lt;span style=&#34;white-space:pre;-webkit-user-select:none;user-select:none;margin-right:0.4em;padding:0 0.4em 0 0.4em;color:#8c8fa1&#34;&gt;2&#xA;&lt;/span&gt;&lt;/code&gt;&lt;/pre&gt;&lt;/td&gt;&#xA;&lt;td style=&#34;vertical-align:top;padding:0;margin:0;border:0;;width:100%&#34;&gt;&#xA;&lt;pre tabindex=&#34;0&#34; style=&#34;color:#4c4f69;background-color:#eff1f5;-moz-tab-size:2;-o-tab-size:2;tab-size:2;&#34;&gt;&lt;code class=&#34;language-c&#34; data-lang=&#34;c&#34;&gt;&lt;span style=&#34;display:flex;&#34;&gt;&lt;span&gt;&lt;span style=&#34;color:#9ca0b0;font-style:italic&#34;&gt;// Pseudo code representing physical write&#xA;&lt;/span&gt;&lt;/span&gt;&lt;/span&gt;&lt;span style=&#34;display:flex;&#34;&gt;&lt;span&gt;&lt;span style=&#34;color:#9ca0b0;font-style:italic&#34;&gt;&lt;/span&gt;&lt;span style=&#34;color:#1e66f5&#34;&gt;write&lt;/span&gt;(log_file, log_record, log_size); &lt;span style=&#34;color:#9ca0b0;font-style:italic&#34;&gt;// Always append write&#xA;&lt;/span&gt;&lt;/span&gt;&lt;/span&gt;&lt;/code&gt;&lt;/pre&gt;&lt;/td&gt;&lt;/tr&gt;&lt;/table&gt;&#xA;&lt;/div&gt;&#xA;&lt;/div&gt;&lt;h3 id=&#34;write-ahead-logging-wal&#34;&gt;Write-Ahead Logging (WAL):&lt;/h3&gt;&#xA;&lt;ul&gt;&#xA;&lt;li&gt;Update data pages in Buffer Pool, these data pages become &lt;strong&gt;dirty pages&lt;/strong&gt;.&lt;/li&gt;&#xA;&lt;li&gt;Write physical changes to data pages (such as &amp;ldquo;page number X, offset Y write data Z&amp;rdquo;) sequentially to redo log buffer.&lt;/li&gt;&#xA;&lt;li&gt;When executing COMMIT, behavior is determined by configuration parameter innodb_flush_log_at_trx_commit (usually default value is 1)&lt;/li&gt;&#xA;&lt;/ul&gt;&#xA;&lt;table&gt;&#xA;  &lt;thead&gt;&#xA;      &lt;tr&gt;&#xA;          &lt;th&gt;Parameter Value&lt;/th&gt;&#xA;          &lt;th&gt;Behavior&lt;/th&gt;&#xA;          &lt;th&gt;Durability Guarantee&lt;/th&gt;&#xA;      &lt;/tr&gt;&#xA;  &lt;/thead&gt;&#xA;  &lt;tbody&gt;&#xA;      &lt;tr&gt;&#xA;          &lt;td&gt;1 (default)&lt;/td&gt;&#xA;          &lt;td&gt;1. Write PageCache&lt;br&gt;2. Immediate fsync() flush to disk&lt;/td&gt;&#xA;          &lt;td&gt;Complete durability&lt;/td&gt;&#xA;      &lt;/tr&gt;&#xA;      &lt;tr&gt;&#xA;          &lt;td&gt;0&lt;/td&gt;&#xA;          &lt;td&gt;Batch write + flush to disk every second&lt;/td&gt;&#xA;          &lt;td&gt;May lose 1 second of data&lt;/td&gt;&#xA;      &lt;/tr&gt;&#xA;      &lt;tr&gt;&#xA;          &lt;td&gt;2&lt;/td&gt;&#xA;          &lt;td&gt;Write PageCache but delay flush to disk&lt;/td&gt;&#xA;          &lt;td&gt;Only guarantees OS doesn&amp;rsquo;t crash&lt;/td&gt;&#xA;      &lt;/tr&gt;&#xA;  &lt;/tbody&gt;&#xA;&lt;/table&gt;&#xA;&lt;ul&gt;&#xA;&lt;li&gt;Asynchronous dirty page flush to disk, background threads flush data from BufferPool to hard disk&lt;/li&gt;&#xA;&lt;/ul&gt;&#xA;&lt;p&gt;&lt;img src=&#34;https://blog-ruoke.oss-cn-hongkong.aliyuncs.com/static/redolog1.png&#34; alt=&#34;Alt text&#34;&gt;&lt;/p&gt;</description>
    </item>
    <item>
      <title>Redis Interview Notes</title>
      <link>https://ruokezhang.github.io/en/post/redis/redis_interview/</link>
      <pubDate>Tue, 25 Mar 2025 00:00:00 +0000</pubDate>
      <guid>https://ruokezhang.github.io/en/post/redis/redis_interview/</guid>
      <description>&lt;h2 id=&#34;sorted-sets-zset&#34;&gt;Sorted Sets (&lt;code&gt;ZSET&lt;/code&gt;)&lt;/h2&gt;&#xA;&lt;p&gt;A sorted set maps each unique member to a score and orders members by score. Range queries and updates are typically O(log N).&lt;/p&gt;&#xA;&lt;h3 id=&#34;compact-encoding&#34;&gt;Compact Encoding&lt;/h3&gt;&#xA;&lt;p&gt;Small sorted sets can use a compact listpack representation. Redis converts to its general representation when the set exceeds limits such as &lt;code&gt;zset-max-listpack-entries&lt;/code&gt; or &lt;code&gt;zset-max-listpack-value&lt;/code&gt;. Older Redis versions used a ziplist and correspondingly named settings. Check the settings for the version you run.&lt;/p&gt;</description>
    </item>
    <item>
      <title>Common MySQL Interview Questions</title>
      <link>https://ruokezhang.github.io/en/post/mysql-interview/</link>
      <pubDate>Mon, 24 Mar 2025 00:00:00 +0000</pubDate>
      <guid>https://ruokezhang.github.io/en/post/mysql-interview/</guid>
      <description>&lt;h2 id=&#34;storage-engine-comparison&#34;&gt;Storage Engine Comparison&lt;/h2&gt;&#xA;&lt;ol&gt;&#xA;&lt;li&gt;In InnoDB, primary key index and data are stored together, with the primary key index B+ tree containing complete data rows; in MyISAM, index and data are stored separately, with the B tree storing index values and physical addresses of rows&lt;/li&gt;&#xA;&lt;li&gt;InnoDB supports ACID transactions, MyISAM does not&lt;/li&gt;&#xA;&lt;li&gt;InnoDB supports row-level locking, MyISAM does not&lt;/li&gt;&#xA;&lt;/ol&gt;&#xA;&lt;h2 id=&#34;what-is-page-split&#34;&gt;What is Page Split&lt;/h2&gt;&#xA;&lt;p&gt;When inserting new data into a full index page (usually 16KB), the storage engine will split the current page into two pages to accommodate the new data&lt;/p&gt;</description>
    </item>
    <item>
      <title>Java Reflection &amp; Dynamic Proxy</title>
      <link>https://ruokezhang.github.io/en/post/java/javabasic/reflection/</link>
      <pubDate>Tue, 18 Mar 2025 00:00:00 +0000</pubDate>
      <guid>https://ruokezhang.github.io/en/post/java/javabasic/reflection/</guid>
      <description>&lt;h2 id=&#34;reflection&#34;&gt;Reflection&lt;/h2&gt;&#xA;&lt;p&gt;Reflection is Java&amp;rsquo;s ability to dynamically &lt;strong&gt;obtain class information&lt;/strong&gt; (such as class name, methods, fields, constructors, etc.) and &lt;strong&gt;manipulate classes&lt;/strong&gt; at &lt;strong&gt;runtime&lt;/strong&gt;.&lt;/p&gt;&#xA;&lt;h3 id=&#34;api&#34;&gt;API&lt;/h3&gt;&#xA;&lt;h4 id=&#34;getting-a-class-object&#34;&gt;Getting a Class Object&lt;/h4&gt;&#xA;&lt;div class=&#34;highlight&#34;&gt;&lt;div style=&#34;color:#4c4f69;background-color:#eff1f5;-moz-tab-size:2;-o-tab-size:2;tab-size:2;&#34;&gt;&#xA;&lt;table style=&#34;border-spacing:0;padding:0;margin:0;border:0;&#34;&gt;&lt;tr&gt;&lt;td style=&#34;vertical-align:top;padding:0;margin:0;border:0;&#34;&gt;&#xA;&lt;pre tabindex=&#34;0&#34; style=&#34;color:#4c4f69;background-color:#eff1f5;-moz-tab-size:2;-o-tab-size:2;tab-size:2;&#34;&gt;&lt;code&gt;&lt;span style=&#34;white-space:pre;-webkit-user-select:none;user-select:none;margin-right:0.4em;padding:0 0.4em 0 0.4em;color:#8c8fa1&#34;&gt;1&#xA;&lt;/span&gt;&lt;span style=&#34;white-space:pre;-webkit-user-select:none;user-select:none;margin-right:0.4em;padding:0 0.4em 0 0.4em;color:#8c8fa1&#34;&gt;2&#xA;&lt;/span&gt;&lt;span style=&#34;white-space:pre;-webkit-user-select:none;user-select:none;margin-right:0.4em;padding:0 0.4em 0 0.4em;color:#8c8fa1&#34;&gt;3&#xA;&lt;/span&gt;&lt;span style=&#34;white-space:pre;-webkit-user-select:none;user-select:none;margin-right:0.4em;padding:0 0.4em 0 0.4em;color:#8c8fa1&#34;&gt;4&#xA;&lt;/span&gt;&lt;span style=&#34;white-space:pre;-webkit-user-select:none;user-select:none;margin-right:0.4em;padding:0 0.4em 0 0.4em;color:#8c8fa1&#34;&gt;5&#xA;&lt;/span&gt;&lt;span style=&#34;white-space:pre;-webkit-user-select:none;user-select:none;margin-right:0.4em;padding:0 0.4em 0 0.4em;color:#8c8fa1&#34;&gt;6&#xA;&lt;/span&gt;&lt;span style=&#34;white-space:pre;-webkit-user-select:none;user-select:none;margin-right:0.4em;padding:0 0.4em 0 0.4em;color:#8c8fa1&#34;&gt;7&#xA;&lt;/span&gt;&lt;/code&gt;&lt;/pre&gt;&lt;/td&gt;&#xA;&lt;td style=&#34;vertical-align:top;padding:0;margin:0;border:0;;width:100%&#34;&gt;&#xA;&lt;pre tabindex=&#34;0&#34; style=&#34;color:#4c4f69;background-color:#eff1f5;-moz-tab-size:2;-o-tab-size:2;tab-size:2;&#34;&gt;&lt;code class=&#34;language-java&#34; data-lang=&#34;java&#34;&gt;&lt;span style=&#34;display:flex;&#34;&gt;&lt;span&gt;String str&lt;span style=&#34;color:#04a5e5;font-weight:bold&#34;&gt;=&lt;/span&gt;&lt;span style=&#34;color:#40a02b&#34;&gt;&amp;#34;test&amp;#34;&lt;/span&gt;;&#xA;&lt;/span&gt;&lt;/span&gt;&lt;span style=&#34;display:flex;&#34;&gt;&lt;span&gt;Class&lt;span style=&#34;color:#04a5e5;font-weight:bold&#34;&gt;&amp;lt;?&amp;gt;&lt;/span&gt; clazz &lt;span style=&#34;color:#04a5e5;font-weight:bold&#34;&gt;=&lt;/span&gt; String.&lt;span style=&#34;color:#1e66f5&#34;&gt;class&lt;/span&gt;;&#xA;&lt;/span&gt;&lt;/span&gt;&lt;span style=&#34;display:flex;&#34;&gt;&lt;span&gt;&#xA;&lt;/span&gt;&lt;/span&gt;&lt;span style=&#34;display:flex;&#34;&gt;&lt;span&gt;String str &lt;span style=&#34;color:#04a5e5;font-weight:bold&#34;&gt;=&lt;/span&gt; &lt;span style=&#34;color:#40a02b&#34;&gt;&amp;#34;test&amp;#34;&lt;/span&gt;;&#xA;&lt;/span&gt;&lt;/span&gt;&lt;span style=&#34;display:flex;&#34;&gt;&lt;span&gt;Class&lt;span style=&#34;color:#04a5e5;font-weight:bold&#34;&gt;&amp;lt;?&amp;gt;&lt;/span&gt; clazz &lt;span style=&#34;color:#04a5e5;font-weight:bold&#34;&gt;=&lt;/span&gt; str.&lt;span style=&#34;color:#1e66f5&#34;&gt;getClass&lt;/span&gt;();&#xA;&lt;/span&gt;&lt;/span&gt;&lt;span style=&#34;display:flex;&#34;&gt;&lt;span&gt;&#xA;&lt;/span&gt;&lt;/span&gt;&lt;span style=&#34;display:flex;&#34;&gt;&lt;span&gt;Class&lt;span style=&#34;color:#04a5e5;font-weight:bold&#34;&gt;&amp;lt;?&amp;gt;&lt;/span&gt; clazz &lt;span style=&#34;color:#04a5e5;font-weight:bold&#34;&gt;=&lt;/span&gt; Class.&lt;span style=&#34;color:#1e66f5&#34;&gt;forName&lt;/span&gt;(&lt;span style=&#34;color:#40a02b&#34;&gt;&amp;#34;java.lang.String&amp;#34;&lt;/span&gt;);&#xA;&lt;/span&gt;&lt;/span&gt;&lt;/code&gt;&lt;/pre&gt;&lt;/td&gt;&lt;/tr&gt;&lt;/table&gt;&#xA;&lt;/div&gt;&#xA;&lt;/div&gt;&lt;h4 id=&#34;creating-objects-via-reflection&#34;&gt;Creating Objects via Reflection&lt;/h4&gt;&#xA;&lt;div class=&#34;highlight&#34;&gt;&lt;div style=&#34;color:#4c4f69;background-color:#eff1f5;-moz-tab-size:2;-o-tab-size:2;tab-size:2;&#34;&gt;&#xA;&lt;table style=&#34;border-spacing:0;padding:0;margin:0;border:0;&#34;&gt;&lt;tr&gt;&lt;td style=&#34;vertical-align:top;padding:0;margin:0;border:0;&#34;&gt;&#xA;&lt;pre tabindex=&#34;0&#34; style=&#34;color:#4c4f69;background-color:#eff1f5;-moz-tab-size:2;-o-tab-size:2;tab-size:2;&#34;&gt;&lt;code&gt;&lt;span style=&#34;white-space:pre;-webkit-user-select:none;user-select:none;margin-right:0.4em;padding:0 0.4em 0 0.4em;color:#8c8fa1&#34;&gt;1&#xA;&lt;/span&gt;&lt;span style=&#34;white-space:pre;-webkit-user-select:none;user-select:none;margin-right:0.4em;padding:0 0.4em 0 0.4em;color:#8c8fa1&#34;&gt;2&#xA;&lt;/span&gt;&lt;span style=&#34;white-space:pre;-webkit-user-select:none;user-select:none;margin-right:0.4em;padding:0 0.4em 0 0.4em;color:#8c8fa1&#34;&gt;3&#xA;&lt;/span&gt;&lt;span style=&#34;white-space:pre;-webkit-user-select:none;user-select:none;margin-right:0.4em;padding:0 0.4em 0 0.4em;color:#8c8fa1&#34;&gt;4&#xA;&lt;/span&gt;&lt;span style=&#34;white-space:pre;-webkit-user-select:none;user-select:none;margin-right:0.4em;padding:0 0.4em 0 0.4em;color:#8c8fa1&#34;&gt;5&#xA;&lt;/span&gt;&lt;/code&gt;&lt;/pre&gt;&lt;/td&gt;&#xA;&lt;td style=&#34;vertical-align:top;padding:0;margin:0;border:0;;width:100%&#34;&gt;&#xA;&lt;pre tabindex=&#34;0&#34; style=&#34;color:#4c4f69;background-color:#eff1f5;-moz-tab-size:2;-o-tab-size:2;tab-size:2;&#34;&gt;&lt;code class=&#34;language-java&#34; data-lang=&#34;java&#34;&gt;&lt;span style=&#34;display:flex;&#34;&gt;&lt;span&gt;Class&lt;span style=&#34;color:#04a5e5;font-weight:bold&#34;&gt;&amp;lt;?&amp;gt;&lt;/span&gt; clazz &lt;span style=&#34;color:#04a5e5;font-weight:bold&#34;&gt;=&lt;/span&gt; Class.&lt;span style=&#34;color:#1e66f5&#34;&gt;forName&lt;/span&gt;(&lt;span style=&#34;color:#40a02b&#34;&gt;&amp;#34;com.example.User&amp;#34;&lt;/span&gt;);&#xA;&lt;/span&gt;&lt;/span&gt;&lt;span style=&#34;display:flex;&#34;&gt;&lt;span&gt;Object obj &lt;span style=&#34;color:#04a5e5;font-weight:bold&#34;&gt;=&lt;/span&gt; clazz.&lt;span style=&#34;color:#1e66f5&#34;&gt;getDeclaredConstructor&lt;/span&gt;().&lt;span style=&#34;color:#1e66f5&#34;&gt;newInstance&lt;/span&gt;();&#xA;&lt;/span&gt;&lt;/span&gt;&lt;span style=&#34;display:flex;&#34;&gt;&lt;span&gt;&#xA;&lt;/span&gt;&lt;/span&gt;&lt;span style=&#34;display:flex;&#34;&gt;&lt;span&gt;Constructor&lt;span style=&#34;color:#04a5e5;font-weight:bold&#34;&gt;&amp;lt;?&amp;gt;&lt;/span&gt; constructor &lt;span style=&#34;color:#04a5e5;font-weight:bold&#34;&gt;=&lt;/span&gt; clazz.&lt;span style=&#34;color:#1e66f5&#34;&gt;getConstructor&lt;/span&gt;(String.&lt;span style=&#34;color:#1e66f5&#34;&gt;class&lt;/span&gt;, &lt;span style=&#34;color:#d20f39&#34;&gt;int&lt;/span&gt;.&lt;span style=&#34;color:#1e66f5&#34;&gt;class&lt;/span&gt;);&#xA;&lt;/span&gt;&lt;/span&gt;&lt;span style=&#34;display:flex;&#34;&gt;&lt;span&gt;Object obj &lt;span style=&#34;color:#04a5e5;font-weight:bold&#34;&gt;=&lt;/span&gt; constructor.&lt;span style=&#34;color:#1e66f5&#34;&gt;newInstance&lt;/span&gt;(&lt;span style=&#34;color:#40a02b&#34;&gt;&amp;#34;Alice&amp;#34;&lt;/span&gt;, 25);&#xA;&lt;/span&gt;&lt;/span&gt;&lt;/code&gt;&lt;/pre&gt;&lt;/td&gt;&lt;/tr&gt;&lt;/table&gt;&#xA;&lt;/div&gt;&#xA;&lt;/div&gt;&lt;h4 id=&#34;getting-fields&#34;&gt;Getting Fields&lt;/h4&gt;&#xA;&lt;p&gt;&lt;code&gt;getDeclaredField(&amp;quot;fieldName&amp;quot;)&lt;/code&gt;&lt;/p&gt;</description>
    </item>
    <item>
      <title>MySQL Locks</title>
      <link>https://ruokezhang.github.io/en/post/mysql-locks/</link>
      <pubDate>Mon, 17 Mar 2025 00:00:00 +0000</pubDate>
      <guid>https://ruokezhang.github.io/en/post/mysql-locks/</guid>
      <description>&lt;h2 id=&#34;global-lock&#34;&gt;Global Lock&lt;/h2&gt;&#xA;&lt;p&gt;Generally used when doing &lt;strong&gt;full database backup&lt;/strong&gt;. It blocks write operations and only allows read requests. Therefore, it&amp;rsquo;s usually chosen during business low-peak periods for full database backup.&lt;/p&gt;&#xA;&lt;div class=&#34;highlight&#34;&gt;&lt;div style=&#34;color:#4c4f69;background-color:#eff1f5;-moz-tab-size:2;-o-tab-size:2;tab-size:2;&#34;&gt;&#xA;&lt;table style=&#34;border-spacing:0;padding:0;margin:0;border:0;&#34;&gt;&lt;tr&gt;&lt;td style=&#34;vertical-align:top;padding:0;margin:0;border:0;&#34;&gt;&#xA;&lt;pre tabindex=&#34;0&#34; style=&#34;color:#4c4f69;background-color:#eff1f5;-moz-tab-size:2;-o-tab-size:2;tab-size:2;&#34;&gt;&lt;code&gt;&lt;span style=&#34;white-space:pre;-webkit-user-select:none;user-select:none;margin-right:0.4em;padding:0 0.4em 0 0.4em;color:#8c8fa1&#34;&gt;1&#xA;&lt;/span&gt;&lt;/code&gt;&lt;/pre&gt;&lt;/td&gt;&#xA;&lt;td style=&#34;vertical-align:top;padding:0;margin:0;border:0;;width:100%&#34;&gt;&#xA;&lt;pre tabindex=&#34;0&#34; style=&#34;color:#4c4f69;background-color:#eff1f5;-moz-tab-size:2;-o-tab-size:2;tab-size:2;&#34;&gt;&lt;code class=&#34;language-sql&#34; data-lang=&#34;sql&#34;&gt;&lt;span style=&#34;display:flex;&#34;&gt;&lt;span&gt;flush tables &lt;span style=&#34;color:#8839ef&#34;&gt;with&lt;/span&gt; &lt;span style=&#34;color:#8839ef&#34;&gt;read&lt;/span&gt; &lt;span style=&#34;color:#8839ef&#34;&gt;lock&lt;/span&gt;&#xA;&lt;/span&gt;&lt;/span&gt;&lt;/code&gt;&lt;/pre&gt;&lt;/td&gt;&lt;/tr&gt;&lt;/table&gt;&#xA;&lt;/div&gt;&#xA;&lt;/div&gt;&lt;h2 id=&#34;table-level-locks&#34;&gt;Table-Level Locks&lt;/h2&gt;&#xA;&lt;h3 id=&#34;table-lock&#34;&gt;Table Lock&lt;/h3&gt;&#xA;&lt;ol&gt;&#xA;&lt;li&gt;Table shared read lock. Multiple threads can acquire this lock simultaneously. Threads with this lock can read the table but cannot write to it. MyISAM acquires table shared read locks when processing read requests. InnoDB defaults to &lt;strong&gt;row locks&lt;/strong&gt; and handles read requests through MVCC.&lt;/li&gt;&#xA;&lt;li&gt;Table exclusive write lock. Only one thread can acquire this lock and perform write operations on the table. No other threads can read this table.&lt;/li&gt;&#xA;&lt;/ol&gt;&#xA;&lt;div class=&#34;highlight&#34;&gt;&lt;div style=&#34;color:#4c4f69;background-color:#eff1f5;-moz-tab-size:2;-o-tab-size:2;tab-size:2;&#34;&gt;&#xA;&lt;table style=&#34;border-spacing:0;padding:0;margin:0;border:0;&#34;&gt;&lt;tr&gt;&lt;td style=&#34;vertical-align:top;padding:0;margin:0;border:0;&#34;&gt;&#xA;&lt;pre tabindex=&#34;0&#34; style=&#34;color:#4c4f69;background-color:#eff1f5;-moz-tab-size:2;-o-tab-size:2;tab-size:2;&#34;&gt;&lt;code&gt;&lt;span style=&#34;white-space:pre;-webkit-user-select:none;user-select:none;margin-right:0.4em;padding:0 0.4em 0 0.4em;color:#8c8fa1&#34;&gt;1&#xA;&lt;/span&gt;&lt;/code&gt;&lt;/pre&gt;&lt;/td&gt;&#xA;&lt;td style=&#34;vertical-align:top;padding:0;margin:0;border:0;;width:100%&#34;&gt;&#xA;&lt;pre tabindex=&#34;0&#34; style=&#34;color:#4c4f69;background-color:#eff1f5;-moz-tab-size:2;-o-tab-size:2;tab-size:2;&#34;&gt;&lt;code class=&#34;language-sql&#34; data-lang=&#34;sql&#34;&gt;&lt;span style=&#34;display:flex;&#34;&gt;&lt;span&gt;&lt;span style=&#34;color:#8839ef&#34;&gt;lock&lt;/span&gt; tables t_student &lt;span style=&#34;color:#8839ef&#34;&gt;read&lt;/span&gt;;&#xA;&lt;/span&gt;&lt;/span&gt;&lt;/code&gt;&lt;/pre&gt;&lt;/td&gt;&lt;/tr&gt;&lt;/table&gt;&#xA;&lt;/div&gt;&#xA;&lt;/div&gt;&lt;p&gt;Table locks are triggered by: ALTER/DROP/TRUNCATE TABLE&lt;/p&gt;</description>
    </item>
    <item>
      <title>Redis High Availability</title>
      <link>https://ruokezhang.github.io/en/post/redis/highavailability/</link>
      <pubDate>Sat, 15 Mar 2025 00:00:00 +0000</pubDate>
      <guid>https://ruokezhang.github.io/en/post/redis/highavailability/</guid>
      <description>&lt;p&gt;References: &lt;a href=&#34;https://redis.io/docs/latest/operate/oss_and_stack/management/replication/&#34;&gt;Redis replication&lt;/a&gt;, &lt;a href=&#34;https://redis.io/docs/latest/operate/oss_and_stack/management/sentinel/&#34;&gt;Sentinel&lt;/a&gt;, and &lt;a href=&#34;https://redis.io/docs/latest/operate/oss_and_stack/management/scaling/&#34;&gt;Redis Cluster&lt;/a&gt;.&lt;/p&gt;&#xA;&lt;h2 id=&#34;primaryreplica-replication&#34;&gt;Primary–Replica Replication&lt;/h2&gt;&#xA;&lt;p&gt;Replication provides copies of data and can serve reads from replicas. A primary accepts writes and sends updates to its replicas. Replication is asynchronous, so a replica can lag behind a successful write.&lt;/p&gt;&#xA;&lt;p&gt;&lt;img src=&#34;https://blog-ruoke.oss-cn-hongkong.aliyuncs.com/static/availability.png&#34; alt=&#34;Redis replication&#34;&gt;&lt;/p&gt;&#xA;&lt;h3 id=&#34;full-synchronization&#34;&gt;Full Synchronization&lt;/h3&gt;&#xA;&lt;ol&gt;&#xA;&lt;li&gt;A replica connects to a primary and requests synchronization with &lt;code&gt;PSYNC&lt;/code&gt;.&lt;/li&gt;&#xA;&lt;li&gt;If a partial sync is impossible, the primary responds with &lt;code&gt;FULLRESYNC&lt;/code&gt;, including its replication ID and offset.&lt;/li&gt;&#xA;&lt;li&gt;The primary produces an RDB snapshot and sends it to the replica while buffering subsequent writes.&lt;/li&gt;&#xA;&lt;li&gt;The replica loads the snapshot and applies the buffered updates, then continues receiving the replication stream over a long-lived connection.&lt;/li&gt;&#xA;&lt;/ol&gt;&#xA;&lt;p&gt;To configure a replica, use &lt;code&gt;REPLICAOF &amp;lt;primary-host&amp;gt; &amp;lt;primary-port&amp;gt;&lt;/code&gt;. A full sync consumes network and CPU resources; replicas can also replicate from other replicas to reduce load on the primary.&lt;/p&gt;</description>
    </item>
    <item>
      <title>Binary Search</title>
      <link>https://ruokezhang.github.io/en/post/leetcode/binarysearch/</link>
      <pubDate>Thu, 13 Mar 2025 00:00:00 +0000</pubDate>
      <guid>https://ruokezhang.github.io/en/post/leetcode/binarysearch/</guid>
      <description>&lt;p&gt;&lt;a href=&#34;https://leetcode.cn/discuss/post/3579164/ti-dan-er-fen-suan-fa-er-fen-da-an-zui-x-3rqn/&#34;&gt;https://leetcode.cn/discuss/post/3579164/ti-dan-er-fen-suan-fa-er-fen-da-an-zui-x-3rqn/&lt;/a&gt;&lt;/p&gt;&#xA;&lt;h2 id=&#34;closed-interval-approach&#34;&gt;Closed Interval Approach&lt;/h2&gt;&#xA;&lt;h3 id=&#34;find-target&#34;&gt;Find Target&lt;/h3&gt;&#xA;&lt;div class=&#34;highlight&#34;&gt;&lt;div style=&#34;color:#4c4f69;background-color:#eff1f5;-moz-tab-size:2;-o-tab-size:2;tab-size:2;&#34;&gt;&#xA;&lt;table style=&#34;border-spacing:0;padding:0;margin:0;border:0;&#34;&gt;&lt;tr&gt;&lt;td style=&#34;vertical-align:top;padding:0;margin:0;border:0;&#34;&gt;&#xA;&lt;pre tabindex=&#34;0&#34; style=&#34;color:#4c4f69;background-color:#eff1f5;-moz-tab-size:2;-o-tab-size:2;tab-size:2;&#34;&gt;&lt;code&gt;&lt;span style=&#34;white-space:pre;-webkit-user-select:none;user-select:none;margin-right:0.4em;padding:0 0.4em 0 0.4em;color:#8c8fa1&#34;&gt; 1&#xA;&lt;/span&gt;&lt;span style=&#34;white-space:pre;-webkit-user-select:none;user-select:none;margin-right:0.4em;padding:0 0.4em 0 0.4em;color:#8c8fa1&#34;&gt; 2&#xA;&lt;/span&gt;&lt;span style=&#34;white-space:pre;-webkit-user-select:none;user-select:none;margin-right:0.4em;padding:0 0.4em 0 0.4em;color:#8c8fa1&#34;&gt; 3&#xA;&lt;/span&gt;&lt;span style=&#34;white-space:pre;-webkit-user-select:none;user-select:none;margin-right:0.4em;padding:0 0.4em 0 0.4em;color:#8c8fa1&#34;&gt; 4&#xA;&lt;/span&gt;&lt;span style=&#34;white-space:pre;-webkit-user-select:none;user-select:none;margin-right:0.4em;padding:0 0.4em 0 0.4em;color:#8c8fa1&#34;&gt; 5&#xA;&lt;/span&gt;&lt;span style=&#34;white-space:pre;-webkit-user-select:none;user-select:none;margin-right:0.4em;padding:0 0.4em 0 0.4em;color:#8c8fa1&#34;&gt; 6&#xA;&lt;/span&gt;&lt;span style=&#34;white-space:pre;-webkit-user-select:none;user-select:none;margin-right:0.4em;padding:0 0.4em 0 0.4em;color:#8c8fa1&#34;&gt; 7&#xA;&lt;/span&gt;&lt;span style=&#34;white-space:pre;-webkit-user-select:none;user-select:none;margin-right:0.4em;padding:0 0.4em 0 0.4em;color:#8c8fa1&#34;&gt; 8&#xA;&lt;/span&gt;&lt;span style=&#34;white-space:pre;-webkit-user-select:none;user-select:none;margin-right:0.4em;padding:0 0.4em 0 0.4em;color:#8c8fa1&#34;&gt; 9&#xA;&lt;/span&gt;&lt;span style=&#34;white-space:pre;-webkit-user-select:none;user-select:none;margin-right:0.4em;padding:0 0.4em 0 0.4em;color:#8c8fa1&#34;&gt;10&#xA;&lt;/span&gt;&lt;span style=&#34;white-space:pre;-webkit-user-select:none;user-select:none;margin-right:0.4em;padding:0 0.4em 0 0.4em;color:#8c8fa1&#34;&gt;11&#xA;&lt;/span&gt;&lt;span style=&#34;white-space:pre;-webkit-user-select:none;user-select:none;margin-right:0.4em;padding:0 0.4em 0 0.4em;color:#8c8fa1&#34;&gt;12&#xA;&lt;/span&gt;&lt;span style=&#34;white-space:pre;-webkit-user-select:none;user-select:none;margin-right:0.4em;padding:0 0.4em 0 0.4em;color:#8c8fa1&#34;&gt;13&#xA;&lt;/span&gt;&lt;span style=&#34;white-space:pre;-webkit-user-select:none;user-select:none;margin-right:0.4em;padding:0 0.4em 0 0.4em;color:#8c8fa1&#34;&gt;14&#xA;&lt;/span&gt;&lt;span style=&#34;white-space:pre;-webkit-user-select:none;user-select:none;margin-right:0.4em;padding:0 0.4em 0 0.4em;color:#8c8fa1&#34;&gt;15&#xA;&lt;/span&gt;&lt;/code&gt;&lt;/pre&gt;&lt;/td&gt;&#xA;&lt;td style=&#34;vertical-align:top;padding:0;margin:0;border:0;;width:100%&#34;&gt;&#xA;&lt;pre tabindex=&#34;0&#34; style=&#34;color:#4c4f69;background-color:#eff1f5;-moz-tab-size:2;-o-tab-size:2;tab-size:2;&#34;&gt;&lt;code class=&#34;language-python&#34; data-lang=&#34;python&#34;&gt;&lt;span style=&#34;display:flex;&#34;&gt;&lt;span&gt;&lt;span style=&#34;color:#8839ef&#34;&gt;class&lt;/span&gt; &lt;span style=&#34;color:#df8e1d&#34;&gt;Solution&lt;/span&gt;:&#xA;&lt;/span&gt;&lt;/span&gt;&lt;span style=&#34;display:flex;&#34;&gt;&lt;span&gt;    &lt;span style=&#34;color:#9ca0b0;font-style:italic&#34;&gt;# Standard binary search framework, returns index of target element, -1 if not found&lt;/span&gt;&#xA;&lt;/span&gt;&lt;/span&gt;&lt;span style=&#34;display:flex;&#34;&gt;&lt;span&gt;    &lt;span style=&#34;color:#8839ef&#34;&gt;def&lt;/span&gt; &lt;span style=&#34;color:#1e66f5&#34;&gt;search&lt;/span&gt;(&lt;span style=&#34;color:#04a5e5&#34;&gt;self&lt;/span&gt;, nums: List[&lt;span style=&#34;color:#04a5e5&#34;&gt;int&lt;/span&gt;], target: &lt;span style=&#34;color:#04a5e5&#34;&gt;int&lt;/span&gt;) &lt;span style=&#34;color:#04a5e5;font-weight:bold&#34;&gt;-&amp;gt;&lt;/span&gt; &lt;span style=&#34;color:#04a5e5&#34;&gt;int&lt;/span&gt;:&#xA;&lt;/span&gt;&lt;/span&gt;&lt;span style=&#34;display:flex;&#34;&gt;&lt;span&gt;        left &lt;span style=&#34;color:#04a5e5;font-weight:bold&#34;&gt;=&lt;/span&gt; &lt;span style=&#34;color:#fe640b&#34;&gt;0&lt;/span&gt;&#xA;&lt;/span&gt;&lt;/span&gt;&lt;span style=&#34;display:flex;&#34;&gt;&lt;span&gt;        right &lt;span style=&#34;color:#04a5e5;font-weight:bold&#34;&gt;=&lt;/span&gt; &lt;span style=&#34;color:#04a5e5&#34;&gt;len&lt;/span&gt;(nums) &lt;span style=&#34;color:#04a5e5;font-weight:bold&#34;&gt;-&lt;/span&gt; &lt;span style=&#34;color:#fe640b&#34;&gt;1&lt;/span&gt;&#xA;&lt;/span&gt;&lt;/span&gt;&lt;span style=&#34;display:flex;&#34;&gt;&lt;span&gt;&#xA;&lt;/span&gt;&lt;/span&gt;&lt;span style=&#34;display:flex;&#34;&gt;&lt;span&gt;        &lt;span style=&#34;color:#8839ef&#34;&gt;while&lt;/span&gt; left &lt;span style=&#34;color:#04a5e5;font-weight:bold&#34;&gt;&amp;lt;=&lt;/span&gt; right:&#xA;&lt;/span&gt;&lt;/span&gt;&lt;span style=&#34;display:flex;&#34;&gt;&lt;span&gt;            mid &lt;span style=&#34;color:#04a5e5;font-weight:bold&#34;&gt;=&lt;/span&gt; left &lt;span style=&#34;color:#04a5e5;font-weight:bold&#34;&gt;+&lt;/span&gt; (right &lt;span style=&#34;color:#04a5e5;font-weight:bold&#34;&gt;-&lt;/span&gt; left) &lt;span style=&#34;color:#04a5e5;font-weight:bold&#34;&gt;//&lt;/span&gt; &lt;span style=&#34;color:#fe640b&#34;&gt;2&lt;/span&gt;&#xA;&lt;/span&gt;&lt;/span&gt;&lt;span style=&#34;display:flex;&#34;&gt;&lt;span&gt;            &lt;span style=&#34;color:#8839ef&#34;&gt;if&lt;/span&gt; nums[mid] &lt;span style=&#34;color:#04a5e5;font-weight:bold&#34;&gt;==&lt;/span&gt; target:&#xA;&lt;/span&gt;&lt;/span&gt;&lt;span style=&#34;display:flex;&#34;&gt;&lt;span&gt;                &lt;span style=&#34;color:#8839ef&#34;&gt;return&lt;/span&gt; mid&#xA;&lt;/span&gt;&lt;/span&gt;&lt;span style=&#34;display:flex;&#34;&gt;&lt;span&gt;            &lt;span style=&#34;color:#8839ef&#34;&gt;elif&lt;/span&gt; nums[mid] &lt;span style=&#34;color:#04a5e5;font-weight:bold&#34;&gt;&amp;lt;&lt;/span&gt; target:&#xA;&lt;/span&gt;&lt;/span&gt;&lt;span style=&#34;display:flex;&#34;&gt;&lt;span&gt;                left &lt;span style=&#34;color:#04a5e5;font-weight:bold&#34;&gt;=&lt;/span&gt; mid &lt;span style=&#34;color:#04a5e5;font-weight:bold&#34;&gt;+&lt;/span&gt; &lt;span style=&#34;color:#fe640b&#34;&gt;1&lt;/span&gt;&#xA;&lt;/span&gt;&lt;/span&gt;&lt;span style=&#34;display:flex;&#34;&gt;&lt;span&gt;            &lt;span style=&#34;color:#8839ef&#34;&gt;elif&lt;/span&gt; nums[mid] &lt;span style=&#34;color:#04a5e5;font-weight:bold&#34;&gt;&amp;gt;&lt;/span&gt; target:&#xA;&lt;/span&gt;&lt;/span&gt;&lt;span style=&#34;display:flex;&#34;&gt;&lt;span&gt;                right &lt;span style=&#34;color:#04a5e5;font-weight:bold&#34;&gt;=&lt;/span&gt; mid &lt;span style=&#34;color:#04a5e5;font-weight:bold&#34;&gt;-&lt;/span&gt; &lt;span style=&#34;color:#fe640b&#34;&gt;1&lt;/span&gt;&#xA;&lt;/span&gt;&lt;/span&gt;&lt;span style=&#34;display:flex;&#34;&gt;&lt;span&gt;        &lt;span style=&#34;color:#8839ef&#34;&gt;return&lt;/span&gt; &lt;span style=&#34;color:#04a5e5;font-weight:bold&#34;&gt;-&lt;/span&gt;&lt;span style=&#34;color:#fe640b&#34;&gt;1&lt;/span&gt;&#xA;&lt;/span&gt;&lt;/span&gt;&lt;/code&gt;&lt;/pre&gt;&lt;/td&gt;&lt;/tr&gt;&lt;/table&gt;&#xA;&lt;/div&gt;&#xA;&lt;/div&gt;&lt;h3 id=&#34;find-left-boundary&#34;&gt;Find Left Boundary&lt;/h3&gt;&#xA;&lt;div class=&#34;highlight&#34;&gt;&lt;div style=&#34;color:#4c4f69;background-color:#eff1f5;-moz-tab-size:2;-o-tab-size:2;tab-size:2;&#34;&gt;&#xA;&lt;table style=&#34;border-spacing:0;padding:0;margin:0;border:0;&#34;&gt;&lt;tr&gt;&lt;td style=&#34;vertical-align:top;padding:0;margin:0;border:0;&#34;&gt;&#xA;&lt;pre tabindex=&#34;0&#34; style=&#34;color:#4c4f69;background-color:#eff1f5;-moz-tab-size:2;-o-tab-size:2;tab-size:2;&#34;&gt;&lt;code&gt;&lt;span style=&#34;white-space:pre;-webkit-user-select:none;user-select:none;margin-right:0.4em;padding:0 0.4em 0 0.4em;color:#8c8fa1&#34;&gt; 1&#xA;&lt;/span&gt;&lt;span style=&#34;white-space:pre;-webkit-user-select:none;user-select:none;margin-right:0.4em;padding:0 0.4em 0 0.4em;color:#8c8fa1&#34;&gt; 2&#xA;&lt;/span&gt;&lt;span style=&#34;white-space:pre;-webkit-user-select:none;user-select:none;margin-right:0.4em;padding:0 0.4em 0 0.4em;color:#8c8fa1&#34;&gt; 3&#xA;&lt;/span&gt;&lt;span style=&#34;white-space:pre;-webkit-user-select:none;user-select:none;margin-right:0.4em;padding:0 0.4em 0 0.4em;color:#8c8fa1&#34;&gt; 4&#xA;&lt;/span&gt;&lt;span style=&#34;white-space:pre;-webkit-user-select:none;user-select:none;margin-right:0.4em;padding:0 0.4em 0 0.4em;color:#8c8fa1&#34;&gt; 5&#xA;&lt;/span&gt;&lt;span style=&#34;white-space:pre;-webkit-user-select:none;user-select:none;margin-right:0.4em;padding:0 0.4em 0 0.4em;color:#8c8fa1&#34;&gt; 6&#xA;&lt;/span&gt;&lt;span style=&#34;white-space:pre;-webkit-user-select:none;user-select:none;margin-right:0.4em;padding:0 0.4em 0 0.4em;color:#8c8fa1&#34;&gt; 7&#xA;&lt;/span&gt;&lt;span style=&#34;white-space:pre;-webkit-user-select:none;user-select:none;margin-right:0.4em;padding:0 0.4em 0 0.4em;color:#8c8fa1&#34;&gt; 8&#xA;&lt;/span&gt;&lt;span style=&#34;white-space:pre;-webkit-user-select:none;user-select:none;margin-right:0.4em;padding:0 0.4em 0 0.4em;color:#8c8fa1&#34;&gt; 9&#xA;&lt;/span&gt;&lt;span style=&#34;white-space:pre;-webkit-user-select:none;user-select:none;margin-right:0.4em;padding:0 0.4em 0 0.4em;color:#8c8fa1&#34;&gt;10&#xA;&lt;/span&gt;&lt;span style=&#34;white-space:pre;-webkit-user-select:none;user-select:none;margin-right:0.4em;padding:0 0.4em 0 0.4em;color:#8c8fa1&#34;&gt;11&#xA;&lt;/span&gt;&lt;span style=&#34;white-space:pre;-webkit-user-select:none;user-select:none;margin-right:0.4em;padding:0 0.4em 0 0.4em;color:#8c8fa1&#34;&gt;12&#xA;&lt;/span&gt;&lt;span style=&#34;white-space:pre;-webkit-user-select:none;user-select:none;margin-right:0.4em;padding:0 0.4em 0 0.4em;color:#8c8fa1&#34;&gt;13&#xA;&lt;/span&gt;&lt;/code&gt;&lt;/pre&gt;&lt;/td&gt;&#xA;&lt;td style=&#34;vertical-align:top;padding:0;margin:0;border:0;;width:100%&#34;&gt;&#xA;&lt;pre tabindex=&#34;0&#34; style=&#34;color:#4c4f69;background-color:#eff1f5;-moz-tab-size:2;-o-tab-size:2;tab-size:2;&#34;&gt;&lt;code class=&#34;language-python&#34; data-lang=&#34;python&#34;&gt;&lt;span style=&#34;display:flex;&#34;&gt;&lt;span&gt;&lt;span style=&#34;color:#8839ef&#34;&gt;def&lt;/span&gt; &lt;span style=&#34;color:#1e66f5&#34;&gt;search&lt;/span&gt;(&lt;span style=&#34;color:#04a5e5&#34;&gt;self&lt;/span&gt;, nums: List[&lt;span style=&#34;color:#04a5e5&#34;&gt;int&lt;/span&gt;], target: &lt;span style=&#34;color:#04a5e5&#34;&gt;int&lt;/span&gt;) &lt;span style=&#34;color:#04a5e5;font-weight:bold&#34;&gt;-&amp;gt;&lt;/span&gt; &lt;span style=&#34;color:#04a5e5&#34;&gt;int&lt;/span&gt;:&#xA;&lt;/span&gt;&lt;/span&gt;&lt;span style=&#34;display:flex;&#34;&gt;&lt;span&gt;    left &lt;span style=&#34;color:#04a5e5;font-weight:bold&#34;&gt;=&lt;/span&gt; &lt;span style=&#34;color:#fe640b&#34;&gt;0&lt;/span&gt;&#xA;&lt;/span&gt;&lt;/span&gt;&lt;span style=&#34;display:flex;&#34;&gt;&lt;span&gt;    right &lt;span style=&#34;color:#04a5e5;font-weight:bold&#34;&gt;=&lt;/span&gt; &lt;span style=&#34;color:#04a5e5&#34;&gt;len&lt;/span&gt;(nums) &lt;span style=&#34;color:#04a5e5;font-weight:bold&#34;&gt;-&lt;/span&gt; &lt;span style=&#34;color:#fe640b&#34;&gt;1&lt;/span&gt;&#xA;&lt;/span&gt;&lt;/span&gt;&lt;span style=&#34;display:flex;&#34;&gt;&lt;span&gt;&#xA;&lt;/span&gt;&lt;/span&gt;&lt;span style=&#34;display:flex;&#34;&gt;&lt;span&gt;    &lt;span style=&#34;color:#8839ef&#34;&gt;while&lt;/span&gt; left &lt;span style=&#34;color:#04a5e5;font-weight:bold&#34;&gt;&amp;lt;=&lt;/span&gt; right:&#xA;&lt;/span&gt;&lt;/span&gt;&lt;span style=&#34;display:flex;&#34;&gt;&lt;span&gt;        mid &lt;span style=&#34;color:#04a5e5;font-weight:bold&#34;&gt;=&lt;/span&gt; left &lt;span style=&#34;color:#04a5e5;font-weight:bold&#34;&gt;+&lt;/span&gt; (right &lt;span style=&#34;color:#04a5e5;font-weight:bold&#34;&gt;-&lt;/span&gt; left) &lt;span style=&#34;color:#04a5e5;font-weight:bold&#34;&gt;//&lt;/span&gt; &lt;span style=&#34;color:#fe640b&#34;&gt;2&lt;/span&gt;&#xA;&lt;/span&gt;&lt;/span&gt;&lt;span style=&#34;display:flex;&#34;&gt;&lt;span&gt;        &lt;span style=&#34;color:#8839ef&#34;&gt;if&lt;/span&gt; nums[mid] &lt;span style=&#34;color:#04a5e5;font-weight:bold&#34;&gt;==&lt;/span&gt; target:&#xA;&lt;/span&gt;&lt;/span&gt;&lt;span style=&#34;display:flex;&#34;&gt;&lt;span&gt;            right&lt;span style=&#34;color:#04a5e5;font-weight:bold&#34;&gt;=&lt;/span&gt;mid&lt;span style=&#34;color:#04a5e5;font-weight:bold&#34;&gt;-&lt;/span&gt;&lt;span style=&#34;color:#fe640b&#34;&gt;1&lt;/span&gt;&#xA;&lt;/span&gt;&lt;/span&gt;&lt;span style=&#34;display:flex;&#34;&gt;&lt;span&gt;        &lt;span style=&#34;color:#8839ef&#34;&gt;elif&lt;/span&gt; nums[mid] &lt;span style=&#34;color:#04a5e5;font-weight:bold&#34;&gt;&amp;lt;&lt;/span&gt; target:&#xA;&lt;/span&gt;&lt;/span&gt;&lt;span style=&#34;display:flex;&#34;&gt;&lt;span&gt;            left &lt;span style=&#34;color:#04a5e5;font-weight:bold&#34;&gt;=&lt;/span&gt; mid &lt;span style=&#34;color:#04a5e5;font-weight:bold&#34;&gt;+&lt;/span&gt; &lt;span style=&#34;color:#fe640b&#34;&gt;1&lt;/span&gt;&#xA;&lt;/span&gt;&lt;/span&gt;&lt;span style=&#34;display:flex;&#34;&gt;&lt;span&gt;        &lt;span style=&#34;color:#8839ef&#34;&gt;elif&lt;/span&gt; nums[mid] &lt;span style=&#34;color:#04a5e5;font-weight:bold&#34;&gt;&amp;gt;&lt;/span&gt; target:&#xA;&lt;/span&gt;&lt;/span&gt;&lt;span style=&#34;display:flex;&#34;&gt;&lt;span&gt;            right &lt;span style=&#34;color:#04a5e5;font-weight:bold&#34;&gt;=&lt;/span&gt; mid &lt;span style=&#34;color:#04a5e5;font-weight:bold&#34;&gt;-&lt;/span&gt; &lt;span style=&#34;color:#fe640b&#34;&gt;1&lt;/span&gt;&#xA;&lt;/span&gt;&lt;/span&gt;&lt;span style=&#34;display:flex;&#34;&gt;&lt;span&gt;    &lt;span style=&#34;color:#8839ef&#34;&gt;return&lt;/span&gt; left&#xA;&lt;/span&gt;&lt;/span&gt;&lt;/code&gt;&lt;/pre&gt;&lt;/td&gt;&lt;/tr&gt;&lt;/table&gt;&#xA;&lt;/div&gt;&#xA;&lt;/div&gt;&lt;h2 id=&#34;left-closed-right-open&#34;&gt;Left-Closed Right-Open&lt;/h2&gt;&#xA;&lt;h3 id=&#34;find-left-boundary-1&#34;&gt;Find Left Boundary&lt;/h3&gt;&#xA;&lt;div class=&#34;highlight&#34;&gt;&lt;div style=&#34;color:#4c4f69;background-color:#eff1f5;-moz-tab-size:2;-o-tab-size:2;tab-size:2;&#34;&gt;&#xA;&lt;table style=&#34;border-spacing:0;padding:0;margin:0;border:0;&#34;&gt;&lt;tr&gt;&lt;td style=&#34;vertical-align:top;padding:0;margin:0;border:0;&#34;&gt;&#xA;&lt;pre tabindex=&#34;0&#34; style=&#34;color:#4c4f69;background-color:#eff1f5;-moz-tab-size:2;-o-tab-size:2;tab-size:2;&#34;&gt;&lt;code&gt;&lt;span style=&#34;white-space:pre;-webkit-user-select:none;user-select:none;margin-right:0.4em;padding:0 0.4em 0 0.4em;color:#8c8fa1&#34;&gt; 1&#xA;&lt;/span&gt;&lt;span style=&#34;white-space:pre;-webkit-user-select:none;user-select:none;margin-right:0.4em;padding:0 0.4em 0 0.4em;color:#8c8fa1&#34;&gt; 2&#xA;&lt;/span&gt;&lt;span style=&#34;white-space:pre;-webkit-user-select:none;user-select:none;margin-right:0.4em;padding:0 0.4em 0 0.4em;color:#8c8fa1&#34;&gt; 3&#xA;&lt;/span&gt;&lt;span style=&#34;white-space:pre;-webkit-user-select:none;user-select:none;margin-right:0.4em;padding:0 0.4em 0 0.4em;color:#8c8fa1&#34;&gt; 4&#xA;&lt;/span&gt;&lt;span style=&#34;white-space:pre;-webkit-user-select:none;user-select:none;margin-right:0.4em;padding:0 0.4em 0 0.4em;color:#8c8fa1&#34;&gt; 5&#xA;&lt;/span&gt;&lt;span style=&#34;white-space:pre;-webkit-user-select:none;user-select:none;margin-right:0.4em;padding:0 0.4em 0 0.4em;color:#8c8fa1&#34;&gt; 6&#xA;&lt;/span&gt;&lt;span style=&#34;white-space:pre;-webkit-user-select:none;user-select:none;margin-right:0.4em;padding:0 0.4em 0 0.4em;color:#8c8fa1&#34;&gt; 7&#xA;&lt;/span&gt;&lt;span style=&#34;white-space:pre;-webkit-user-select:none;user-select:none;margin-right:0.4em;padding:0 0.4em 0 0.4em;color:#8c8fa1&#34;&gt; 8&#xA;&lt;/span&gt;&lt;span style=&#34;white-space:pre;-webkit-user-select:none;user-select:none;margin-right:0.4em;padding:0 0.4em 0 0.4em;color:#8c8fa1&#34;&gt; 9&#xA;&lt;/span&gt;&lt;span style=&#34;white-space:pre;-webkit-user-select:none;user-select:none;margin-right:0.4em;padding:0 0.4em 0 0.4em;color:#8c8fa1&#34;&gt;10&#xA;&lt;/span&gt;&lt;span style=&#34;white-space:pre;-webkit-user-select:none;user-select:none;margin-right:0.4em;padding:0 0.4em 0 0.4em;color:#8c8fa1&#34;&gt;11&#xA;&lt;/span&gt;&lt;span style=&#34;white-space:pre;-webkit-user-select:none;user-select:none;margin-right:0.4em;padding:0 0.4em 0 0.4em;color:#8c8fa1&#34;&gt;12&#xA;&lt;/span&gt;&lt;span style=&#34;white-space:pre;-webkit-user-select:none;user-select:none;margin-right:0.4em;padding:0 0.4em 0 0.4em;color:#8c8fa1&#34;&gt;13&#xA;&lt;/span&gt;&lt;span style=&#34;white-space:pre;-webkit-user-select:none;user-select:none;margin-right:0.4em;padding:0 0.4em 0 0.4em;color:#8c8fa1&#34;&gt;14&#xA;&lt;/span&gt;&lt;/code&gt;&lt;/pre&gt;&lt;/td&gt;&#xA;&lt;td style=&#34;vertical-align:top;padding:0;margin:0;border:0;;width:100%&#34;&gt;&#xA;&lt;pre tabindex=&#34;0&#34; style=&#34;color:#4c4f69;background-color:#eff1f5;-moz-tab-size:2;-o-tab-size:2;tab-size:2;&#34;&gt;&lt;code class=&#34;language-python&#34; data-lang=&#34;python&#34;&gt;&lt;span style=&#34;display:flex;&#34;&gt;&lt;span&gt;&lt;span style=&#34;color:#8839ef&#34;&gt;def&lt;/span&gt; &lt;span style=&#34;color:#1e66f5&#34;&gt;left_bound&lt;/span&gt;(nums: List[&lt;span style=&#34;color:#04a5e5&#34;&gt;int&lt;/span&gt;], target: &lt;span style=&#34;color:#04a5e5&#34;&gt;int&lt;/span&gt;) &lt;span style=&#34;color:#04a5e5;font-weight:bold&#34;&gt;-&amp;gt;&lt;/span&gt; &lt;span style=&#34;color:#04a5e5&#34;&gt;int&lt;/span&gt;:&#xA;&lt;/span&gt;&lt;/span&gt;&lt;span style=&#34;display:flex;&#34;&gt;&lt;span&gt;    left &lt;span style=&#34;color:#04a5e5;font-weight:bold&#34;&gt;=&lt;/span&gt; &lt;span style=&#34;color:#fe640b&#34;&gt;0&lt;/span&gt;&#xA;&lt;/span&gt;&lt;/span&gt;&lt;span style=&#34;display:flex;&#34;&gt;&lt;span&gt;    right &lt;span style=&#34;color:#04a5e5;font-weight:bold&#34;&gt;=&lt;/span&gt; &lt;span style=&#34;color:#04a5e5&#34;&gt;len&lt;/span&gt;(nums)&#xA;&lt;/span&gt;&lt;/span&gt;&lt;span style=&#34;display:flex;&#34;&gt;&lt;span&gt;    &#xA;&lt;/span&gt;&lt;/span&gt;&lt;span style=&#34;display:flex;&#34;&gt;&lt;span&gt;    &lt;span style=&#34;color:#8839ef&#34;&gt;while&lt;/span&gt; left &lt;span style=&#34;color:#04a5e5;font-weight:bold&#34;&gt;&amp;lt;&lt;/span&gt; right:&#xA;&lt;/span&gt;&lt;/span&gt;&lt;span style=&#34;display:flex;&#34;&gt;&lt;span&gt;        mid &lt;span style=&#34;color:#04a5e5;font-weight:bold&#34;&gt;=&lt;/span&gt; left &lt;span style=&#34;color:#04a5e5;font-weight:bold&#34;&gt;+&lt;/span&gt; (right &lt;span style=&#34;color:#04a5e5;font-weight:bold&#34;&gt;-&lt;/span&gt; left) &lt;span style=&#34;color:#04a5e5;font-weight:bold&#34;&gt;//&lt;/span&gt; &lt;span style=&#34;color:#fe640b&#34;&gt;2&lt;/span&gt;&#xA;&lt;/span&gt;&lt;/span&gt;&lt;span style=&#34;display:flex;&#34;&gt;&lt;span&gt;        &lt;span style=&#34;color:#8839ef&#34;&gt;if&lt;/span&gt; nums[mid] &lt;span style=&#34;color:#04a5e5;font-weight:bold&#34;&gt;==&lt;/span&gt; target:&#xA;&lt;/span&gt;&lt;/span&gt;&lt;span style=&#34;display:flex;&#34;&gt;&lt;span&gt;            right &lt;span style=&#34;color:#04a5e5;font-weight:bold&#34;&gt;=&lt;/span&gt; mid&#xA;&lt;/span&gt;&lt;/span&gt;&lt;span style=&#34;display:flex;&#34;&gt;&lt;span&gt;        &lt;span style=&#34;color:#8839ef&#34;&gt;elif&lt;/span&gt; nums[mid] &lt;span style=&#34;color:#04a5e5;font-weight:bold&#34;&gt;&amp;lt;&lt;/span&gt; target:&#xA;&lt;/span&gt;&lt;/span&gt;&lt;span style=&#34;display:flex;&#34;&gt;&lt;span&gt;            left &lt;span style=&#34;color:#04a5e5;font-weight:bold&#34;&gt;=&lt;/span&gt; mid &lt;span style=&#34;color:#04a5e5;font-weight:bold&#34;&gt;+&lt;/span&gt; &lt;span style=&#34;color:#fe640b&#34;&gt;1&lt;/span&gt;&#xA;&lt;/span&gt;&lt;/span&gt;&lt;span style=&#34;display:flex;&#34;&gt;&lt;span&gt;        &lt;span style=&#34;color:#8839ef&#34;&gt;elif&lt;/span&gt; nums[mid] &lt;span style=&#34;color:#04a5e5;font-weight:bold&#34;&gt;&amp;gt;&lt;/span&gt; target:&#xA;&lt;/span&gt;&lt;/span&gt;&lt;span style=&#34;display:flex;&#34;&gt;&lt;span&gt;            right &lt;span style=&#34;color:#04a5e5;font-weight:bold&#34;&gt;=&lt;/span&gt; mid&#xA;&lt;/span&gt;&lt;/span&gt;&lt;span style=&#34;display:flex;&#34;&gt;&lt;span&gt;&#xA;&lt;/span&gt;&lt;/span&gt;&lt;span style=&#34;display:flex;&#34;&gt;&lt;span&gt;    &lt;span style=&#34;color:#8839ef&#34;&gt;return&lt;/span&gt; left&#xA;&lt;/span&gt;&lt;/span&gt;&lt;/code&gt;&lt;/pre&gt;&lt;/td&gt;&lt;/tr&gt;&lt;/table&gt;&#xA;&lt;/div&gt;&#xA;&lt;/div&gt;&lt;p&gt;If target doesn&amp;rsquo;t exist, left-bound binary search returns index of smallest element &amp;gt; target.&lt;/p&gt;</description>
    </item>
    <item>
      <title>BlackHorse Rating Login Design</title>
      <link>https://ruokezhang.github.io/en/post/blackhorserating/login/</link>
      <pubDate>Thu, 13 Mar 2025 00:00:00 +0000</pubDate>
      <guid>https://ruokezhang.github.io/en/post/blackhorserating/login/</guid>
      <description>&lt;p&gt;&lt;img src=&#34;https://blog-ruoke.oss-cn-hongkong.aliyuncs.com/static/login.png&#34; alt=&#34;Alt text&#34;&gt;&lt;/p&gt;&#xA;&lt;h2 id=&#34;sms-verification-code-login&#34;&gt;SMS Verification Code Login&lt;/h2&gt;&#xA;&lt;ol&gt;&#xA;&lt;li&gt;User enters phone number on login page and clicks &amp;ldquo;Get Code&amp;rdquo;. Backend validates phone format, generates a verification code, stores phone:code in Redis with 2-minute expiry.&lt;/li&gt;&#xA;&lt;li&gt;User enters code and clicks &amp;ldquo;Login&amp;rdquo;. Backend compares submitted code with stored value.&lt;/li&gt;&#xA;&lt;li&gt;If user doesn&amp;rsquo;t exist, create and save to database.&lt;/li&gt;&#xA;&lt;li&gt;Generate random token as login credential; convert User object to Hash and store as token:userHash in Redis.&lt;/li&gt;&#xA;&lt;/ol&gt;&#xA;&lt;h2 id=&#34;login-status-validation&#34;&gt;Login Status Validation&lt;/h2&gt;&#xA;&lt;ol&gt;&#xA;&lt;li&gt;Requests carry token in header. RefreshTokenInterceptor intercepts all requests (passes through if no token).&lt;/li&gt;&#xA;&lt;li&gt;Extract token from header, retrieve user Map from Redis using token.&lt;/li&gt;&#xA;&lt;li&gt;If user exists, convert Map to UserDTO, store in ThreadLocal, and refresh token expiry.&lt;/li&gt;&#xA;&lt;/ol&gt;&#xA;&lt;p&gt;LoginInterceptor intercepts all paths except specified public ones. If UserHolder is empty (not logged in), request is rejected.&lt;/p&gt;</description>
    </item>
    <item>
      <title>Exceptions, Generics</title>
      <link>https://ruokezhang.github.io/en/post/java/javabasic/exceptionr/</link>
      <pubDate>Thu, 13 Mar 2025 00:00:00 +0000</pubDate>
      <guid>https://ruokezhang.github.io/en/post/java/javabasic/exceptionr/</guid>
      <description>&lt;h2 id=&#34;exceptions&#34;&gt;Exceptions&lt;/h2&gt;&#xA;&lt;h3 id=&#34;throwable&#34;&gt;Throwable&lt;/h3&gt;&#xA;&lt;p&gt;&lt;img src=&#34;image.png&#34; alt=&#34;Alt text&#34;&gt;&#xA;Throwable has two subclasses: Exception and Error.&lt;/p&gt;&#xA;&lt;p&gt;Error class represents serious errors, which are generally not recommended to be caught by &lt;code&gt;catch&lt;/code&gt; in our programs. We can only optimize Errors by optimizing the code. When an Error occurs, &lt;strong&gt;JVM generally chooses to terminate the thread&lt;/strong&gt;.&lt;/p&gt;&#xA;&lt;p&gt;Exception class has two subclasses: Checked Exception and Unchecked Exception.&#xA;Checked Exception means that the exception will be checked at compile time. If the exception is not caught by &lt;code&gt;catch&lt;/code&gt; or not &lt;code&gt;throws&lt;/code&gt;, it will not pass compilation. This includes &lt;code&gt;IOException&lt;/code&gt;, &lt;code&gt;ClassNotFoundException&lt;/code&gt;.&#xA;Unchecked Exception means that it will not be checked at compile time. It includes &lt;code&gt;RuntimeException&lt;/code&gt; and its subclasses, such as &lt;code&gt;NullPointerException&lt;/code&gt;, &lt;code&gt;ArrayIndexOutOfBoundsException&lt;/code&gt;, and &lt;code&gt;ClassCastException&lt;/code&gt; that may occur during forced type conversion.&lt;/p&gt;</description>
    </item>
    <item>
      <title>Graph</title>
      <link>https://ruokezhang.github.io/en/post/leetcode/dfs_bfs/</link>
      <pubDate>Thu, 13 Mar 2025 00:00:00 +0000</pubDate>
      <guid>https://ruokezhang.github.io/en/post/leetcode/dfs_bfs/</guid>
      <description>&lt;p&gt;&lt;a href=&#34;https://leetcode.cn/discuss/post/3581143/fen-xiang-gun-ti-dan-tu-lun-suan-fa-dfsb-qyux/&#34;&gt;Graph Problem List&lt;/a&gt;&lt;/p&gt;&#xA;&lt;p&gt;&lt;a href=&#34;https://leetcode.cn/discuss/post/3580195/fen-xiang-gun-ti-dan-wang-ge-tu-dfsbfszo-l3pa/&#34;&gt;Grid Graph Problem List&lt;/a&gt;&lt;/p&gt;&#xA;&lt;h2 id=&#34;graph&#34;&gt;Graph&lt;/h2&gt;&#xA;&lt;h3 id=&#34;dfs&#34;&gt;DFS&lt;/h3&gt;&#xA;&lt;p&gt;Find connected components, check for cycles&lt;/p&gt;&#xA;&lt;h4 id=&#34;261-graph-valid-tree&#34;&gt;261. Graph Valid Tree&lt;/h4&gt;&#xA;&lt;p&gt;&lt;strong&gt;Undirected graph&lt;/strong&gt;, check if it&amp;rsquo;s &lt;strong&gt;acyclic and connected&lt;/strong&gt;.&lt;/p&gt;&#xA;&lt;p&gt;Using vis[i]=True is sufficient. However, since it&amp;rsquo;s an undirected graph, when traversing neighbors, you need to skip the parent node, so it needs to be passed as a parameter.&lt;/p&gt;&#xA;&lt;div class=&#34;highlight&#34;&gt;&lt;div style=&#34;color:#4c4f69;background-color:#eff1f5;-moz-tab-size:2;-o-tab-size:2;tab-size:2;&#34;&gt;&#xA;&lt;table style=&#34;border-spacing:0;padding:0;margin:0;border:0;&#34;&gt;&lt;tr&gt;&lt;td style=&#34;vertical-align:top;padding:0;margin:0;border:0;&#34;&gt;&#xA;&lt;pre tabindex=&#34;0&#34; style=&#34;color:#4c4f69;background-color:#eff1f5;-moz-tab-size:2;-o-tab-size:2;tab-size:2;&#34;&gt;&lt;code&gt;&lt;span style=&#34;white-space:pre;-webkit-user-select:none;user-select:none;margin-right:0.4em;padding:0 0.4em 0 0.4em;color:#8c8fa1&#34;&gt; 1&#xA;&lt;/span&gt;&lt;span style=&#34;white-space:pre;-webkit-user-select:none;user-select:none;margin-right:0.4em;padding:0 0.4em 0 0.4em;color:#8c8fa1&#34;&gt; 2&#xA;&lt;/span&gt;&lt;span style=&#34;white-space:pre;-webkit-user-select:none;user-select:none;margin-right:0.4em;padding:0 0.4em 0 0.4em;color:#8c8fa1&#34;&gt; 3&#xA;&lt;/span&gt;&lt;span style=&#34;white-space:pre;-webkit-user-select:none;user-select:none;margin-right:0.4em;padding:0 0.4em 0 0.4em;color:#8c8fa1&#34;&gt; 4&#xA;&lt;/span&gt;&lt;span style=&#34;white-space:pre;-webkit-user-select:none;user-select:none;margin-right:0.4em;padding:0 0.4em 0 0.4em;color:#8c8fa1&#34;&gt; 5&#xA;&lt;/span&gt;&lt;span style=&#34;white-space:pre;-webkit-user-select:none;user-select:none;margin-right:0.4em;padding:0 0.4em 0 0.4em;color:#8c8fa1&#34;&gt; 6&#xA;&lt;/span&gt;&lt;span style=&#34;white-space:pre;-webkit-user-select:none;user-select:none;margin-right:0.4em;padding:0 0.4em 0 0.4em;color:#8c8fa1&#34;&gt; 7&#xA;&lt;/span&gt;&lt;span style=&#34;white-space:pre;-webkit-user-select:none;user-select:none;margin-right:0.4em;padding:0 0.4em 0 0.4em;color:#8c8fa1&#34;&gt; 8&#xA;&lt;/span&gt;&lt;span style=&#34;white-space:pre;-webkit-user-select:none;user-select:none;margin-right:0.4em;padding:0 0.4em 0 0.4em;color:#8c8fa1&#34;&gt; 9&#xA;&lt;/span&gt;&lt;span style=&#34;white-space:pre;-webkit-user-select:none;user-select:none;margin-right:0.4em;padding:0 0.4em 0 0.4em;color:#8c8fa1&#34;&gt;10&#xA;&lt;/span&gt;&lt;/code&gt;&lt;/pre&gt;&lt;/td&gt;&#xA;&lt;td style=&#34;vertical-align:top;padding:0;margin:0;border:0;;width:100%&#34;&gt;&#xA;&lt;pre tabindex=&#34;0&#34; style=&#34;color:#4c4f69;background-color:#eff1f5;-moz-tab-size:2;-o-tab-size:2;tab-size:2;&#34;&gt;&lt;code class=&#34;language-py&#34; data-lang=&#34;py&#34;&gt;&lt;span style=&#34;display:flex;&#34;&gt;&lt;span&gt;&lt;span style=&#34;color:#8839ef&#34;&gt;def&lt;/span&gt; &lt;span style=&#34;color:#1e66f5&#34;&gt;dfs&lt;/span&gt;(i, parent):&#xA;&lt;/span&gt;&lt;/span&gt;&lt;span style=&#34;display:flex;&#34;&gt;&lt;span&gt;    vis[i]&lt;span style=&#34;color:#04a5e5;font-weight:bold&#34;&gt;=&lt;/span&gt;&lt;span style=&#34;color:#fe640b&#34;&gt;True&lt;/span&gt;&#xA;&lt;/span&gt;&lt;/span&gt;&lt;span style=&#34;display:flex;&#34;&gt;&lt;span&gt;    &lt;span style=&#34;color:#8839ef&#34;&gt;for&lt;/span&gt; nxt &lt;span style=&#34;color:#04a5e5;font-weight:bold&#34;&gt;in&lt;/span&gt; g[i]:&#xA;&lt;/span&gt;&lt;/span&gt;&lt;span style=&#34;display:flex;&#34;&gt;&lt;span&gt;        &lt;span style=&#34;color:#8839ef&#34;&gt;if&lt;/span&gt; nxt&lt;span style=&#34;color:#04a5e5;font-weight:bold&#34;&gt;==&lt;/span&gt;parent:&#xA;&lt;/span&gt;&lt;/span&gt;&lt;span style=&#34;display:flex;&#34;&gt;&lt;span&gt;            &lt;span style=&#34;color:#8839ef&#34;&gt;continue&lt;/span&gt;&#xA;&lt;/span&gt;&lt;/span&gt;&lt;span style=&#34;display:flex;&#34;&gt;&lt;span&gt;        &lt;span style=&#34;color:#8839ef&#34;&gt;if&lt;/span&gt; vis[nxt]:&#xA;&lt;/span&gt;&lt;/span&gt;&lt;span style=&#34;display:flex;&#34;&gt;&lt;span&gt;            &lt;span style=&#34;color:#8839ef&#34;&gt;return&lt;/span&gt; &lt;span style=&#34;color:#fe640b&#34;&gt;False&lt;/span&gt;&#xA;&lt;/span&gt;&lt;/span&gt;&lt;span style=&#34;display:flex;&#34;&gt;&lt;span&gt;        &lt;span style=&#34;color:#8839ef&#34;&gt;if&lt;/span&gt; &lt;span style=&#34;color:#04a5e5;font-weight:bold&#34;&gt;not&lt;/span&gt; dfs(nxt, i):&#xA;&lt;/span&gt;&lt;/span&gt;&lt;span style=&#34;display:flex;&#34;&gt;&lt;span&gt;            &lt;span style=&#34;color:#8839ef&#34;&gt;return&lt;/span&gt; &lt;span style=&#34;color:#fe640b&#34;&gt;False&lt;/span&gt;&#xA;&lt;/span&gt;&lt;/span&gt;&lt;span style=&#34;display:flex;&#34;&gt;&lt;span&gt;    &lt;span style=&#34;color:#8839ef&#34;&gt;return&lt;/span&gt; &lt;span style=&#34;color:#fe640b&#34;&gt;True&lt;/span&gt;&#xA;&lt;/span&gt;&lt;/span&gt;&lt;/code&gt;&lt;/pre&gt;&lt;/td&gt;&lt;/tr&gt;&lt;/table&gt;&#xA;&lt;/div&gt;&#xA;&lt;/div&gt;&lt;p&gt;For example, 1-3-6, 1-5-6. If connected this way, there must be a cycle, so three colors are not needed.&lt;/p&gt;</description>
    </item>
    <item>
      <title>Java Collections</title>
      <link>https://ruokezhang.github.io/en/post/java/javabasic/collection/</link>
      <pubDate>Tue, 11 Mar 2025 00:00:00 +0000</pubDate>
      <guid>https://ruokezhang.github.io/en/post/java/javabasic/collection/</guid>
      <description>&lt;h2 id=&#34;collection-interface&#34;&gt;Collection Interface&lt;/h2&gt;&#xA;&lt;p&gt;&lt;img src=&#34;https://blog-ruoke.oss-cn-hongkong.aliyuncs.com/static/hierarchy-of-collection-framework.jpg&#34; alt=&#34;collection&#34;&gt;&lt;/p&gt;&#xA;&lt;h2 id=&#34;list&#34;&gt;List&lt;/h2&gt;&#xA;&lt;h3 id=&#34;arraylist&#34;&gt;ArrayList&lt;/h3&gt;&#xA;&lt;h4 id=&#34;basic-concepts&#34;&gt;Basic Concepts&lt;/h4&gt;&#xA;&lt;ol&gt;&#xA;&lt;li&gt;Allows null values.&lt;/li&gt;&#xA;&lt;li&gt;Memory is contiguous, saving memory space.&lt;/li&gt;&#xA;&lt;li&gt;Insertion time complexity: O(n) for insertion at the head because all subsequent elements need to be shifted; O(1) for insertion at the tail if no resizing is needed, otherwise O(n) to copy the original ArrayList and then O(1) for insertion. O(n) for insertion in the middle.&lt;/li&gt;&#xA;&lt;li&gt;Deletion time complexity: Corresponds to insertion time complexity.&lt;/li&gt;&#xA;&lt;li&gt;Not thread-safe.&lt;/li&gt;&#xA;&lt;/ol&gt;&#xA;&lt;h4 id=&#34;underlying-implementation&#34;&gt;Underlying Implementation&lt;/h4&gt;&#xA;&lt;ol&gt;&#xA;&lt;li&gt;Implemented by dynamic array. Random access to a node only requires calculating its address, so random access is O(1). Implements the &lt;code&gt;RandomAccess&lt;/code&gt; marker interface.&lt;/li&gt;&#xA;&lt;li&gt;If no initial capacity is specified, the default initial capacity is 0. When the first element is added, the capacity becomes 10. &lt;strong&gt;Each dynamic expansion increases the capacity to 1.5 times the original.&lt;/strong&gt;&lt;/li&gt;&#xA;&lt;/ol&gt;&#xA;&lt;h4 id=&#34;differences-between-arraylist-and-array&#34;&gt;Differences between ArrayList and Array&lt;/h4&gt;&#xA;&lt;ol&gt;&#xA;&lt;li&gt;ArrayList can be dynamically resized; Array cannot, its length is fixed and needs to be specified when initializing the array.&lt;/li&gt;&#xA;&lt;li&gt;ArrayList supports generics.&lt;/li&gt;&#xA;&lt;li&gt;ArrayList only supports objects; for primitive data types, their wrapper classes like Integer, Double are needed. Array supports both primitive data types and objects.&lt;/li&gt;&#xA;&lt;/ol&gt;&#xA;&lt;h3 id=&#34;linkedlist&#34;&gt;LinkedList&lt;/h3&gt;&#xA;&lt;h4 id=&#34;underlying-implementation-1&#34;&gt;Underlying Implementation&lt;/h4&gt;&#xA;&lt;ol&gt;&#xA;&lt;li&gt;Implemented by a doubly linked list. Insertion/deletion at the head/tail are both O(1).&lt;/li&gt;&#xA;&lt;li&gt;Does not support random access. Time complexity for accessing a specific element is O(n).&lt;/li&gt;&#xA;&lt;li&gt;Performance is not as good as ArrayList, rarely used in actual development.&lt;/li&gt;&#xA;&lt;li&gt;Not thread-safe.&lt;/li&gt;&#xA;&lt;li&gt;Allows null values.&lt;/li&gt;&#xA;&lt;li&gt;Occupies more space than ArrayList because it stores pointers in addition to data.&lt;/li&gt;&#xA;&lt;/ol&gt;&#xA;&lt;h2 id=&#34;hashmap&#34;&gt;HashMap&lt;/h2&gt;&#xA;&lt;h3 id=&#34;implementation-principle&#34;&gt;Implementation Principle&lt;/h3&gt;&#xA;&lt;ol&gt;&#xA;&lt;li&gt;Implemented by hash table + linked list/red-black tree. Hash collision resolution methods include chaining/probing, usually chaining.&lt;/li&gt;&#xA;&lt;li&gt;How is the hash value calculated? Get the &lt;code&gt;hashCode()&lt;/code&gt; of the key. Perform an XOR operation between the &lt;strong&gt;original hashcode and the hashcode shifted right by 16 bits&lt;/strong&gt;.&lt;/li&gt;&#xA;&lt;/ol&gt;&#xA;&lt;div class=&#34;highlight&#34;&gt;&lt;div style=&#34;color:#4c4f69;background-color:#eff1f5;-moz-tab-size:2;-o-tab-size:2;tab-size:2;&#34;&gt;&#xA;&lt;table style=&#34;border-spacing:0;padding:0;margin:0;border:0;&#34;&gt;&lt;tr&gt;&lt;td style=&#34;vertical-align:top;padding:0;margin:0;border:0;&#34;&gt;&#xA;&lt;pre tabindex=&#34;0&#34; style=&#34;color:#4c4f69;background-color:#eff1f5;-moz-tab-size:2;-o-tab-size:2;tab-size:2;&#34;&gt;&lt;code&gt;&lt;span style=&#34;white-space:pre;-webkit-user-select:none;user-select:none;margin-right:0.4em;padding:0 0.4em 0 0.4em;color:#8c8fa1&#34;&gt;1&#xA;&lt;/span&gt;&lt;/code&gt;&lt;/pre&gt;&lt;/td&gt;&#xA;&lt;td style=&#34;vertical-align:top;padding:0;margin:0;border:0;;width:100%&#34;&gt;&#xA;&lt;pre tabindex=&#34;0&#34; style=&#34;color:#4c4f69;background-color:#eff1f5;-moz-tab-size:2;-o-tab-size:2;tab-size:2;&#34;&gt;&lt;code class=&#34;language-java&#34; data-lang=&#34;java&#34;&gt;&lt;span style=&#34;display:flex;&#34;&gt;&lt;span&gt;&lt;span style=&#34;color:#d20f39&#34;&gt;int&lt;/span&gt; hash &lt;span style=&#34;color:#04a5e5;font-weight:bold&#34;&gt;=&lt;/span&gt; (key &lt;span style=&#34;color:#04a5e5;font-weight:bold&#34;&gt;==&lt;/span&gt; &lt;span style=&#34;color:#fe640b&#34;&gt;null&lt;/span&gt;) &lt;span style=&#34;color:#04a5e5;font-weight:bold&#34;&gt;?&lt;/span&gt; 0 : (key.&lt;span style=&#34;color:#1e66f5&#34;&gt;hashCode&lt;/span&gt;()) &lt;span style=&#34;color:#04a5e5;font-weight:bold&#34;&gt;^&lt;/span&gt; ((key.&lt;span style=&#34;color:#1e66f5&#34;&gt;hashCode&lt;/span&gt;()) &lt;span style=&#34;color:#04a5e5;font-weight:bold&#34;&gt;&amp;gt;&amp;gt;&amp;gt;&lt;/span&gt; 16);&#xA;&lt;/span&gt;&lt;/span&gt;&lt;/code&gt;&lt;/pre&gt;&lt;/td&gt;&lt;/tr&gt;&lt;/table&gt;&#xA;&lt;/div&gt;&#xA;&lt;/div&gt;&lt;ol start=&#34;3&#34;&gt;&#xA;&lt;li&gt;Calculate array index. &lt;strong&gt;&lt;code&gt;hash &amp;amp; (length - 1)&lt;/code&gt;&lt;/strong&gt;, equivalent to &lt;code&gt;hash % length&lt;/code&gt;. Binary operations are faster than modulo operations.&lt;/li&gt;&#xA;&lt;li&gt;If a collision occurs, check if the key exists in the linked list or red-black tree. If it exists, replace the value directly. If not, add it. When the linked list length is 8 and the hash table length is greater than 64, it is converted to a red-black tree.&lt;/li&gt;&#xA;&lt;li&gt;If the number of red-black tree nodes is less than 6, it reverts to a linked list.&lt;/li&gt;&#xA;&lt;li&gt;Initial capacity is 16, load factor is 0.75, expands to twice the original size.&lt;/li&gt;&#xA;&lt;li&gt;Not thread-safe. Resizing may cause a circular linked list.&lt;/li&gt;&#xA;&lt;/ol&gt;&#xA;&lt;h3 id=&#34;time-complexity&#34;&gt;Time Complexity&lt;/h3&gt;&#xA;&lt;p&gt;Ideally, the average time complexity for HashMap&amp;rsquo;s insertion, deletion, and lookup operations is O(1).&#xA;If converted to a red-black tree, the time complexity of operations will stabilize at O(log n).&lt;/p&gt;</description>
    </item>
    <item>
      <title>Distributed Training</title>
      <link>https://ruokezhang.github.io/en/ai/parallelism/</link>
      <pubDate>Sat, 08 Mar 2025 00:00:00 +0000</pubDate>
      <guid>https://ruokezhang.github.io/en/ai/parallelism/</guid>
      <description>&lt;h2 id=&#34;communication-methods&#34;&gt;Communication Methods&lt;/h2&gt;&#xA;&lt;h3 id=&#34;intra-machine-communication&#34;&gt;Intra-Machine Communication&lt;/h3&gt;&#xA;&lt;ol&gt;&#xA;&lt;li&gt;NVLink: Technology for direct communication between GPUs. NVLink 3.0 has a unidirectional bandwidth of up to 50 GB/s.&lt;/li&gt;&#xA;&lt;li&gt;PCIe: A universal high-speed bus standard used to connect GPUs, CPUs, and other peripherals.&#xA;Under the PCIe architecture, communication between GPUs requires going through the CPU and system memory, with bandwidth and latency not as good as NVLink. PCIe 4.0 x16 has a unidirectional bandwidth of 31.5 GB/s.&#xA;PCIe Switch is used to expand PCIe lanes, allowing multiple devices to share bandwidth.&lt;/li&gt;&#xA;&lt;/ol&gt;&#xA;&lt;h3 id=&#34;inter-machine-communication&#34;&gt;Inter-Machine Communication&lt;/h3&gt;&#xA;&lt;p&gt;TCP/IP: Communication rate is limited by hardware and is slower than intra-machine communication.&lt;/p&gt;</description>
    </item>
    <item>
      <title>Process</title>
      <link>https://ruokezhang.github.io/en/post/os/process/</link>
      <pubDate>Fri, 07 Mar 2025 00:00:00 +0000</pubDate>
      <guid>https://ruokezhang.github.io/en/post/os/process/</guid>
      <description>&lt;h2 id=&#34;process&#34;&gt;Process&lt;/h2&gt;&#xA;&lt;p&gt;A process uniquely owns:&lt;/p&gt;&#xA;&lt;ol&gt;&#xA;&lt;li&gt;PC&lt;/li&gt;&#xA;&lt;li&gt;Stack pointer (stores return addresses)&lt;/li&gt;&#xA;&lt;li&gt;Address space&lt;/li&gt;&#xA;&lt;li&gt;File descriptors&lt;/li&gt;&#xA;&lt;/ol&gt;&#xA;&lt;p&gt;To manipulate a process, user code must invoke system calls to enter kernel mode. Always check syscall return values; -1 indicates an error.&lt;/p&gt;&#xA;&lt;h3 id=&#34;kernel-space&#34;&gt;Kernel Space&lt;/h3&gt;&#xA;&lt;ol&gt;&#xA;&lt;li&gt;Kernel space is at the top of the entire virtual address space and is shared by all user processes. User processes occupy the lower portion.&lt;/li&gt;&#xA;&lt;li&gt;As long as the system is running, the kernel remains active. It doesn’t start/stop like ordinary processes; it initializes at boot and runs until shutdown.&lt;/li&gt;&#xA;&lt;/ol&gt;&#xA;&lt;h3 id=&#34;process-termination&#34;&gt;Process termination&lt;/h3&gt;&#xA;&lt;p&gt;A process can terminate via three paths:&lt;/p&gt;</description>
    </item>
    <item>
      <title>Redis Persistence: AOF and RDB</title>
      <link>https://ruokezhang.github.io/en/post/redis/aofrdb/</link>
      <pubDate>Fri, 07 Mar 2025 00:00:00 +0000</pubDate>
      <guid>https://ruokezhang.github.io/en/post/redis/aofrdb/</guid>
      <description>&lt;p&gt;References: &lt;a href=&#34;https://www.bilibili.com/video/BV1sK421i7B8/&#34;&gt;Xiaolin Coding video&lt;/a&gt; and &lt;a href=&#34;https://redis.io/docs/latest/operate/oss_and_stack/management/persistence/&#34;&gt;Redis persistence documentation&lt;/a&gt;.&lt;/p&gt;&#xA;&lt;h2 id=&#34;append-only-file-aof&#34;&gt;Append-Only File (AOF)&lt;/h2&gt;&#xA;&lt;p&gt;AOF records write operations after Redis applies them in memory. Redis can replay the log at startup to reconstruct the dataset. The log uses the Redis protocol format, so it is generally larger than an RDB snapshot.&lt;/p&gt;&#xA;&lt;h3 id=&#34;why-log-after-executing-a-command&#34;&gt;Why Log After Executing a Command?&lt;/h3&gt;&#xA;&lt;p&gt;Redis records a write only after it has accepted and executed it. Appending and syncing the log still have a cost; the chosen &lt;code&gt;appendfsync&lt;/code&gt; policy determines the durability and performance tradeoff.&lt;/p&gt;</description>
    </item>
    <item>
      <title>Virtualization</title>
      <link>https://ruokezhang.github.io/en/post/os/virtualization/</link>
      <pubDate>Wed, 05 Mar 2025 00:00:00 +0000</pubDate>
      <guid>https://ruokezhang.github.io/en/post/os/virtualization/</guid>
      <description>&lt;p&gt;&lt;a href=&#34;https://notes.yxy.ninja/OS/Process/Address-Space&#34;&gt;Referenced technical blog&lt;/a&gt;&lt;br&gt;&#xA;&lt;a href=&#34;https://pages.cs.wisc.edu/~remzi/OSTEP/Educators-Slides/Tyler/sep17/paging.pdf&#34;&gt;OSTEP slides&lt;/a&gt;&lt;br&gt;&#xA;&lt;a href=&#34;https://os.phil-opp.com/paging-introduction/&#34;&gt;Reference&lt;/a&gt;&lt;/p&gt;&#xA;&lt;h2 id=&#34;virtual-memory&#34;&gt;Virtual Memory&lt;/h2&gt;&#xA;&lt;p&gt;Virtualization: each process believes it has its own address space, and different processes&amp;rsquo; address spaces are isolated from each other.&#xA;&lt;img src=&#34;https://blog-ruoke.oss-cn-hongkong.aliyuncs.com/static/address_space.png&#34; alt=&#34;Address Space&#34;&gt;&lt;/p&gt;&#xA;&lt;p&gt;In practice, when the CPU gets a virtual address, the MMU inside the CPU translates the virtual address into a physical address (an address in main memory). Each memory address refers to a single byte.&lt;/p&gt;&#xA;&lt;h3 id=&#34;segmentation&#34;&gt;Segmentation&lt;/h3&gt;&#xA;&lt;p&gt;Each segment corresponds to a logical entity in the address space, for example the stack or data. Each segment can:&lt;/p&gt;</description>
    </item>
    <item>
      <title>Troubleshooting</title>
      <link>https://ruokezhang.github.io/en/post/java/jvm/oom/</link>
      <pubDate>Mon, 03 Mar 2025 00:00:00 +0000</pubDate>
      <guid>https://ruokezhang.github.io/en/post/java/jvm/oom/</guid>
      <description>&lt;p&gt;&lt;a href=&#34;https://www.bilibili.com/video/BV1Lb4y1j7uc/?spm_id_from=333.337.search-card.all.click&amp;amp;vd_source=3417d90294dd8bcb1cc2b3dc8bc1ef3c&#34;&gt;Reference video (Chinese)&lt;/a&gt;&lt;/p&gt;&#xA;&lt;h2 id=&#34;causes-of-outofmemoryerror&#34;&gt;Causes of OutOfMemoryError&lt;/h2&gt;&#xA;&lt;ol&gt;&#xA;&lt;li&gt;Allocating too many objects at once → use pagination/streaming&lt;/li&gt;&#xA;&lt;li&gt;Memory leak: reachable but no-longer-needed objects still retained → find and release them&lt;/li&gt;&#xA;&lt;li&gt;Insufficient resources → use  to inspect the heap&lt;/li&gt;&#xA;&lt;/ol&gt;&#xA;&lt;blockquote&gt;&#xA;&lt;p&gt;jmap is a JDK CLI tool to generate a heap dump. A heap dump is a binary snapshot of all objects on the heap.&#xA;Or add -XX:+HeapDumpOnOutOfMemoryError so the JVM dumps the heap automatically on OOM.&lt;/p&gt;</description>
    </item>
    <item>
      <title>Transaction</title>
      <link>https://ruokezhang.github.io/en/post/mysql-transaction/</link>
      <pubDate>Sun, 02 Mar 2025 00:00:00 +0000</pubDate>
      <guid>https://ruokezhang.github.io/en/post/mysql-transaction/</guid>
      <description>&lt;p&gt;Reference: Xiaolin Coding&lt;/p&gt;&#xA;&lt;h2 id=&#34;transaction-properties&#34;&gt;Transaction Properties&lt;/h2&gt;&#xA;&lt;p&gt;&lt;strong&gt;Atomicity&lt;/strong&gt;: Implemented via &lt;code&gt;undo log&lt;/code&gt;.&lt;/p&gt;&#xA;&lt;p&gt;&lt;strong&gt;Consistency&lt;/strong&gt;: Achieved through the other three properties. Before and after a transaction, the database transitions from one consistent state to another.&lt;/p&gt;&#xA;&lt;p&gt;&lt;strong&gt;Isolation&lt;/strong&gt;: Implemented via MVCC/locking. The execution of one transaction does not affect the execution of others.&lt;/p&gt;&#xA;&lt;p&gt;&lt;strong&gt;Durability&lt;/strong&gt;: Implemented via &lt;code&gt;redo log&lt;/code&gt;. Once a transaction is committed, its changes to the database are permanent, even in the event of a system failure or crash.&lt;/p&gt;</description>
    </item>
    <item>
      <title>Indexes</title>
      <link>https://ruokezhang.github.io/en/post/mysql-indexes/</link>
      <pubDate>Fri, 28 Feb 2025 00:00:00 +0000</pubDate>
      <guid>https://ruokezhang.github.io/en/post/mysql-indexes/</guid>
      <description>&lt;h2 id=&#34;clustered-index-secondary-index&#34;&gt;Clustered Index, Secondary Index&lt;/h2&gt;&#xA;&lt;h3 id=&#34;clustered-index&#34;&gt;Clustered Index&lt;/h3&gt;&#xA;&lt;p&gt;In InnoDB, each table has a clustered index that determines the physical order of data storage on disk.&lt;/p&gt;&#xA;&lt;ol&gt;&#xA;&lt;li&gt;If there is a primary key, it serves as the clustered index&lt;/li&gt;&#xA;&lt;li&gt;If there is no primary key, choose a unique non-null index as the clustered index&lt;/li&gt;&#xA;&lt;li&gt;If there still isn&amp;rsquo;t one, InnoDB implicitly creates an auto-increment column as the clustered index&lt;/li&gt;&#xA;&lt;/ol&gt;&#xA;&lt;h3 id=&#34;b-tree&#34;&gt;B+ Tree&lt;/h3&gt;&#xA;&lt;p&gt;By default, InnoDB uses B+ Tree storage for both clustered and secondary indexes.&lt;/p&gt;</description>
    </item>
    <item>
      <title>ThreadLocal &amp; ThreadPool</title>
      <link>https://ruokezhang.github.io/en/post/java/juc/threadlocal/</link>
      <pubDate>Thu, 27 Feb 2025 00:00:00 +0000</pubDate>
      <guid>https://ruokezhang.github.io/en/post/java/juc/threadlocal/</guid>
      <description>&lt;p&gt;Reference: JavaGuide&lt;/p&gt;&#xA;&lt;h2 id=&#34;threadlocal&#34;&gt;ThreadLocal&lt;/h2&gt;&#xA;&lt;p&gt;The &lt;strong&gt;&lt;code&gt;Thread&lt;/code&gt; class&lt;/strong&gt; has a variable &lt;code&gt;threadLocals&lt;/code&gt;, which can be considered a &lt;code&gt;HashMap&lt;/code&gt; used to store thread-private content.&lt;/p&gt;&#xA;&lt;div class=&#34;highlight&#34;&gt;&lt;div style=&#34;color:#4c4f69;background-color:#eff1f5;-moz-tab-size:2;-o-tab-size:2;tab-size:2;&#34;&gt;&#xA;&lt;table style=&#34;border-spacing:0;padding:0;margin:0;border:0;&#34;&gt;&lt;tr&gt;&lt;td style=&#34;vertical-align:top;padding:0;margin:0;border:0;&#34;&gt;&#xA;&lt;pre tabindex=&#34;0&#34; style=&#34;color:#4c4f69;background-color:#eff1f5;-moz-tab-size:2;-o-tab-size:2;tab-size:2;&#34;&gt;&lt;code&gt;&lt;span style=&#34;white-space:pre;-webkit-user-select:none;user-select:none;margin-right:0.4em;padding:0 0.4em 0 0.4em;color:#8c8fa1&#34;&gt;1&#xA;&lt;/span&gt;&lt;span style=&#34;white-space:pre;-webkit-user-select:none;user-select:none;margin-right:0.4em;padding:0 0.4em 0 0.4em;color:#8c8fa1&#34;&gt;2&#xA;&lt;/span&gt;&lt;span style=&#34;white-space:pre;-webkit-user-select:none;user-select:none;margin-right:0.4em;padding:0 0.4em 0 0.4em;color:#8c8fa1&#34;&gt;3&#xA;&lt;/span&gt;&lt;/code&gt;&lt;/pre&gt;&lt;/td&gt;&#xA;&lt;td style=&#34;vertical-align:top;padding:0;margin:0;border:0;;width:100%&#34;&gt;&#xA;&lt;pre tabindex=&#34;0&#34; style=&#34;color:#4c4f69;background-color:#eff1f5;-moz-tab-size:2;-o-tab-size:2;tab-size:2;&#34;&gt;&lt;code class=&#34;language-java&#34; data-lang=&#34;java&#34;&gt;&lt;span style=&#34;display:flex;&#34;&gt;&lt;span&gt;&lt;span style=&#34;color:#9ca0b0;font-style:italic&#34;&gt;/* ThreadLocal values pertaining to this thread. This map is maintained&#xA;&lt;/span&gt;&lt;/span&gt;&lt;/span&gt;&lt;span style=&#34;display:flex;&#34;&gt;&lt;span&gt;&lt;span style=&#34;color:#9ca0b0;font-style:italic&#34;&gt;    * by the ThreadLocal class. */&lt;/span&gt;&#xA;&lt;/span&gt;&lt;/span&gt;&lt;span style=&#34;display:flex;&#34;&gt;&lt;span&gt;ThreadLocal.&lt;span style=&#34;color:#1e66f5&#34;&gt;ThreadLocalMap&lt;/span&gt; threadLocals &lt;span style=&#34;color:#04a5e5;font-weight:bold&#34;&gt;=&lt;/span&gt; &lt;span style=&#34;color:#fe640b&#34;&gt;null&lt;/span&gt;;&#xA;&lt;/span&gt;&lt;/span&gt;&lt;/code&gt;&lt;/pre&gt;&lt;/td&gt;&lt;/tr&gt;&lt;/table&gt;&#xA;&lt;/div&gt;&#xA;&lt;/div&gt;&lt;p&gt;The &lt;code&gt;ThreadLocal&lt;/code&gt; class has an instance method &lt;code&gt;set&lt;/code&gt;, which actually stores the content in &lt;code&gt;threadLocals&lt;/code&gt;. The key is &lt;strong&gt;the &lt;code&gt;ThreadLocal&lt;/code&gt; object itself&lt;/strong&gt;.&lt;/p&gt;</description>
    </item>
    <item>
      <title>Skill Problems</title>
      <link>https://ruokezhang.github.io/en/post/leetcode/skill/</link>
      <pubDate>Wed, 26 Feb 2025 00:00:00 +0000</pubDate>
      <guid>https://ruokezhang.github.io/en/post/leetcode/skill/</guid>
      <description>&lt;h2 id=&#34;31-next-permutation&#34;&gt;31. Next Permutation&lt;/h2&gt;&#xA;&lt;p&gt;Consider the last permutation: 5-4-3-2-1, all in descending order.&lt;/p&gt;&#xA;&lt;ol&gt;&#xA;&lt;li&gt;From right to left, find the first ascending pair nums[i] and nums[i+1], e.g., 129&lt;strong&gt;47&lt;/strong&gt;653, found nums[4]=4.&lt;/li&gt;&#xA;&lt;li&gt;From right to left, find the first number nums[j] greater than nums[i], which is 5.&lt;/li&gt;&#xA;&lt;li&gt;Swap nums[i] and nums[j], resulting in 129&lt;strong&gt;5&lt;/strong&gt;76&lt;strong&gt;4&lt;/strong&gt;3. At this point, all numbers after nums[i] are in descending order.&lt;/li&gt;&#xA;&lt;li&gt;Sort the numbers after nums[i] in ascending order, resulting in 1295&lt;strong&gt;3467&lt;/strong&gt;.&lt;/li&gt;&#xA;&lt;/ol&gt;&#xA;&lt;h2 id=&#34;128-longest-consecutive-sequence&#34;&gt;128. Longest Consecutive Sequence&lt;/h2&gt;&#xA;&lt;p&gt;[100,4,200,1,3,2]&lt;/p&gt;</description>
    </item>
    <item>
      <title>Array</title>
      <link>https://ruokezhang.github.io/en/post/leetcode/array/</link>
      <pubDate>Sat, 22 Feb 2025 00:00:00 +0000</pubDate>
      <guid>https://ruokezhang.github.io/en/post/leetcode/array/</guid>
      <description>&lt;h3 id=&#34;lc-188-rotate-array&#34;&gt;LC 188 Rotate Array&lt;/h3&gt;&#xA;&lt;p&gt;Input: nums = [1,2,3,4,5,6,7], k = 3&#xA;Output: [5,6,7,1,2,3,4]&lt;/p&gt;&#xA;&lt;p&gt;Method 1: Slicing operation; take last k elements: nums[-k%n:]&lt;/p&gt;&#xA;&lt;p&gt;Method 2: Reverse entire array first, then reverse parts. Implement reversal separately without slicing to avoid extra space.&lt;/p&gt;&#xA;&lt;h2 id=&#34;two-pointers&#34;&gt;Two Pointers&lt;/h2&gt;&#xA;&lt;h3 id=&#34;opposite-direction-two-pointers&#34;&gt;Opposite Direction Two Pointers&lt;/h3&gt;&#xA;&lt;h4 id=&#34;lc-75-sort-colors&#34;&gt;LC 75: Sort Colors&lt;/h4&gt;&#xA;&lt;p&gt;Use pointer i to traverse array, left and right pointers point to &lt;strong&gt;next position to fill 0 or 2&lt;/strong&gt;.&#xA;First continuously fill 2s, then fill 0s when encountered.&#xA;Loop condition: i&amp;lt;=r. When i&amp;gt;r, nums[i] must be 2.&lt;/p&gt;</description>
    </item>
    <item>
      <title>JMM</title>
      <link>https://ruokezhang.github.io/en/post/java/juc/jmm/</link>
      <pubDate>Fri, 21 Feb 2025 00:00:00 +0000</pubDate>
      <guid>https://ruokezhang.github.io/en/post/java/juc/jmm/</guid>
      <description>&lt;p&gt;Reference: JavaGuide&lt;/p&gt;&#xA;&lt;h2 id=&#34;concurrency-issues&#34;&gt;Concurrency Issues&lt;/h2&gt;&#xA;&lt;h3 id=&#34;cpu-cache&#34;&gt;CPU Cache&lt;/h3&gt;&#xA;&lt;p&gt;&lt;img src=&#34;https://blog-ruoke.oss-cn-hongkong.aliyuncs.com/blog/images/CPUCache.png&#34; alt=&#34;Alt text&#34;&gt;&#xA;The value of a variable in the Cache may be inconsistent with the value in Main Memory, leading to calculation errors.&lt;/p&gt;&#xA;&lt;h3 id=&#34;instruction-level-reordering&#34;&gt;Instruction-Level Reordering&lt;/h3&gt;&#xA;&lt;h3 id=&#34;compiler-optimization-reordering&#34;&gt;Compiler Optimization Reordering&lt;/h3&gt;&#xA;&lt;p&gt;JVM and JIT do this. For Java programs, instruction reordering is performed during compilation without changing its semantics, similar to g1, g2 optimization reordering.&lt;/p&gt;&#xA;&lt;p&gt;Solution: Prohibit compiler reordering&lt;/p&gt;&#xA;&lt;h3 id=&#34;instruction-parallel-reordering&#34;&gt;Instruction Parallel Reordering&lt;/h3&gt;&#xA;&lt;p&gt;CPU does this, related to CPU pipeline. It means a thread can run in parallel on different CPU hardware.&lt;/p&gt;</description>
    </item>
    <item>
      <title>Sorting</title>
      <link>https://ruokezhang.github.io/en/post/leetcode/sort/</link>
      <pubDate>Fri, 21 Feb 2025 00:00:00 +0000</pubDate>
      <guid>https://ruokezhang.github.io/en/post/leetcode/sort/</guid>
      <description>&lt;h2 id=&#34;merge-sort&#34;&gt;Merge Sort&lt;/h2&gt;&#xA;&lt;h3 id=&#34;lc-148-sort-a-linked-list&#34;&gt;LC 148: Sort a Linked List&lt;/h3&gt;&#xA;&lt;p&gt;Use fast and slow pointers to divide into two halves, break in the middle, recursively sort each half, and finally merge the two sorted linked lists in ascending order. Boundary conditions: head==None or head.next==None.&lt;/p&gt;&#xA;&lt;h3 id=&#34;lc-23-merge-k-sorted-lists&#34;&gt;LC 23. Merge k Sorted Lists&lt;/h3&gt;&#xA;&lt;p&gt;Pay attention to edge cases.&lt;/p&gt;&#xA;&lt;h2 id=&#34;quick-sort&#34;&gt;Quick Sort&lt;/h2&gt;&#xA;&lt;p&gt;Using an element of the array (usually the first element) as the pivot, move all elements smaller than the pivot to its left, and all elements larger than the pivot to its right.&#xA;&lt;a href=&#34;https://leetcode.cn/problems/kth-largest-element-in-an-array/solutions/821137/ji-yu-kuai-pai-de-suo-you-topkwen-ti-jia-ylsd/&#34;&gt;Python Template&lt;/a&gt;&lt;/p&gt;</description>
    </item>
    <item>
      <title>Common Python Operations</title>
      <link>https://ruokezhang.github.io/en/post/leetcode/pythonskill/</link>
      <pubDate>Tue, 18 Feb 2025 00:00:00 +0000</pubDate>
      <guid>https://ruokezhang.github.io/en/post/leetcode/pythonskill/</guid>
      <description>&lt;p&gt;intervals.sort(key=lambda p: p[0])&lt;/p&gt;&#xA;&lt;p&gt;LC 189 [:] slicing operation&lt;/p&gt;&#xA;&lt;h2 id=&#34;dict&#34;&gt;dict&lt;/h2&gt;&#xA;&lt;div class=&#34;highlight&#34;&gt;&lt;div style=&#34;color:#4c4f69;background-color:#eff1f5;-moz-tab-size:2;-o-tab-size:2;tab-size:2;&#34;&gt;&#xA;&lt;table style=&#34;border-spacing:0;padding:0;margin:0;border:0;&#34;&gt;&lt;tr&gt;&lt;td style=&#34;vertical-align:top;padding:0;margin:0;border:0;&#34;&gt;&#xA;&lt;pre tabindex=&#34;0&#34; style=&#34;color:#4c4f69;background-color:#eff1f5;-moz-tab-size:2;-o-tab-size:2;tab-size:2;&#34;&gt;&lt;code&gt;&lt;span style=&#34;white-space:pre;-webkit-user-select:none;user-select:none;margin-right:0.4em;padding:0 0.4em 0 0.4em;color:#8c8fa1&#34;&gt; 1&#xA;&lt;/span&gt;&lt;span style=&#34;white-space:pre;-webkit-user-select:none;user-select:none;margin-right:0.4em;padding:0 0.4em 0 0.4em;color:#8c8fa1&#34;&gt; 2&#xA;&lt;/span&gt;&lt;span style=&#34;white-space:pre;-webkit-user-select:none;user-select:none;margin-right:0.4em;padding:0 0.4em 0 0.4em;color:#8c8fa1&#34;&gt; 3&#xA;&lt;/span&gt;&lt;span style=&#34;white-space:pre;-webkit-user-select:none;user-select:none;margin-right:0.4em;padding:0 0.4em 0 0.4em;color:#8c8fa1&#34;&gt; 4&#xA;&lt;/span&gt;&lt;span style=&#34;white-space:pre;-webkit-user-select:none;user-select:none;margin-right:0.4em;padding:0 0.4em 0 0.4em;color:#8c8fa1&#34;&gt; 5&#xA;&lt;/span&gt;&lt;span style=&#34;white-space:pre;-webkit-user-select:none;user-select:none;margin-right:0.4em;padding:0 0.4em 0 0.4em;color:#8c8fa1&#34;&gt; 6&#xA;&lt;/span&gt;&lt;span style=&#34;white-space:pre;-webkit-user-select:none;user-select:none;margin-right:0.4em;padding:0 0.4em 0 0.4em;color:#8c8fa1&#34;&gt; 7&#xA;&lt;/span&gt;&lt;span style=&#34;white-space:pre;-webkit-user-select:none;user-select:none;margin-right:0.4em;padding:0 0.4em 0 0.4em;color:#8c8fa1&#34;&gt; 8&#xA;&lt;/span&gt;&lt;span style=&#34;white-space:pre;-webkit-user-select:none;user-select:none;margin-right:0.4em;padding:0 0.4em 0 0.4em;color:#8c8fa1&#34;&gt; 9&#xA;&lt;/span&gt;&lt;span style=&#34;white-space:pre;-webkit-user-select:none;user-select:none;margin-right:0.4em;padding:0 0.4em 0 0.4em;color:#8c8fa1&#34;&gt;10&#xA;&lt;/span&gt;&lt;span style=&#34;white-space:pre;-webkit-user-select:none;user-select:none;margin-right:0.4em;padding:0 0.4em 0 0.4em;color:#8c8fa1&#34;&gt;11&#xA;&lt;/span&gt;&lt;/code&gt;&lt;/pre&gt;&lt;/td&gt;&#xA;&lt;td style=&#34;vertical-align:top;padding:0;margin:0;border:0;;width:100%&#34;&gt;&#xA;&lt;pre tabindex=&#34;0&#34; style=&#34;color:#4c4f69;background-color:#eff1f5;-moz-tab-size:2;-o-tab-size:2;tab-size:2;&#34;&gt;&lt;code class=&#34;language-python&#34; data-lang=&#34;python&#34;&gt;&lt;span style=&#34;display:flex;&#34;&gt;&lt;span&gt;&lt;span style=&#34;color:#9ca0b0;font-style:italic&#34;&gt;# Dictionary with initial key-value pairs&lt;/span&gt;&#xA;&lt;/span&gt;&lt;/span&gt;&lt;span style=&#34;display:flex;&#34;&gt;&lt;span&gt;filled_dict &lt;span style=&#34;color:#04a5e5;font-weight:bold&#34;&gt;=&lt;/span&gt; {&lt;span style=&#34;color:#40a02b&#34;&gt;&amp;#39;key1&amp;#39;&lt;/span&gt;: &lt;span style=&#34;color:#40a02b&#34;&gt;&amp;#39;value1&amp;#39;&lt;/span&gt;, &lt;span style=&#34;color:#40a02b&#34;&gt;&amp;#39;key2&amp;#39;&lt;/span&gt;: &lt;span style=&#34;color:#40a02b&#34;&gt;&amp;#39;value2&amp;#39;&lt;/span&gt;}&#xA;&lt;/span&gt;&lt;/span&gt;&lt;span style=&#34;display:flex;&#34;&gt;&lt;span&gt;&#xA;&lt;/span&gt;&lt;/span&gt;&lt;span style=&#34;display:flex;&#34;&gt;&lt;span&gt;&lt;span style=&#34;color:#9ca0b0;font-style:italic&#34;&gt;# Using dict() constructor&lt;/span&gt;&#xA;&lt;/span&gt;&lt;/span&gt;&lt;span style=&#34;display:flex;&#34;&gt;&lt;span&gt;constructed_dict &lt;span style=&#34;color:#04a5e5;font-weight:bold&#34;&gt;=&lt;/span&gt; &lt;span style=&#34;color:#04a5e5&#34;&gt;dict&lt;/span&gt;(key1&lt;span style=&#34;color:#04a5e5;font-weight:bold&#34;&gt;=&lt;/span&gt;&lt;span style=&#34;color:#40a02b&#34;&gt;&amp;#39;value1&amp;#39;&lt;/span&gt;, key2&lt;span style=&#34;color:#04a5e5;font-weight:bold&#34;&gt;=&lt;/span&gt;&lt;span style=&#34;color:#40a02b&#34;&gt;&amp;#39;value2&amp;#39;&lt;/span&gt;)&#xA;&lt;/span&gt;&lt;/span&gt;&lt;span style=&#34;display:flex;&#34;&gt;&lt;span&gt;&#xA;&lt;/span&gt;&lt;/span&gt;&lt;span style=&#34;display:flex;&#34;&gt;&lt;span&gt;valueList&lt;span style=&#34;color:#04a5e5;font-weight:bold&#34;&gt;=&lt;/span&gt;&lt;span style=&#34;color:#04a5e5&#34;&gt;list&lt;/span&gt;(filled_dict&lt;span style=&#34;color:#04a5e5;font-weight:bold&#34;&gt;.&lt;/span&gt;values())&#xA;&lt;/span&gt;&lt;/span&gt;&lt;span style=&#34;display:flex;&#34;&gt;&lt;span&gt;&#xA;&lt;/span&gt;&lt;/span&gt;&lt;span style=&#34;display:flex;&#34;&gt;&lt;span&gt;my_dict &lt;span style=&#34;color:#04a5e5;font-weight:bold&#34;&gt;=&lt;/span&gt; {&lt;span style=&#34;color:#40a02b&#34;&gt;&amp;#39;apple&amp;#39;&lt;/span&gt;: &lt;span style=&#34;color:#fe640b&#34;&gt;1&lt;/span&gt;, &lt;span style=&#34;color:#40a02b&#34;&gt;&amp;#39;banana&amp;#39;&lt;/span&gt;: &lt;span style=&#34;color:#fe640b&#34;&gt;2&lt;/span&gt;, &lt;span style=&#34;color:#40a02b&#34;&gt;&amp;#39;cherry&amp;#39;&lt;/span&gt;: &lt;span style=&#34;color:#fe640b&#34;&gt;3&lt;/span&gt;}&#xA;&lt;/span&gt;&lt;/span&gt;&lt;span style=&#34;display:flex;&#34;&gt;&lt;span&gt;&lt;span style=&#34;color:#8839ef&#34;&gt;for&lt;/span&gt; key &lt;span style=&#34;color:#04a5e5;font-weight:bold&#34;&gt;in&lt;/span&gt; my_dict&lt;span style=&#34;color:#04a5e5;font-weight:bold&#34;&gt;.&lt;/span&gt;keys():&#xA;&lt;/span&gt;&lt;/span&gt;&lt;span style=&#34;display:flex;&#34;&gt;&lt;span&gt;    &lt;span style=&#34;color:#04a5e5&#34;&gt;print&lt;/span&gt;(&lt;span style=&#34;color:#d20f39&#34;&gt;f&lt;/span&gt;&lt;span style=&#34;color:#40a02b&#34;&gt;&amp;#34;Key: &lt;/span&gt;&lt;span style=&#34;color:#40a02b&#34;&gt;{&lt;/span&gt;key&lt;span style=&#34;color:#40a02b&#34;&gt;}&lt;/span&gt;&lt;span style=&#34;color:#40a02b&#34;&gt;&amp;#34;&lt;/span&gt;)&#xA;&lt;/span&gt;&lt;/span&gt;&lt;/code&gt;&lt;/pre&gt;&lt;/td&gt;&lt;/tr&gt;&lt;/table&gt;&#xA;&lt;/div&gt;&#xA;&lt;/div&gt;&lt;p&gt;LC 49&lt;/p&gt;</description>
    </item>
    <item>
      <title>Java Threads</title>
      <link>https://ruokezhang.github.io/en/post/java/juc/thread/</link>
      <pubDate>Tue, 18 Feb 2025 00:00:00 +0000</pubDate>
      <guid>https://ruokezhang.github.io/en/post/java/juc/thread/</guid>
      <description>&lt;p&gt;Reference: JavaGuide&lt;/p&gt;&#xA;&lt;h2 id=&#34;threads&#34;&gt;Threads&lt;/h2&gt;&#xA;&lt;h3 id=&#34;thread-implementation&#34;&gt;Thread Implementation&lt;/h3&gt;&#xA;&lt;p&gt;A Java program runs as a process and is actually multi-threaded concurrently; the main function is the main thread. Each instance of java.lang.Thread that has called start() and not yet finished is a thread. Java threads are the concurrent execution units of Java programs.&lt;/p&gt;&#xA;&lt;h4 id=&#34;one-to-one-thread-model&#34;&gt;One-to-One Thread Model✨&lt;/h4&gt;&#xA;&lt;p&gt;Each Java thread corresponds to a kernel thread in the operating system, fully utilizing multi-core processors. (Now Windows and Linux use this.)&lt;/p&gt;</description>
    </item>
    <item>
      <title>Prefix Sum</title>
      <link>https://ruokezhang.github.io/en/post/leetcode/presum/</link>
      <pubDate>Tue, 18 Feb 2025 00:00:00 +0000</pubDate>
      <guid>https://ruokezhang.github.io/en/post/leetcode/presum/</guid>
      <description>&lt;p&gt;&lt;a href=&#34;https://leetcode.cn/discuss/post/3583665/fen-xiang-gun-ti-dan-chang-yong-shu-ju-j-bvmv/&#34;&gt;Prefix Sum Problem List&lt;/a&gt;&lt;/p&gt;&#xA;&lt;h2 id=&#34;one-dimensional-prefix-sum&#34;&gt;One-dimensional Prefix Sum&lt;/h2&gt;&#xA;&lt;h3 id=&#34;lc-1749&#34;&gt;LC 1749&lt;/h3&gt;&#xA;&lt;p&gt;Maximum absolute sum of any subarray: Find the minimum and maximum values in the prefix sum array, and the absolute difference between them is the answer.&lt;/p&gt;&#xA;&lt;div class=&#34;highlight&#34;&gt;&lt;div style=&#34;color:#4c4f69;background-color:#eff1f5;-moz-tab-size:2;-o-tab-size:2;tab-size:2;&#34;&gt;&#xA;&lt;table style=&#34;border-spacing:0;padding:0;margin:0;border:0;&#34;&gt;&lt;tr&gt;&lt;td style=&#34;vertical-align:top;padding:0;margin:0;border:0;&#34;&gt;&#xA;&lt;pre tabindex=&#34;0&#34; style=&#34;color:#4c4f69;background-color:#eff1f5;-moz-tab-size:2;-o-tab-size:2;tab-size:2;&#34;&gt;&lt;code&gt;&lt;span style=&#34;white-space:pre;-webkit-user-select:none;user-select:none;margin-right:0.4em;padding:0 0.4em 0 0.4em;color:#8c8fa1&#34;&gt;1&#xA;&lt;/span&gt;&lt;span style=&#34;white-space:pre;-webkit-user-select:none;user-select:none;margin-right:0.4em;padding:0 0.4em 0 0.4em;color:#8c8fa1&#34;&gt;2&#xA;&lt;/span&gt;&lt;span style=&#34;white-space:pre;-webkit-user-select:none;user-select:none;margin-right:0.4em;padding:0 0.4em 0 0.4em;color:#8c8fa1&#34;&gt;3&#xA;&lt;/span&gt;&lt;/code&gt;&lt;/pre&gt;&lt;/td&gt;&#xA;&lt;td style=&#34;vertical-align:top;padding:0;margin:0;border:0;;width:100%&#34;&gt;&#xA;&lt;pre tabindex=&#34;0&#34; style=&#34;color:#4c4f69;background-color:#eff1f5;-moz-tab-size:2;-o-tab-size:2;tab-size:2;&#34;&gt;&lt;code class=&#34;language-python&#34; data-lang=&#34;python&#34;&gt;&lt;span style=&#34;display:flex;&#34;&gt;&lt;span&gt;&lt;span style=&#34;color:#8839ef&#34;&gt;def&lt;/span&gt; &lt;span style=&#34;color:#1e66f5&#34;&gt;maxAbsoluteSum&lt;/span&gt;(&lt;span style=&#34;color:#04a5e5&#34;&gt;self&lt;/span&gt;, nums: List[&lt;span style=&#34;color:#04a5e5&#34;&gt;int&lt;/span&gt;]) &lt;span style=&#34;color:#04a5e5;font-weight:bold&#34;&gt;-&amp;gt;&lt;/span&gt; &lt;span style=&#34;color:#04a5e5&#34;&gt;int&lt;/span&gt;:&#xA;&lt;/span&gt;&lt;/span&gt;&lt;span style=&#34;display:flex;&#34;&gt;&lt;span&gt;    s &lt;span style=&#34;color:#04a5e5;font-weight:bold&#34;&gt;=&lt;/span&gt; &lt;span style=&#34;color:#04a5e5&#34;&gt;list&lt;/span&gt;(accumulate(nums, initial&lt;span style=&#34;color:#04a5e5;font-weight:bold&#34;&gt;=&lt;/span&gt;&lt;span style=&#34;color:#fe640b&#34;&gt;0&lt;/span&gt;))  &lt;span style=&#34;color:#9ca0b0;font-style:italic&#34;&gt;# prefix sum of nums&lt;/span&gt;&#xA;&lt;/span&gt;&lt;/span&gt;&lt;span style=&#34;display:flex;&#34;&gt;&lt;span&gt;    &lt;span style=&#34;color:#8839ef&#34;&gt;return&lt;/span&gt; &lt;span style=&#34;color:#04a5e5&#34;&gt;max&lt;/span&gt;(s) &lt;span style=&#34;color:#04a5e5;font-weight:bold&#34;&gt;-&lt;/span&gt; &lt;span style=&#34;color:#04a5e5&#34;&gt;min&lt;/span&gt;(s)&#xA;&lt;/span&gt;&lt;/span&gt;&lt;/code&gt;&lt;/pre&gt;&lt;/td&gt;&lt;/tr&gt;&lt;/table&gt;&#xA;&lt;/div&gt;&#xA;&lt;/div&gt;&lt;h3 id=&#34;2055-plates-between-candles&#34;&gt;2055. Plates Between Candles&lt;/h3&gt;&#xA;&lt;ol&gt;&#xA;&lt;li&gt;Find the first candle at or to the right of a&lt;/li&gt;&#xA;&lt;li&gt;Find the first candle at or to the left of b&lt;/li&gt;&#xA;&lt;li&gt;Use prefix sum to count the number of plates between them&lt;/li&gt;&#xA;&lt;/ol&gt;&#xA;&lt;p&gt;Steps 1 and 2 can use binary search, but it will time out.&#xA;It&amp;rsquo;s best to pre-process and record the position of the first candle to the left/right of each position.&lt;/p&gt;</description>
    </item>
    <item>
      <title>Sliding Window</title>
      <link>https://ruokezhang.github.io/en/post/leetcode/slidingwindow/</link>
      <pubDate>Tue, 18 Feb 2025 00:00:00 +0000</pubDate>
      <guid>https://ruokezhang.github.io/en/post/leetcode/slidingwindow/</guid>
      <description>&lt;p&gt;reference: Lingchashan Aifu&lt;/p&gt;&#xA;&lt;h2 id=&#34;fixed-size-sliding-window&#34;&gt;Fixed-size Sliding Window&lt;/h2&gt;&#xA;&lt;p&gt;Entry: The element at index i enters the window, update relevant statistics. If i&amp;lt;k-1, repeat the first step.&lt;/p&gt;&#xA;&lt;p&gt;Update: Update the answer. Generally, update the maximum/minimum value.&lt;/p&gt;&#xA;&lt;p&gt;Exit: The element at index i-k+1 leaves the window, update relevant statistics.&lt;/p&gt;&#xA;&lt;p&gt;LC 1456&#xA;LC 1052 Grumpy Bookstore Owner: Answer = number of customers during all non-grumpy times + number of grumpy customers within the window.&lt;/p&gt;&#xA;&lt;h4 id=&#34;1297-maximum-number-of-occurrences-of-a-substring-&#34;&gt;1297. Maximum Number of Occurrences of a Substring ✨&lt;/h4&gt;&#xA;&lt;p&gt;High-frequency problem, greedy approach.&lt;/p&gt;</description>
    </item>
    <item>
      <title>Garbage Collection</title>
      <link>https://ruokezhang.github.io/en/post/java/jvm/gc/</link>
      <pubDate>Mon, 17 Feb 2025 00:00:00 +0000</pubDate>
      <guid>https://ruokezhang.github.io/en/post/java/jvm/gc/</guid>
      <description>&lt;p&gt;References: &lt;a href=&#34;https://github.com/RongleXie/java-books-collections/blob/master/%E6%B7%B1%E5%85%A5%E7%90%86%E8%A7%A3Java%E8%99%9A%E6%8B%9F%E6%9C%BA%EF%BC%9AJVM%E9%AB%98%E7%BA%A7%E7%89%B9%E6%80%A7%E4%B8%8E%E6%9C%80%E4%BD%B3%E5%AE%9E%E8%B7%B5%EF%BC%88%E7%AC%AC3%E7%89%88%EF%BC%89%E5%91%A8%E5%BF%97%E6%98%8E.pdf&#34;&gt;Understanding the JVM (3rd Edition, Chinese)&lt;/a&gt;, &lt;a href=&#34;%E6%9E%81%E8%87%B4%E5%85%AB%E8%82%A1%E6%96%87%E4%B9%8BJVM%E5%9E%83%E5%9C%BE%E5%9B%9E%E6%94%B6%E5%99%A8G1&amp;amp;ZGC%E8%AF%A6%E8%A7%A3&#34;&gt;G1 &amp;amp; ZGC deep dive (Chinese)&lt;/a&gt;&lt;/p&gt;&#xA;&lt;h2 id=&#34;is-an-object-dead&#34;&gt;Is an Object Dead?&lt;/h2&gt;&#xA;&lt;h3 id=&#34;reference-counting&#34;&gt;Reference Counting&lt;/h3&gt;&#xA;&lt;p&gt;Drawback: they reference each other, so neither count goes to 0; they won’t be collected.&lt;/p&gt;&#xA;&lt;h3 id=&#34;reachability-analysis&#34;&gt;Reachability Analysis&lt;/h3&gt;&#xA;&lt;p&gt;Start from GC Roots and traverse references downward, marking all reachable objects. The traversal paths are “reference chains.”&lt;/p&gt;&#xA;&lt;p&gt;GC Roots include:&lt;/p&gt;&#xA;&lt;ol&gt;&#xA;&lt;li&gt;Objects referenced from local variable tables in JVM stack frames (method params, temps, and the this of instance methods)&lt;/li&gt;&#xA;&lt;li&gt;Class static variables (in the method area)&lt;/li&gt;&#xA;&lt;li&gt;Constants referenced from the method area&lt;/li&gt;&#xA;&lt;li&gt;Native references from the native method stack&lt;/li&gt;&#xA;&lt;li&gt;All objects held by synchronized&lt;/li&gt;&#xA;&lt;li&gt;JVM-internal refs: Class objects for primitives, permanent exception objects, system class loader&lt;/li&gt;&#xA;&lt;/ol&gt;&#xA;&lt;p&gt;Even if first marked “unreachable,” an object isn’t necessarily collected immediately.&lt;/p&gt;</description>
    </item>
    <item>
      <title>Binary Tree Patterns</title>
      <link>https://ruokezhang.github.io/en/post/leetcode/binarytree/binarytree/</link>
      <pubDate>Wed, 12 Feb 2025 00:00:00 +0000</pubDate>
      <guid>https://ruokezhang.github.io/en/post/leetcode/binarytree/binarytree/</guid>
      <description>&lt;p&gt;&lt;a href=&#34;https://leetcode.cn/circle/discuss/K0n2gO/&#34;&gt;Problem list&lt;/a&gt;&lt;/p&gt;&#xA;&lt;h2 id=&#34;bottom-up-dfs-postorder-traversal&#34;&gt;Bottom-Up DFS: Postorder Traversal&lt;/h2&gt;&#xA;&lt;p&gt;Use postorder when the computation at a node needs results from its children.&lt;/p&gt;&#xA;&lt;ul&gt;&#xA;&lt;li&gt;&lt;strong&gt;1110, Delete Nodes and Return Forest:&lt;/strong&gt; Process children before deciding which remaining subtrees become new roots.&lt;/li&gt;&#xA;&lt;li&gt;&lt;strong&gt;1123, Lowest Common Ancestor of Deepest Leaves:&lt;/strong&gt; Return both the deepest depth beneath a node and the common ancestor of leaves at that depth.&lt;/li&gt;&#xA;&lt;li&gt;&lt;strong&gt;1530, Number of Good Leaf Nodes Pairs:&lt;/strong&gt; Return the distances from a node to leaves in its subtree. Combine distances from opposite children to count valid pairs.&lt;/li&gt;&#xA;&lt;/ul&gt;&#xA;&lt;h2 id=&#34;preorder-traversal&#34;&gt;Preorder Traversal&lt;/h2&gt;&#xA;&lt;p&gt;&lt;strong&gt;1026, Maximum Difference Between Node and Ancestor:&lt;/strong&gt; Carry the smallest and largest ancestor values down the path. A postorder solution is also possible.&lt;/p&gt;</description>
    </item>
    <item>
      <title>Dynamic Programming</title>
      <link>https://ruokezhang.github.io/en/post/leetcode/dp/</link>
      <pubDate>Wed, 12 Feb 2025 00:00:00 +0000</pubDate>
      <guid>https://ruokezhang.github.io/en/post/leetcode/dp/</guid>
      <description>&lt;p&gt;&lt;a href=&#34;https://leetcode.cn/circle/discuss/tXLS3i/&#34;&gt;Ling Shen Problem List&lt;/a&gt;&lt;/p&gt;&#xA;&lt;h2 id=&#34;linear-dp&#34;&gt;Linear DP&lt;/h2&gt;&#xA;&lt;p&gt;&lt;img src=&#34;./dfs_dp.png&#34; alt=&#34;Alt text&#34;&gt;&lt;/p&gt;&#xA;&lt;h4 id=&#34;10-regular-expression-matching&#34;&gt;10. Regular Expression Matching&lt;/h4&gt;&#xA;&lt;p&gt;dp[i][j] indicates if s(0,i-1) matches p(0,j-1)&lt;/p&gt;&#xA;&lt;p&gt;Base case: s empty, p empty → True; s empty, p x&lt;em&gt;x&lt;/em&gt; type → True&#xA;Compare s[i], p[j]: if not match and p[j] is *, and s[i] matches p[j-1], three possibilities: match one letter, zero letters, multiple letters.&#xA;If not match and p[j] is *, and s[i] doesn&amp;rsquo;t match p[j-1], check zero letter option.&lt;/p&gt;</description>
    </item>
    <item>
      <title>Linked List</title>
      <link>https://ruokezhang.github.io/en/post/leetcode/linkedlist/</link>
      <pubDate>Sun, 09 Feb 2025 00:00:00 +0000</pubDate>
      <guid>https://ruokezhang.github.io/en/post/leetcode/linkedlist/</guid>
      <description>&lt;h2 id=&#34;reverse-linked-list&#34;&gt;Reverse Linked List&lt;/h2&gt;&#xA;&lt;div class=&#34;highlight&#34;&gt;&lt;div style=&#34;color:#4c4f69;background-color:#eff1f5;-moz-tab-size:2;-o-tab-size:2;tab-size:2;&#34;&gt;&#xA;&lt;table style=&#34;border-spacing:0;padding:0;margin:0;border:0;&#34;&gt;&lt;tr&gt;&lt;td style=&#34;vertical-align:top;padding:0;margin:0;border:0;&#34;&gt;&#xA;&lt;pre tabindex=&#34;0&#34; style=&#34;color:#4c4f69;background-color:#eff1f5;-moz-tab-size:2;-o-tab-size:2;tab-size:2;&#34;&gt;&lt;code&gt;&lt;span style=&#34;white-space:pre;-webkit-user-select:none;user-select:none;margin-right:0.4em;padding:0 0.4em 0 0.4em;color:#8c8fa1&#34;&gt; 1&#xA;&lt;/span&gt;&lt;span style=&#34;white-space:pre;-webkit-user-select:none;user-select:none;margin-right:0.4em;padding:0 0.4em 0 0.4em;color:#8c8fa1&#34;&gt; 2&#xA;&lt;/span&gt;&lt;span style=&#34;white-space:pre;-webkit-user-select:none;user-select:none;margin-right:0.4em;padding:0 0.4em 0 0.4em;color:#8c8fa1&#34;&gt; 3&#xA;&lt;/span&gt;&lt;span style=&#34;white-space:pre;-webkit-user-select:none;user-select:none;margin-right:0.4em;padding:0 0.4em 0 0.4em;color:#8c8fa1&#34;&gt; 4&#xA;&lt;/span&gt;&lt;span style=&#34;white-space:pre;-webkit-user-select:none;user-select:none;margin-right:0.4em;padding:0 0.4em 0 0.4em;color:#8c8fa1&#34;&gt; 5&#xA;&lt;/span&gt;&lt;span style=&#34;white-space:pre;-webkit-user-select:none;user-select:none;margin-right:0.4em;padding:0 0.4em 0 0.4em;color:#8c8fa1&#34;&gt; 6&#xA;&lt;/span&gt;&lt;span style=&#34;white-space:pre;-webkit-user-select:none;user-select:none;margin-right:0.4em;padding:0 0.4em 0 0.4em;color:#8c8fa1&#34;&gt; 7&#xA;&lt;/span&gt;&lt;span style=&#34;white-space:pre;-webkit-user-select:none;user-select:none;margin-right:0.4em;padding:0 0.4em 0 0.4em;color:#8c8fa1&#34;&gt; 8&#xA;&lt;/span&gt;&lt;span style=&#34;white-space:pre;-webkit-user-select:none;user-select:none;margin-right:0.4em;padding:0 0.4em 0 0.4em;color:#8c8fa1&#34;&gt; 9&#xA;&lt;/span&gt;&lt;span style=&#34;white-space:pre;-webkit-user-select:none;user-select:none;margin-right:0.4em;padding:0 0.4em 0 0.4em;color:#8c8fa1&#34;&gt;10&#xA;&lt;/span&gt;&lt;span style=&#34;white-space:pre;-webkit-user-select:none;user-select:none;margin-right:0.4em;padding:0 0.4em 0 0.4em;color:#8c8fa1&#34;&gt;11&#xA;&lt;/span&gt;&lt;span style=&#34;white-space:pre;-webkit-user-select:none;user-select:none;margin-right:0.4em;padding:0 0.4em 0 0.4em;color:#8c8fa1&#34;&gt;12&#xA;&lt;/span&gt;&lt;span style=&#34;white-space:pre;-webkit-user-select:none;user-select:none;margin-right:0.4em;padding:0 0.4em 0 0.4em;color:#8c8fa1&#34;&gt;13&#xA;&lt;/span&gt;&lt;span style=&#34;white-space:pre;-webkit-user-select:none;user-select:none;margin-right:0.4em;padding:0 0.4em 0 0.4em;color:#8c8fa1&#34;&gt;14&#xA;&lt;/span&gt;&lt;span style=&#34;white-space:pre;-webkit-user-select:none;user-select:none;margin-right:0.4em;padding:0 0.4em 0 0.4em;color:#8c8fa1&#34;&gt;15&#xA;&lt;/span&gt;&lt;span style=&#34;white-space:pre;-webkit-user-select:none;user-select:none;margin-right:0.4em;padding:0 0.4em 0 0.4em;color:#8c8fa1&#34;&gt;16&#xA;&lt;/span&gt;&lt;span style=&#34;white-space:pre;-webkit-user-select:none;user-select:none;margin-right:0.4em;padding:0 0.4em 0 0.4em;color:#8c8fa1&#34;&gt;17&#xA;&lt;/span&gt;&lt;span style=&#34;white-space:pre;-webkit-user-select:none;user-select:none;margin-right:0.4em;padding:0 0.4em 0 0.4em;color:#8c8fa1&#34;&gt;18&#xA;&lt;/span&gt;&lt;span style=&#34;white-space:pre;-webkit-user-select:none;user-select:none;margin-right:0.4em;padding:0 0.4em 0 0.4em;color:#8c8fa1&#34;&gt;19&#xA;&lt;/span&gt;&lt;span style=&#34;white-space:pre;-webkit-user-select:none;user-select:none;margin-right:0.4em;padding:0 0.4em 0 0.4em;color:#8c8fa1&#34;&gt;20&#xA;&lt;/span&gt;&lt;span style=&#34;white-space:pre;-webkit-user-select:none;user-select:none;margin-right:0.4em;padding:0 0.4em 0 0.4em;color:#8c8fa1&#34;&gt;21&#xA;&lt;/span&gt;&lt;span style=&#34;white-space:pre;-webkit-user-select:none;user-select:none;margin-right:0.4em;padding:0 0.4em 0 0.4em;color:#8c8fa1&#34;&gt;22&#xA;&lt;/span&gt;&lt;/code&gt;&lt;/pre&gt;&lt;/td&gt;&#xA;&lt;td style=&#34;vertical-align:top;padding:0;margin:0;border:0;;width:100%&#34;&gt;&#xA;&lt;pre tabindex=&#34;0&#34; style=&#34;color:#4c4f69;background-color:#eff1f5;-moz-tab-size:2;-o-tab-size:2;tab-size:2;&#34;&gt;&lt;code class=&#34;language-python&#34; data-lang=&#34;python&#34;&gt;&lt;span style=&#34;display:flex;&#34;&gt;&lt;span&gt;&lt;span style=&#34;color:#8839ef&#34;&gt;def&lt;/span&gt; &lt;span style=&#34;color:#1e66f5&#34;&gt;reverseBetween&lt;/span&gt;(&lt;span style=&#34;color:#04a5e5&#34;&gt;self&lt;/span&gt;, head: Optional[ListNode], left: &lt;span style=&#34;color:#04a5e5&#34;&gt;int&lt;/span&gt;, right: &lt;span style=&#34;color:#04a5e5&#34;&gt;int&lt;/span&gt;) &lt;span style=&#34;color:#04a5e5;font-weight:bold&#34;&gt;-&amp;gt;&lt;/span&gt; Optional[ListNode]:&#xA;&lt;/span&gt;&lt;/span&gt;&lt;span style=&#34;display:flex;&#34;&gt;&lt;span&gt;    &lt;span style=&#34;color:#9ca0b0;font-style:italic&#34;&gt;#Answer head might change, so use dummy&lt;/span&gt;&#xA;&lt;/span&gt;&lt;/span&gt;&lt;span style=&#34;display:flex;&#34;&gt;&lt;span&gt;    dummy&lt;span style=&#34;color:#04a5e5;font-weight:bold&#34;&gt;=&lt;/span&gt;ListNode(&lt;span style=&#34;color:#04a5e5&#34;&gt;next&lt;/span&gt;&lt;span style=&#34;color:#04a5e5;font-weight:bold&#34;&gt;=&lt;/span&gt;head)&#xA;&lt;/span&gt;&lt;/span&gt;&lt;span style=&#34;display:flex;&#34;&gt;&lt;span&gt;    pre&lt;span style=&#34;color:#04a5e5;font-weight:bold&#34;&gt;=&lt;/span&gt;dummy&#xA;&lt;/span&gt;&lt;/span&gt;&lt;span style=&#34;display:flex;&#34;&gt;&lt;span&gt;    &lt;span style=&#34;color:#9ca0b0;font-style:italic&#34;&gt;#Move pre, cur to positions 1 and 2&lt;/span&gt;&#xA;&lt;/span&gt;&lt;/span&gt;&lt;span style=&#34;display:flex;&#34;&gt;&lt;span&gt;    &lt;span style=&#34;color:#8839ef&#34;&gt;for&lt;/span&gt; _ &lt;span style=&#34;color:#04a5e5;font-weight:bold&#34;&gt;in&lt;/span&gt; &lt;span style=&#34;color:#04a5e5&#34;&gt;range&lt;/span&gt;(left&lt;span style=&#34;color:#04a5e5;font-weight:bold&#34;&gt;-&lt;/span&gt;&lt;span style=&#34;color:#fe640b&#34;&gt;1&lt;/span&gt;):&#xA;&lt;/span&gt;&lt;/span&gt;&lt;span style=&#34;display:flex;&#34;&gt;&lt;span&gt;        pre&lt;span style=&#34;color:#04a5e5;font-weight:bold&#34;&gt;=&lt;/span&gt;pre&lt;span style=&#34;color:#04a5e5;font-weight:bold&#34;&gt;.&lt;/span&gt;next&#xA;&lt;/span&gt;&lt;/span&gt;&lt;span style=&#34;display:flex;&#34;&gt;&lt;span&gt;    cur&lt;span style=&#34;color:#04a5e5;font-weight:bold&#34;&gt;=&lt;/span&gt;pre&lt;span style=&#34;color:#04a5e5;font-weight:bold&#34;&gt;.&lt;/span&gt;next&#xA;&lt;/span&gt;&lt;/span&gt;&lt;span style=&#34;display:flex;&#34;&gt;&lt;span&gt;    &lt;span style=&#34;color:#9ca0b0;font-style:italic&#34;&gt;#Record current pre&lt;/span&gt;&#xA;&lt;/span&gt;&lt;/span&gt;&lt;span style=&#34;display:flex;&#34;&gt;&lt;span&gt;    p0&lt;span style=&#34;color:#04a5e5;font-weight:bold&#34;&gt;=&lt;/span&gt;pre&#xA;&lt;/span&gt;&lt;/span&gt;&lt;span style=&#34;display:flex;&#34;&gt;&lt;span&gt;    &lt;span style=&#34;color:#9ca0b0;font-style:italic&#34;&gt;#Reverse from 2 to 4, essentially changing next pointers&lt;/span&gt;&#xA;&lt;/span&gt;&lt;/span&gt;&lt;span style=&#34;display:flex;&#34;&gt;&lt;span&gt;    &lt;span style=&#34;color:#8839ef&#34;&gt;for&lt;/span&gt; _ &lt;span style=&#34;color:#04a5e5;font-weight:bold&#34;&gt;in&lt;/span&gt; &lt;span style=&#34;color:#04a5e5&#34;&gt;range&lt;/span&gt;(right&lt;span style=&#34;color:#04a5e5;font-weight:bold&#34;&gt;-&lt;/span&gt;left&lt;span style=&#34;color:#04a5e5;font-weight:bold&#34;&gt;+&lt;/span&gt;&lt;span style=&#34;color:#fe640b&#34;&gt;1&lt;/span&gt;):&#xA;&lt;/span&gt;&lt;/span&gt;&lt;span style=&#34;display:flex;&#34;&gt;&lt;span&gt;        nxt&lt;span style=&#34;color:#04a5e5;font-weight:bold&#34;&gt;=&lt;/span&gt;cur&lt;span style=&#34;color:#04a5e5;font-weight:bold&#34;&gt;.&lt;/span&gt;next&#xA;&lt;/span&gt;&lt;/span&gt;&lt;span style=&#34;display:flex;&#34;&gt;&lt;span&gt;        cur&lt;span style=&#34;color:#04a5e5;font-weight:bold&#34;&gt;.&lt;/span&gt;next&lt;span style=&#34;color:#04a5e5;font-weight:bold&#34;&gt;=&lt;/span&gt;pre&#xA;&lt;/span&gt;&lt;/span&gt;&lt;span style=&#34;display:flex;&#34;&gt;&lt;span&gt;        pre&lt;span style=&#34;color:#04a5e5;font-weight:bold&#34;&gt;=&lt;/span&gt;cur&#xA;&lt;/span&gt;&lt;/span&gt;&lt;span style=&#34;display:flex;&#34;&gt;&lt;span&gt;        cur&lt;span style=&#34;color:#04a5e5;font-weight:bold&#34;&gt;=&lt;/span&gt;nxt&#xA;&lt;/span&gt;&lt;/span&gt;&lt;span style=&#34;display:flex;&#34;&gt;&lt;span&gt;    &lt;span style=&#34;color:#9ca0b0;font-style:italic&#34;&gt;#New pre,cur are 4,5&lt;/span&gt;&#xA;&lt;/span&gt;&lt;/span&gt;&lt;span style=&#34;display:flex;&#34;&gt;&lt;span&gt;    &lt;span style=&#34;color:#9ca0b0;font-style:italic&#34;&gt;#Connect 2 and 5&lt;/span&gt;&#xA;&lt;/span&gt;&lt;/span&gt;&lt;span style=&#34;display:flex;&#34;&gt;&lt;span&gt;    p0&lt;span style=&#34;color:#04a5e5;font-weight:bold&#34;&gt;.&lt;/span&gt;next&lt;span style=&#34;color:#04a5e5;font-weight:bold&#34;&gt;.&lt;/span&gt;next&lt;span style=&#34;color:#04a5e5;font-weight:bold&#34;&gt;=&lt;/span&gt;cur&#xA;&lt;/span&gt;&lt;/span&gt;&lt;span style=&#34;display:flex;&#34;&gt;&lt;span&gt;    &lt;span style=&#34;color:#9ca0b0;font-style:italic&#34;&gt;#Connect 1 and 4&lt;/span&gt;&#xA;&lt;/span&gt;&lt;/span&gt;&lt;span style=&#34;display:flex;&#34;&gt;&lt;span&gt;    p0&lt;span style=&#34;color:#04a5e5;font-weight:bold&#34;&gt;.&lt;/span&gt;next&lt;span style=&#34;color:#04a5e5;font-weight:bold&#34;&gt;=&lt;/span&gt;pre&#xA;&lt;/span&gt;&lt;/span&gt;&lt;span style=&#34;display:flex;&#34;&gt;&lt;span&gt;    &lt;span style=&#34;color:#8839ef&#34;&gt;return&lt;/span&gt; dummy&lt;span style=&#34;color:#04a5e5;font-weight:bold&#34;&gt;.&lt;/span&gt;next&#xA;&lt;/span&gt;&lt;/span&gt;&lt;/code&gt;&lt;/pre&gt;&lt;/td&gt;&lt;/tr&gt;&lt;/table&gt;&#xA;&lt;/div&gt;&#xA;&lt;/div&gt;&lt;p&gt;Reverse linked list focuses on pre and cur positions before start and after end. In this case, old pre.next becomes new pre, old cur.next becomes new cur.&#xA;&lt;img src=&#34;https://blog-ruoke.oss-cn-hongkong.aliyuncs.com/static/reverse.png&#34; alt=&#34;Alt text&#34;&gt;&lt;/p&gt;</description>
    </item>
    <item>
      <title>Influencer Exploration</title>
      <link>https://ruokezhang.github.io/en/post/blackhorserating/post/</link>
      <pubDate>Fri, 07 Feb 2025 00:00:00 +0000</pubDate>
      <guid>https://ruokezhang.github.io/en/post/blackhorserating/post/</guid>
      <description>&lt;h2 id=&#34;like-design&#34;&gt;Like Design&lt;/h2&gt;&#xA;&lt;p&gt;Use Redis sorted set: key is post ID, set stores user IDs who liked, score is timestamp of like.&lt;/p&gt;&#xA;&lt;p&gt;When frontend views post details, backend needs to:&lt;/p&gt;&#xA;&lt;ol&gt;&#xA;&lt;li&gt;Fetch content from database by post ID&lt;/li&gt;&#xA;&lt;li&gt;Check Redis to determine if current user liked this post&lt;/li&gt;&#xA;&lt;li&gt;Add liked field to Blog object and return to frontend&lt;/li&gt;&#xA;&lt;/ol&gt;&#xA;&lt;div class=&#34;highlight&#34;&gt;&lt;div style=&#34;color:#4c4f69;background-color:#eff1f5;-moz-tab-size:2;-o-tab-size:2;tab-size:2;&#34;&gt;&#xA;&lt;table style=&#34;border-spacing:0;padding:0;margin:0;border:0;&#34;&gt;&lt;tr&gt;&lt;td style=&#34;vertical-align:top;padding:0;margin:0;border:0;&#34;&gt;&#xA;&lt;pre tabindex=&#34;0&#34; style=&#34;color:#4c4f69;background-color:#eff1f5;-moz-tab-size:2;-o-tab-size:2;tab-size:2;&#34;&gt;&lt;code&gt;&lt;span style=&#34;white-space:pre;-webkit-user-select:none;user-select:none;margin-right:0.4em;padding:0 0.4em 0 0.4em;color:#8c8fa1&#34;&gt;1&#xA;&lt;/span&gt;&lt;span style=&#34;white-space:pre;-webkit-user-select:none;user-select:none;margin-right:0.4em;padding:0 0.4em 0 0.4em;color:#8c8fa1&#34;&gt;2&#xA;&lt;/span&gt;&lt;span style=&#34;white-space:pre;-webkit-user-select:none;user-select:none;margin-right:0.4em;padding:0 0.4em 0 0.4em;color:#8c8fa1&#34;&gt;3&#xA;&lt;/span&gt;&lt;span style=&#34;white-space:pre;-webkit-user-select:none;user-select:none;margin-right:0.4em;padding:0 0.4em 0 0.4em;color:#8c8fa1&#34;&gt;4&#xA;&lt;/span&gt;&lt;/code&gt;&lt;/pre&gt;&lt;/td&gt;&#xA;&lt;td style=&#34;vertical-align:top;padding:0;margin:0;border:0;;width:100%&#34;&gt;&#xA;&lt;pre tabindex=&#34;0&#34; style=&#34;color:#4c4f69;background-color:#eff1f5;-moz-tab-size:2;-o-tab-size:2;tab-size:2;&#34;&gt;&lt;code class=&#34;language-java&#34; data-lang=&#34;java&#34;&gt;&lt;span style=&#34;display:flex;&#34;&gt;&lt;span&gt;&lt;span style=&#34;color:#1e66f5;font-weight:bold&#34;&gt;@PutMapping&lt;/span&gt;(&lt;span style=&#34;color:#40a02b&#34;&gt;&amp;#34;/like/{id}&amp;#34;&lt;/span&gt;)&#xA;&lt;/span&gt;&lt;/span&gt;&lt;span style=&#34;display:flex;&#34;&gt;&lt;span&gt;&lt;span style=&#34;color:#d20f39&#34;&gt;public&lt;/span&gt; Result &lt;span style=&#34;color:#1e66f5&#34;&gt;likeBlog&lt;/span&gt;(&lt;span style=&#34;color:#1e66f5;font-weight:bold&#34;&gt;@PathVariable&lt;/span&gt;(&lt;span style=&#34;color:#40a02b&#34;&gt;&amp;#34;id&amp;#34;&lt;/span&gt;) Long id) {&#xA;&lt;/span&gt;&lt;/span&gt;&lt;span style=&#34;display:flex;&#34;&gt;&lt;span&gt;    &lt;span style=&#34;color:#8839ef&#34;&gt;return&lt;/span&gt; blogService.&lt;span style=&#34;color:#1e66f5&#34;&gt;likeBlog&lt;/span&gt;(id);&#xA;&lt;/span&gt;&lt;/span&gt;&lt;span style=&#34;display:flex;&#34;&gt;&lt;span&gt;}&#xA;&lt;/span&gt;&lt;/span&gt;&lt;/code&gt;&lt;/pre&gt;&lt;/td&gt;&lt;/tr&gt;&lt;/table&gt;&#xA;&lt;/div&gt;&#xA;&lt;/div&gt;&lt;p&gt;Frontend doesn&amp;rsquo;t send current like status; backend checks if user liked by checking sorted set for user ID.&lt;/p&gt;</description>
    </item>
    <item>
      <title>Interfaces and Abstract Classes</title>
      <link>https://ruokezhang.github.io/en/post/java/javabasic/interfaceabstractclass/</link>
      <pubDate>Fri, 07 Feb 2025 00:00:00 +0000</pubDate>
      <guid>https://ruokezhang.github.io/en/post/java/javabasic/interfaceabstractclass/</guid>
      <description>&lt;h2 id=&#34;interface&#34;&gt;Interface&lt;/h2&gt;&#xA;&lt;p&gt;An interface is an abstraction of behavior.&lt;/p&gt;&#xA;&lt;ol&gt;&#xA;&lt;li&gt;Abstract methods: Before Java 8, interfaces could only have abstract methods.&lt;/li&gt;&#xA;&lt;li&gt;Default methods: Provide method bodies, available since Java 8.&lt;/li&gt;&#xA;&lt;li&gt;Static methods: Provide method bodies, available since Java 8, can be called via &lt;code&gt;Interface.method()&lt;/code&gt;.&lt;/li&gt;&#xA;&lt;/ol&gt;&#xA;&lt;div class=&#34;highlight&#34;&gt;&lt;div style=&#34;color:#4c4f69;background-color:#eff1f5;-moz-tab-size:2;-o-tab-size:2;tab-size:2;&#34;&gt;&#xA;&lt;table style=&#34;border-spacing:0;padding:0;margin:0;border:0;&#34;&gt;&lt;tr&gt;&lt;td style=&#34;vertical-align:top;padding:0;margin:0;border:0;&#34;&gt;&#xA;&lt;pre tabindex=&#34;0&#34; style=&#34;color:#4c4f69;background-color:#eff1f5;-moz-tab-size:2;-o-tab-size:2;tab-size:2;&#34;&gt;&lt;code&gt;&lt;span style=&#34;white-space:pre;-webkit-user-select:none;user-select:none;margin-right:0.4em;padding:0 0.4em 0 0.4em;color:#8c8fa1&#34;&gt; 1&#xA;&lt;/span&gt;&lt;span style=&#34;white-space:pre;-webkit-user-select:none;user-select:none;margin-right:0.4em;padding:0 0.4em 0 0.4em;color:#8c8fa1&#34;&gt; 2&#xA;&lt;/span&gt;&lt;span style=&#34;white-space:pre;-webkit-user-select:none;user-select:none;margin-right:0.4em;padding:0 0.4em 0 0.4em;color:#8c8fa1&#34;&gt; 3&#xA;&lt;/span&gt;&lt;span style=&#34;white-space:pre;-webkit-user-select:none;user-select:none;margin-right:0.4em;padding:0 0.4em 0 0.4em;color:#8c8fa1&#34;&gt; 4&#xA;&lt;/span&gt;&lt;span style=&#34;white-space:pre;-webkit-user-select:none;user-select:none;margin-right:0.4em;padding:0 0.4em 0 0.4em;color:#8c8fa1&#34;&gt; 5&#xA;&lt;/span&gt;&lt;span style=&#34;white-space:pre;-webkit-user-select:none;user-select:none;margin-right:0.4em;padding:0 0.4em 0 0.4em;color:#8c8fa1&#34;&gt; 6&#xA;&lt;/span&gt;&lt;span style=&#34;white-space:pre;-webkit-user-select:none;user-select:none;margin-right:0.4em;padding:0 0.4em 0 0.4em;color:#8c8fa1&#34;&gt; 7&#xA;&lt;/span&gt;&lt;span style=&#34;white-space:pre;-webkit-user-select:none;user-select:none;margin-right:0.4em;padding:0 0.4em 0 0.4em;color:#8c8fa1&#34;&gt; 8&#xA;&lt;/span&gt;&lt;span style=&#34;white-space:pre;-webkit-user-select:none;user-select:none;margin-right:0.4em;padding:0 0.4em 0 0.4em;color:#8c8fa1&#34;&gt; 9&#xA;&lt;/span&gt;&lt;span style=&#34;white-space:pre;-webkit-user-select:none;user-select:none;margin-right:0.4em;padding:0 0.4em 0 0.4em;color:#8c8fa1&#34;&gt;10&#xA;&lt;/span&gt;&lt;span style=&#34;white-space:pre;-webkit-user-select:none;user-select:none;margin-right:0.4em;padding:0 0.4em 0 0.4em;color:#8c8fa1&#34;&gt;11&#xA;&lt;/span&gt;&lt;span style=&#34;white-space:pre;-webkit-user-select:none;user-select:none;margin-right:0.4em;padding:0 0.4em 0 0.4em;color:#8c8fa1&#34;&gt;12&#xA;&lt;/span&gt;&lt;span style=&#34;white-space:pre;-webkit-user-select:none;user-select:none;margin-right:0.4em;padding:0 0.4em 0 0.4em;color:#8c8fa1&#34;&gt;13&#xA;&lt;/span&gt;&lt;span style=&#34;white-space:pre;-webkit-user-select:none;user-select:none;margin-right:0.4em;padding:0 0.4em 0 0.4em;color:#8c8fa1&#34;&gt;14&#xA;&lt;/span&gt;&lt;span style=&#34;white-space:pre;-webkit-user-select:none;user-select:none;margin-right:0.4em;padding:0 0.4em 0 0.4em;color:#8c8fa1&#34;&gt;15&#xA;&lt;/span&gt;&lt;span style=&#34;white-space:pre;-webkit-user-select:none;user-select:none;margin-right:0.4em;padding:0 0.4em 0 0.4em;color:#8c8fa1&#34;&gt;16&#xA;&lt;/span&gt;&lt;span style=&#34;white-space:pre;-webkit-user-select:none;user-select:none;margin-right:0.4em;padding:0 0.4em 0 0.4em;color:#8c8fa1&#34;&gt;17&#xA;&lt;/span&gt;&lt;span style=&#34;white-space:pre;-webkit-user-select:none;user-select:none;margin-right:0.4em;padding:0 0.4em 0 0.4em;color:#8c8fa1&#34;&gt;18&#xA;&lt;/span&gt;&lt;span style=&#34;white-space:pre;-webkit-user-select:none;user-select:none;margin-right:0.4em;padding:0 0.4em 0 0.4em;color:#8c8fa1&#34;&gt;19&#xA;&lt;/span&gt;&lt;span style=&#34;white-space:pre;-webkit-user-select:none;user-select:none;margin-right:0.4em;padding:0 0.4em 0 0.4em;color:#8c8fa1&#34;&gt;20&#xA;&lt;/span&gt;&lt;span style=&#34;white-space:pre;-webkit-user-select:none;user-select:none;margin-right:0.4em;padding:0 0.4em 0 0.4em;color:#8c8fa1&#34;&gt;21&#xA;&lt;/span&gt;&lt;span style=&#34;white-space:pre;-webkit-user-select:none;user-select:none;margin-right:0.4em;padding:0 0.4em 0 0.4em;color:#8c8fa1&#34;&gt;22&#xA;&lt;/span&gt;&lt;span style=&#34;white-space:pre;-webkit-user-select:none;user-select:none;margin-right:0.4em;padding:0 0.4em 0 0.4em;color:#8c8fa1&#34;&gt;23&#xA;&lt;/span&gt;&lt;span style=&#34;white-space:pre;-webkit-user-select:none;user-select:none;margin-right:0.4em;padding:0 0.4em 0 0.4em;color:#8c8fa1&#34;&gt;24&#xA;&lt;/span&gt;&lt;span style=&#34;white-space:pre;-webkit-user-select:none;user-select:none;margin-right:0.4em;padding:0 0.4em 0 0.4em;color:#8c8fa1&#34;&gt;25&#xA;&lt;/span&gt;&lt;span style=&#34;white-space:pre;-webkit-user-select:none;user-select:none;margin-right:0.4em;padding:0 0.4em 0 0.4em;color:#8c8fa1&#34;&gt;26&#xA;&lt;/span&gt;&lt;span style=&#34;white-space:pre;-webkit-user-select:none;user-select:none;margin-right:0.4em;padding:0 0.4em 0 0.4em;color:#8c8fa1&#34;&gt;27&#xA;&lt;/span&gt;&lt;span style=&#34;white-space:pre;-webkit-user-select:none;user-select:none;margin-right:0.4em;padding:0 0.4em 0 0.4em;color:#8c8fa1&#34;&gt;28&#xA;&lt;/span&gt;&lt;span style=&#34;white-space:pre;-webkit-user-select:none;user-select:none;margin-right:0.4em;padding:0 0.4em 0 0.4em;color:#8c8fa1&#34;&gt;29&#xA;&lt;/span&gt;&lt;span style=&#34;white-space:pre;-webkit-user-select:none;user-select:none;margin-right:0.4em;padding:0 0.4em 0 0.4em;color:#8c8fa1&#34;&gt;30&#xA;&lt;/span&gt;&lt;span style=&#34;white-space:pre;-webkit-user-select:none;user-select:none;margin-right:0.4em;padding:0 0.4em 0 0.4em;color:#8c8fa1&#34;&gt;31&#xA;&lt;/span&gt;&lt;span style=&#34;white-space:pre;-webkit-user-select:none;user-select:none;margin-right:0.4em;padding:0 0.4em 0 0.4em;color:#8c8fa1&#34;&gt;32&#xA;&lt;/span&gt;&lt;span style=&#34;white-space:pre;-webkit-user-select:none;user-select:none;margin-right:0.4em;padding:0 0.4em 0 0.4em;color:#8c8fa1&#34;&gt;33&#xA;&lt;/span&gt;&lt;span style=&#34;white-space:pre;-webkit-user-select:none;user-select:none;margin-right:0.4em;padding:0 0.4em 0 0.4em;color:#8c8fa1&#34;&gt;34&#xA;&lt;/span&gt;&lt;span style=&#34;white-space:pre;-webkit-user-select:none;user-select:none;margin-right:0.4em;padding:0 0.4em 0 0.4em;color:#8c8fa1&#34;&gt;35&#xA;&lt;/span&gt;&lt;span style=&#34;white-space:pre;-webkit-user-select:none;user-select:none;margin-right:0.4em;padding:0 0.4em 0 0.4em;color:#8c8fa1&#34;&gt;36&#xA;&lt;/span&gt;&lt;span style=&#34;white-space:pre;-webkit-user-select:none;user-select:none;margin-right:0.4em;padding:0 0.4em 0 0.4em;color:#8c8fa1&#34;&gt;37&#xA;&lt;/span&gt;&lt;span style=&#34;white-space:pre;-webkit-user-select:none;user-select:none;margin-right:0.4em;padding:0 0.4em 0 0.4em;color:#8c8fa1&#34;&gt;38&#xA;&lt;/span&gt;&lt;span style=&#34;white-space:pre;-webkit-user-select:none;user-select:none;margin-right:0.4em;padding:0 0.4em 0 0.4em;color:#8c8fa1&#34;&gt;39&#xA;&lt;/span&gt;&lt;span style=&#34;white-space:pre;-webkit-user-select:none;user-select:none;margin-right:0.4em;padding:0 0.4em 0 0.4em;color:#8c8fa1&#34;&gt;40&#xA;&lt;/span&gt;&lt;span style=&#34;white-space:pre;-webkit-user-select:none;user-select:none;margin-right:0.4em;padding:0 0.4em 0 0.4em;color:#8c8fa1&#34;&gt;41&#xA;&lt;/span&gt;&lt;span style=&#34;white-space:pre;-webkit-user-select:none;user-select:none;margin-right:0.4em;padding:0 0.4em 0 0.4em;color:#8c8fa1&#34;&gt;42&#xA;&lt;/span&gt;&lt;span style=&#34;white-space:pre;-webkit-user-select:none;user-select:none;margin-right:0.4em;padding:0 0.4em 0 0.4em;color:#8c8fa1&#34;&gt;43&#xA;&lt;/span&gt;&lt;span style=&#34;white-space:pre;-webkit-user-select:none;user-select:none;margin-right:0.4em;padding:0 0.4em 0 0.4em;color:#8c8fa1&#34;&gt;44&#xA;&lt;/span&gt;&lt;span style=&#34;white-space:pre;-webkit-user-select:none;user-select:none;margin-right:0.4em;padding:0 0.4em 0 0.4em;color:#8c8fa1&#34;&gt;45&#xA;&lt;/span&gt;&lt;span style=&#34;white-space:pre;-webkit-user-select:none;user-select:none;margin-right:0.4em;padding:0 0.4em 0 0.4em;color:#8c8fa1&#34;&gt;46&#xA;&lt;/span&gt;&lt;span style=&#34;white-space:pre;-webkit-user-select:none;user-select:none;margin-right:0.4em;padding:0 0.4em 0 0.4em;color:#8c8fa1&#34;&gt;47&#xA;&lt;/span&gt;&lt;span style=&#34;white-space:pre;-webkit-user-select:none;user-select:none;margin-right:0.4em;padding:0 0.4em 0 0.4em;color:#8c8fa1&#34;&gt;48&#xA;&lt;/span&gt;&lt;span style=&#34;white-space:pre;-webkit-user-select:none;user-select:none;margin-right:0.4em;padding:0 0.4em 0 0.4em;color:#8c8fa1&#34;&gt;49&#xA;&lt;/span&gt;&lt;/code&gt;&lt;/pre&gt;&lt;/td&gt;&#xA;&lt;td style=&#34;vertical-align:top;padding:0;margin:0;border:0;;width:100%&#34;&gt;&#xA;&lt;pre tabindex=&#34;0&#34; style=&#34;color:#4c4f69;background-color:#eff1f5;-moz-tab-size:2;-o-tab-size:2;tab-size:2;&#34;&gt;&lt;code class=&#34;language-java&#34; data-lang=&#34;java&#34;&gt;&lt;span style=&#34;display:flex;&#34;&gt;&lt;span&gt;&lt;span style=&#34;color:#d20f39&#34;&gt;public&lt;/span&gt; &lt;span style=&#34;color:#d20f39&#34;&gt;interface&lt;/span&gt; &lt;span style=&#34;color:#df8e1d&#34;&gt;MyInterface&lt;/span&gt; {&#xA;&lt;/span&gt;&lt;/span&gt;&lt;span style=&#34;display:flex;&#34;&gt;&lt;span&gt;    &lt;span style=&#34;color:#9ca0b0;font-style:italic&#34;&gt;// Abstract method&lt;/span&gt;&#xA;&lt;/span&gt;&lt;/span&gt;&lt;span style=&#34;display:flex;&#34;&gt;&lt;span&gt;    &lt;span style=&#34;color:#d20f39&#34;&gt;void&lt;/span&gt; &lt;span style=&#34;color:#1e66f5&#34;&gt;abstractMethod&lt;/span&gt;();&#xA;&lt;/span&gt;&lt;/span&gt;&lt;span style=&#34;display:flex;&#34;&gt;&lt;span&gt;&#xA;&lt;/span&gt;&lt;/span&gt;&lt;span style=&#34;display:flex;&#34;&gt;&lt;span&gt;    &lt;span style=&#34;color:#9ca0b0;font-style:italic&#34;&gt;// Default method&lt;/span&gt;&#xA;&lt;/span&gt;&lt;/span&gt;&lt;span style=&#34;display:flex;&#34;&gt;&lt;span&gt;    &lt;span style=&#34;color:#8839ef&#34;&gt;default&lt;/span&gt; &lt;span style=&#34;color:#d20f39&#34;&gt;void&lt;/span&gt; &lt;span style=&#34;color:#1e66f5&#34;&gt;defaultMethod&lt;/span&gt;() {&#xA;&lt;/span&gt;&lt;/span&gt;&lt;span style=&#34;display:flex;&#34;&gt;&lt;span&gt;        System.&lt;span style=&#34;color:#1e66f5&#34;&gt;out&lt;/span&gt;.&lt;span style=&#34;color:#1e66f5&#34;&gt;println&lt;/span&gt;(&lt;span style=&#34;color:#40a02b&#34;&gt;&amp;#34;This is the default method of the interface&amp;#34;&lt;/span&gt;);&#xA;&lt;/span&gt;&lt;/span&gt;&lt;span style=&#34;display:flex;&#34;&gt;&lt;span&gt;        privateHelperMethod();  &lt;span style=&#34;color:#9ca0b0;font-style:italic&#34;&gt;// Call private helper method (Note: private methods are a Java 9 feature, shown here for example only)&lt;/span&gt;&#xA;&lt;/span&gt;&lt;/span&gt;&lt;span style=&#34;display:flex;&#34;&gt;&lt;span&gt;    }&#xA;&lt;/span&gt;&lt;/span&gt;&lt;span style=&#34;display:flex;&#34;&gt;&lt;span&gt;&#xA;&lt;/span&gt;&lt;/span&gt;&lt;span style=&#34;display:flex;&#34;&gt;&lt;span&gt;    &lt;span style=&#34;color:#9ca0b0;font-style:italic&#34;&gt;// Static method&lt;/span&gt;&#xA;&lt;/span&gt;&lt;/span&gt;&lt;span style=&#34;display:flex;&#34;&gt;&lt;span&gt;    &lt;span style=&#34;color:#d20f39&#34;&gt;static&lt;/span&gt; &lt;span style=&#34;color:#d20f39&#34;&gt;void&lt;/span&gt; &lt;span style=&#34;color:#1e66f5&#34;&gt;staticMethod&lt;/span&gt;() {&#xA;&lt;/span&gt;&lt;/span&gt;&lt;span style=&#34;display:flex;&#34;&gt;&lt;span&gt;        System.&lt;span style=&#34;color:#1e66f5&#34;&gt;out&lt;/span&gt;.&lt;span style=&#34;color:#1e66f5&#34;&gt;println&lt;/span&gt;(&lt;span style=&#34;color:#40a02b&#34;&gt;&amp;#34;This is the static method of the interface&amp;#34;&lt;/span&gt;);&#xA;&lt;/span&gt;&lt;/span&gt;&lt;span style=&#34;display:flex;&#34;&gt;&lt;span&gt;    }&#xA;&lt;/span&gt;&lt;/span&gt;&lt;span style=&#34;display:flex;&#34;&gt;&lt;span&gt;&#xA;&lt;/span&gt;&lt;/span&gt;&lt;span style=&#34;display:flex;&#34;&gt;&lt;span&gt;    &lt;span style=&#34;color:#9ca0b0;font-style:italic&#34;&gt;// Private helper method (Java 9 feature, but included for completeness)&lt;/span&gt;&#xA;&lt;/span&gt;&lt;/span&gt;&lt;span style=&#34;display:flex;&#34;&gt;&lt;span&gt;    &lt;span style=&#34;color:#d20f39&#34;&gt;private&lt;/span&gt; &lt;span style=&#34;color:#d20f39&#34;&gt;void&lt;/span&gt; &lt;span style=&#34;color:#1e66f5&#34;&gt;privateHelperMethod&lt;/span&gt;() {&#xA;&lt;/span&gt;&lt;/span&gt;&lt;span style=&#34;display:flex;&#34;&gt;&lt;span&gt;        System.&lt;span style=&#34;color:#1e66f5&#34;&gt;out&lt;/span&gt;.&lt;span style=&#34;color:#1e66f5&#34;&gt;println&lt;/span&gt;(&lt;span style=&#34;color:#40a02b&#34;&gt;&amp;#34;This is the private helper method of the interface&amp;#34;&lt;/span&gt;);&#xA;&lt;/span&gt;&lt;/span&gt;&lt;span style=&#34;display:flex;&#34;&gt;&lt;span&gt;    }&#xA;&lt;/span&gt;&lt;/span&gt;&lt;span style=&#34;display:flex;&#34;&gt;&lt;span&gt;}&#xA;&lt;/span&gt;&lt;/span&gt;&lt;span style=&#34;display:flex;&#34;&gt;&lt;span&gt;&#xA;&lt;/span&gt;&lt;/span&gt;&lt;span style=&#34;display:flex;&#34;&gt;&lt;span&gt;&lt;span style=&#34;color:#d20f39&#34;&gt;public&lt;/span&gt; &lt;span style=&#34;color:#d20f39&#34;&gt;class&lt;/span&gt; &lt;span style=&#34;color:#df8e1d&#34;&gt;MyClass&lt;/span&gt; &lt;span style=&#34;color:#d20f39&#34;&gt;implements&lt;/span&gt; MyInterface {&#xA;&lt;/span&gt;&lt;/span&gt;&lt;span style=&#34;display:flex;&#34;&gt;&lt;span&gt;    &lt;span style=&#34;color:#1e66f5;font-weight:bold&#34;&gt;@Override&lt;/span&gt;&#xA;&lt;/span&gt;&lt;/span&gt;&lt;span style=&#34;display:flex;&#34;&gt;&lt;span&gt;    &lt;span style=&#34;color:#d20f39&#34;&gt;public&lt;/span&gt; &lt;span style=&#34;color:#d20f39&#34;&gt;void&lt;/span&gt; &lt;span style=&#34;color:#1e66f5&#34;&gt;abstractMethod&lt;/span&gt;() {&#xA;&lt;/span&gt;&lt;/span&gt;&lt;span style=&#34;display:flex;&#34;&gt;&lt;span&gt;        System.&lt;span style=&#34;color:#1e66f5&#34;&gt;out&lt;/span&gt;.&lt;span style=&#34;color:#1e66f5&#34;&gt;println&lt;/span&gt;(&lt;span style=&#34;color:#40a02b&#34;&gt;&amp;#34;Implementing the abstract method of the interface&amp;#34;&lt;/span&gt;);&#xA;&lt;/span&gt;&lt;/span&gt;&lt;span style=&#34;display:flex;&#34;&gt;&lt;span&gt;    }&#xA;&lt;/span&gt;&lt;/span&gt;&lt;span style=&#34;display:flex;&#34;&gt;&lt;span&gt;&#xA;&lt;/span&gt;&lt;/span&gt;&lt;span style=&#34;display:flex;&#34;&gt;&lt;span&gt;    &lt;span style=&#34;color:#9ca0b0;font-style:italic&#34;&gt;// Can choose to override the default method&lt;/span&gt;&#xA;&lt;/span&gt;&lt;/span&gt;&lt;span style=&#34;display:flex;&#34;&gt;&lt;span&gt;    &lt;span style=&#34;color:#1e66f5;font-weight:bold&#34;&gt;@Override&lt;/span&gt;&#xA;&lt;/span&gt;&lt;/span&gt;&lt;span style=&#34;display:flex;&#34;&gt;&lt;span&gt;    &lt;span style=&#34;color:#d20f39&#34;&gt;public&lt;/span&gt; &lt;span style=&#34;color:#d20f39&#34;&gt;void&lt;/span&gt; &lt;span style=&#34;color:#1e66f5&#34;&gt;defaultMethod&lt;/span&gt;() {&#xA;&lt;/span&gt;&lt;/span&gt;&lt;span style=&#34;display:flex;&#34;&gt;&lt;span&gt;        System.&lt;span style=&#34;color:#1e66f5&#34;&gt;out&lt;/span&gt;.&lt;span style=&#34;color:#1e66f5&#34;&gt;println&lt;/span&gt;(&lt;span style=&#34;color:#40a02b&#34;&gt;&amp;#34;Overriding the default method of the interface&amp;#34;&lt;/span&gt;);&#xA;&lt;/span&gt;&lt;/span&gt;&lt;span style=&#34;display:flex;&#34;&gt;&lt;span&gt;        MyInterface.&lt;span style=&#34;color:#1e66f5&#34;&gt;super&lt;/span&gt;.&lt;span style=&#34;color:#1e66f5&#34;&gt;defaultMethod&lt;/span&gt;();  &lt;span style=&#34;color:#9ca0b0;font-style:italic&#34;&gt;// Call the default method of the interface&lt;/span&gt;&#xA;&lt;/span&gt;&lt;/span&gt;&lt;span style=&#34;display:flex;&#34;&gt;&lt;span&gt;    }&#xA;&lt;/span&gt;&lt;/span&gt;&lt;span style=&#34;display:flex;&#34;&gt;&lt;span&gt;}&#xA;&lt;/span&gt;&lt;/span&gt;&lt;span style=&#34;display:flex;&#34;&gt;&lt;span&gt;&#xA;&lt;/span&gt;&lt;/span&gt;&lt;span style=&#34;display:flex;&#34;&gt;&lt;span&gt;&lt;span style=&#34;color:#d20f39&#34;&gt;public&lt;/span&gt; &lt;span style=&#34;color:#d20f39&#34;&gt;class&lt;/span&gt; &lt;span style=&#34;color:#df8e1d&#34;&gt;Main&lt;/span&gt; {&#xA;&lt;/span&gt;&lt;/span&gt;&lt;span style=&#34;display:flex;&#34;&gt;&lt;span&gt;    &lt;span style=&#34;color:#d20f39&#34;&gt;public&lt;/span&gt; &lt;span style=&#34;color:#d20f39&#34;&gt;static&lt;/span&gt; &lt;span style=&#34;color:#d20f39&#34;&gt;void&lt;/span&gt; &lt;span style=&#34;color:#1e66f5&#34;&gt;main&lt;/span&gt;(String&lt;span style=&#34;color:#04a5e5;font-weight:bold&#34;&gt;[]&lt;/span&gt; args) {&#xA;&lt;/span&gt;&lt;/span&gt;&lt;span style=&#34;display:flex;&#34;&gt;&lt;span&gt;        MyClass myClass &lt;span style=&#34;color:#04a5e5;font-weight:bold&#34;&gt;=&lt;/span&gt; &lt;span style=&#34;color:#8839ef&#34;&gt;new&lt;/span&gt; MyClass();&#xA;&lt;/span&gt;&lt;/span&gt;&lt;span style=&#34;display:flex;&#34;&gt;&lt;span&gt;&#xA;&lt;/span&gt;&lt;/span&gt;&lt;span style=&#34;display:flex;&#34;&gt;&lt;span&gt;        &lt;span style=&#34;color:#9ca0b0;font-style:italic&#34;&gt;// Call the implemented abstract method&lt;/span&gt;&#xA;&lt;/span&gt;&lt;/span&gt;&lt;span style=&#34;display:flex;&#34;&gt;&lt;span&gt;        myClass.&lt;span style=&#34;color:#1e66f5&#34;&gt;abstractMethod&lt;/span&gt;();&#xA;&lt;/span&gt;&lt;/span&gt;&lt;span style=&#34;display:flex;&#34;&gt;&lt;span&gt;&#xA;&lt;/span&gt;&lt;/span&gt;&lt;span style=&#34;display:flex;&#34;&gt;&lt;span&gt;        &lt;span style=&#34;color:#9ca0b0;font-style:italic&#34;&gt;// Call the default method&lt;/span&gt;&#xA;&lt;/span&gt;&lt;/span&gt;&lt;span style=&#34;display:flex;&#34;&gt;&lt;span&gt;        myClass.&lt;span style=&#34;color:#1e66f5&#34;&gt;defaultMethod&lt;/span&gt;();  &lt;span style=&#34;color:#9ca0b0;font-style:italic&#34;&gt;// Note that the overridden version is called here&lt;/span&gt;&#xA;&lt;/span&gt;&lt;/span&gt;&lt;span style=&#34;display:flex;&#34;&gt;&lt;span&gt;&#xA;&lt;/span&gt;&lt;/span&gt;&lt;span style=&#34;display:flex;&#34;&gt;&lt;span&gt;        &lt;span style=&#34;color:#9ca0b0;font-style:italic&#34;&gt;// Call the static method of the interface&lt;/span&gt;&#xA;&lt;/span&gt;&lt;/span&gt;&lt;span style=&#34;display:flex;&#34;&gt;&lt;span&gt;        MyInterface.&lt;span style=&#34;color:#1e66f5&#34;&gt;staticMethod&lt;/span&gt;();&#xA;&lt;/span&gt;&lt;/span&gt;&lt;span style=&#34;display:flex;&#34;&gt;&lt;span&gt;    }&#xA;&lt;/span&gt;&lt;/span&gt;&lt;span style=&#34;display:flex;&#34;&gt;&lt;span&gt;}&#xA;&lt;/span&gt;&lt;/span&gt;&lt;/code&gt;&lt;/pre&gt;&lt;/td&gt;&lt;/tr&gt;&lt;/table&gt;&#xA;&lt;/div&gt;&#xA;&lt;/div&gt;&lt;h2 id=&#34;abstract-class&#34;&gt;Abstract Class&lt;/h2&gt;&#xA;&lt;p&gt;Abstract classes typically serve as base classes, such as Person, Animal. Because the body of certain methods may differ among various subclasses, these methods are placed as abstract methods in the abstract class.&lt;/p&gt;</description>
    </item>
    <item>
      <title>New Features in Java 8</title>
      <link>https://ruokezhang.github.io/en/post/java/javabasic/java8/</link>
      <pubDate>Fri, 07 Feb 2025 00:00:00 +0000</pubDate>
      <guid>https://ruokezhang.github.io/en/post/java/javabasic/java8/</guid>
      <description>&lt;h2 id=&#34;functional-interface&#34;&gt;Functional Interface&lt;/h2&gt;&#xA;&lt;p&gt;A functional interface is defined as an interface that must contain only one abstract method. It can have many static or default methods (with implementations), but there must be only one abstract method.&lt;/p&gt;&#xA;&lt;p&gt;This abstract method indicates that it can perform a certain behavior, but the specific action is determined by the caller through overriding this abstract method. This can be achieved using anonymous inner classes or lambda expressions.&lt;/p&gt;</description>
    </item>
    <item>
      <title>Concurrency</title>
      <link>https://ruokezhang.github.io/en/post/os/concurrency/</link>
      <pubDate>Wed, 05 Feb 2025 00:00:00 +0000</pubDate>
      <guid>https://ruokezhang.github.io/en/post/os/concurrency/</guid>
      <description>&lt;h2 id=&#34;goals&#34;&gt;Goals&lt;/h2&gt;&#xA;&lt;ul&gt;&#xA;&lt;li&gt;Mutual exclusion (e.g., A and B don’t run at the same time) — process mutual exclusion&#xA;&lt;ul&gt;&#xA;&lt;li&gt;solved with locks&lt;/li&gt;&#xA;&lt;/ul&gt;&#xA;&lt;/li&gt;&#xA;&lt;li&gt;Ordering (e.g., B runs after A does something) — process synchronization&#xA;&lt;ul&gt;&#xA;&lt;li&gt;solved with condition variables OR semaphores&lt;/li&gt;&#xA;&lt;/ul&gt;&#xA;&lt;/li&gt;&#xA;&lt;/ul&gt;&#xA;&lt;p&gt;&lt;a href=&#34;https://pages.cs.wisc.edu/~remzi/Classes/537/Fall2021/Discussion/videos.html&#34;&gt;CS 537 Videos&lt;/a&gt;&#xA;&lt;a href=&#34;https://xiaolincoding.com/os/4_process/multithread_sync.html#%E4%BF%A1%E5%8F%B7%E9%87%8F&#34;&gt;小林coding&lt;/a&gt;&lt;/p&gt;&#xA;&lt;h2 id=&#34;locks&#34;&gt;Locks&lt;/h2&gt;&#xA;&lt;p&gt;You can think of a lock as a mutex. It’s just a variable with two states: available/acquired. Each thread can acquire and release it.&#xA;&lt;a href=&#34;https://pages.cs.wisc.edu/~remzi/OSTEP/threads-locks.pdf&#34;&gt;Reference: OSTEP-Locks&lt;/a&gt;&lt;/p&gt;</description>
    </item>
    <item>
      <title>BlackHorse Rating Merchant Cache</title>
      <link>https://ruokezhang.github.io/en/post/blackhorserating/shopcache/</link>
      <pubDate>Mon, 03 Feb 2025 00:00:00 +0000</pubDate>
      <guid>https://ruokezhang.github.io/en/post/blackhorserating/shopcache/</guid>
      <description>&lt;h2 id=&#34;consistency&#34;&gt;Consistency&lt;/h2&gt;&#xA;&lt;h3 id=&#34;cache-update-strategies&#34;&gt;Cache Update Strategies&lt;/h3&gt;&#xA;&lt;ol&gt;&#xA;&lt;li&gt;Memory Eviction: Redis automatically evicts data when memory is low; cache updated on next request.&lt;/li&gt;&#xA;&lt;li&gt;TTL Expiry: Set TTL on cached data; deleted automatically when expired; updated on next request.&lt;/li&gt;&#xA;&lt;li&gt;Active Update: Update cache simultaneously with database modification.&lt;/li&gt;&#xA;&lt;/ol&gt;&#xA;&lt;h3 id=&#34;cache-database-consistency&#34;&gt;Cache-Database Consistency&lt;/h3&gt;&#xA;&lt;p&gt;Concurrent requests can cause inconsistency regardless of update order (cache first or database first).&lt;/p&gt;&#xA;&lt;p&gt;Use &lt;strong&gt;Cache Aside&lt;/strong&gt; strategy: cache only updated during read operations.&lt;/p&gt;&#xA;&lt;ul&gt;&#xA;&lt;li&gt;Write strategy: When modifying data, update database and &lt;strong&gt;delete&lt;/strong&gt; cache.&lt;/li&gt;&#xA;&lt;li&gt;Read strategy: When reading data, if cache miss, read from database and update cache.&lt;/li&gt;&#xA;&lt;/ul&gt;&#xA;&lt;h4 id=&#34;update-then-delete-delayed-double-delete&#34;&gt;Update-Then-Delete (Delayed Double Delete)&lt;/h4&gt;&#xA;&lt;p&gt;Thread A reading, Thread B updating simultaneously:&lt;/p&gt;</description>
    </item>
    <item>
      <title>Coupon Seckill</title>
      <link>https://ruokezhang.github.io/en/post/blackhorserating/voucher/</link>
      <pubDate>Sat, 01 Feb 2025 00:00:00 +0000</pubDate>
      <guid>https://ruokezhang.github.io/en/post/blackhorserating/voucher/</guid>
      <description>&lt;h2 id=&#34;global-id-generator-redis-auto-increment&#34;&gt;Global ID Generator: Redis Auto-increment&lt;/h2&gt;&#xA;&lt;p&gt;Disadvantages of database auto-increment IDs:&lt;/p&gt;&#xA;&lt;ol&gt;&#xA;&lt;li&gt;May expose business metrics: users could infer daily coupon sales.&lt;/li&gt;&#xA;&lt;li&gt;Large coupon volumes lead to oversized IDs; sharding causes ID conflicts.&lt;/li&gt;&#xA;&lt;/ol&gt;&#xA;&lt;p&gt;&lt;img src=&#34;https://blog-ruoke.oss-cn-hongkong.aliyuncs.com/blog/images/uniqueID.png&#34; alt=&#34;Alt text&#34;&gt;&lt;/p&gt;&#xA;&lt;div class=&#34;highlight&#34;&gt;&lt;div style=&#34;color:#4c4f69;background-color:#eff1f5;-moz-tab-size:2;-o-tab-size:2;tab-size:2;&#34;&gt;&#xA;&lt;table style=&#34;border-spacing:0;padding:0;margin:0;border:0;&#34;&gt;&lt;tr&gt;&lt;td style=&#34;vertical-align:top;padding:0;margin:0;border:0;&#34;&gt;&#xA;&lt;pre tabindex=&#34;0&#34; style=&#34;color:#4c4f69;background-color:#eff1f5;-moz-tab-size:2;-o-tab-size:2;tab-size:2;&#34;&gt;&lt;code&gt;&lt;span style=&#34;white-space:pre;-webkit-user-select:none;user-select:none;margin-right:0.4em;padding:0 0.4em 0 0.4em;color:#8c8fa1&#34;&gt; 1&#xA;&lt;/span&gt;&lt;span style=&#34;white-space:pre;-webkit-user-select:none;user-select:none;margin-right:0.4em;padding:0 0.4em 0 0.4em;color:#8c8fa1&#34;&gt; 2&#xA;&lt;/span&gt;&lt;span style=&#34;white-space:pre;-webkit-user-select:none;user-select:none;margin-right:0.4em;padding:0 0.4em 0 0.4em;color:#8c8fa1&#34;&gt; 3&#xA;&lt;/span&gt;&lt;span style=&#34;white-space:pre;-webkit-user-select:none;user-select:none;margin-right:0.4em;padding:0 0.4em 0 0.4em;color:#8c8fa1&#34;&gt; 4&#xA;&lt;/span&gt;&lt;span style=&#34;white-space:pre;-webkit-user-select:none;user-select:none;margin-right:0.4em;padding:0 0.4em 0 0.4em;color:#8c8fa1&#34;&gt; 5&#xA;&lt;/span&gt;&lt;span style=&#34;white-space:pre;-webkit-user-select:none;user-select:none;margin-right:0.4em;padding:0 0.4em 0 0.4em;color:#8c8fa1&#34;&gt; 6&#xA;&lt;/span&gt;&lt;span style=&#34;white-space:pre;-webkit-user-select:none;user-select:none;margin-right:0.4em;padding:0 0.4em 0 0.4em;color:#8c8fa1&#34;&gt; 7&#xA;&lt;/span&gt;&lt;span style=&#34;white-space:pre;-webkit-user-select:none;user-select:none;margin-right:0.4em;padding:0 0.4em 0 0.4em;color:#8c8fa1&#34;&gt; 8&#xA;&lt;/span&gt;&lt;span style=&#34;white-space:pre;-webkit-user-select:none;user-select:none;margin-right:0.4em;padding:0 0.4em 0 0.4em;color:#8c8fa1&#34;&gt; 9&#xA;&lt;/span&gt;&lt;span style=&#34;white-space:pre;-webkit-user-select:none;user-select:none;margin-right:0.4em;padding:0 0.4em 0 0.4em;color:#8c8fa1&#34;&gt;10&#xA;&lt;/span&gt;&lt;span style=&#34;white-space:pre;-webkit-user-select:none;user-select:none;margin-right:0.4em;padding:0 0.4em 0 0.4em;color:#8c8fa1&#34;&gt;11&#xA;&lt;/span&gt;&lt;span style=&#34;white-space:pre;-webkit-user-select:none;user-select:none;margin-right:0.4em;padding:0 0.4em 0 0.4em;color:#8c8fa1&#34;&gt;12&#xA;&lt;/span&gt;&lt;/code&gt;&lt;/pre&gt;&lt;/td&gt;&#xA;&lt;td style=&#34;vertical-align:top;padding:0;margin:0;border:0;;width:100%&#34;&gt;&#xA;&lt;pre tabindex=&#34;0&#34; style=&#34;color:#4c4f69;background-color:#eff1f5;-moz-tab-size:2;-o-tab-size:2;tab-size:2;&#34;&gt;&lt;code class=&#34;language-java&#34; data-lang=&#34;java&#34;&gt;&lt;span style=&#34;display:flex;&#34;&gt;&lt;span&gt;&lt;span style=&#34;color:#9ca0b0;font-style:italic&#34;&gt;// Sign bit 0 + 31-bit timestamp + 32-bit sequence number&lt;/span&gt;&#xA;&lt;/span&gt;&lt;/span&gt;&lt;span style=&#34;display:flex;&#34;&gt;&lt;span&gt;&lt;span style=&#34;color:#d20f39&#34;&gt;public&lt;/span&gt; &lt;span style=&#34;color:#d20f39&#34;&gt;long&lt;/span&gt; &lt;span style=&#34;color:#1e66f5&#34;&gt;nextId&lt;/span&gt;(String keyPrefix){&#xA;&lt;/span&gt;&lt;/span&gt;&lt;span style=&#34;display:flex;&#34;&gt;&lt;span&gt;    &lt;span style=&#34;color:#9ca0b0;font-style:italic&#34;&gt;// Generate timestamp&lt;/span&gt;&#xA;&lt;/span&gt;&lt;/span&gt;&lt;span style=&#34;display:flex;&#34;&gt;&lt;span&gt;    LocalDateTime now&lt;span style=&#34;color:#04a5e5;font-weight:bold&#34;&gt;=&lt;/span&gt;LocalDateTime.&lt;span style=&#34;color:#1e66f5&#34;&gt;now&lt;/span&gt;();&#xA;&lt;/span&gt;&lt;/span&gt;&lt;span style=&#34;display:flex;&#34;&gt;&lt;span&gt;    &lt;span style=&#34;color:#d20f39&#34;&gt;long&lt;/span&gt; nowSecond&lt;span style=&#34;color:#04a5e5;font-weight:bold&#34;&gt;=&lt;/span&gt;now.&lt;span style=&#34;color:#1e66f5&#34;&gt;toEpochSecond&lt;/span&gt;(ZoneOffset.&lt;span style=&#34;color:#1e66f5&#34;&gt;UTC&lt;/span&gt;);&#xA;&lt;/span&gt;&lt;/span&gt;&lt;span style=&#34;display:flex;&#34;&gt;&lt;span&gt;    &lt;span style=&#34;color:#d20f39&#34;&gt;long&lt;/span&gt; timestamp&lt;span style=&#34;color:#04a5e5;font-weight:bold&#34;&gt;=&lt;/span&gt;nowSecond&lt;span style=&#34;color:#04a5e5;font-weight:bold&#34;&gt;-&lt;/span&gt;BEGIN_TIMESTAMP;&#xA;&lt;/span&gt;&lt;/span&gt;&lt;span style=&#34;display:flex;&#34;&gt;&lt;span&gt;    &lt;span style=&#34;color:#9ca0b0;font-style:italic&#34;&gt;// Generate sequence number. Same key per day&lt;/span&gt;&#xA;&lt;/span&gt;&lt;/span&gt;&lt;span style=&#34;display:flex;&#34;&gt;&lt;span&gt;    String date&lt;span style=&#34;color:#04a5e5;font-weight:bold&#34;&gt;=&lt;/span&gt;now.&lt;span style=&#34;color:#1e66f5&#34;&gt;format&lt;/span&gt;(DateTimeFormatter.&lt;span style=&#34;color:#1e66f5&#34;&gt;ofPattern&lt;/span&gt;(&lt;span style=&#34;color:#40a02b&#34;&gt;&amp;#34;yyyy:MM:dd&amp;#34;&lt;/span&gt;));&#xA;&lt;/span&gt;&lt;/span&gt;&lt;span style=&#34;display:flex;&#34;&gt;&lt;span&gt;    &lt;span style=&#34;color:#d20f39&#34;&gt;long&lt;/span&gt; count&lt;span style=&#34;color:#04a5e5;font-weight:bold&#34;&gt;=&lt;/span&gt;  stringRedisTemplate.&lt;span style=&#34;color:#1e66f5&#34;&gt;opsForValue&lt;/span&gt;().&lt;span style=&#34;color:#1e66f5&#34;&gt;increment&lt;/span&gt;(&lt;span style=&#34;color:#40a02b&#34;&gt;&amp;#34;icr:&amp;#34;&lt;/span&gt;&lt;span style=&#34;color:#04a5e5;font-weight:bold&#34;&gt;+&lt;/span&gt;keyPrefix&lt;span style=&#34;color:#04a5e5;font-weight:bold&#34;&gt;+&lt;/span&gt;&lt;span style=&#34;color:#40a02b&#34;&gt;&amp;#34;:&amp;#34;&lt;/span&gt;&lt;span style=&#34;color:#04a5e5;font-weight:bold&#34;&gt;+&lt;/span&gt;date);&#xA;&lt;/span&gt;&lt;/span&gt;&lt;span style=&#34;display:flex;&#34;&gt;&lt;span&gt;    &lt;span style=&#34;color:#9ca0b0;font-style:italic&#34;&gt;// Combine and return&lt;/span&gt;&#xA;&lt;/span&gt;&lt;/span&gt;&lt;span style=&#34;display:flex;&#34;&gt;&lt;span&gt;    &lt;span style=&#34;color:#8839ef&#34;&gt;return&lt;/span&gt; timestamp&lt;span style=&#34;color:#04a5e5;font-weight:bold&#34;&gt;&amp;lt;&amp;lt;&lt;/span&gt;COUNT_BITS&lt;span style=&#34;color:#04a5e5;font-weight:bold&#34;&gt;|&lt;/span&gt;count;&#xA;&lt;/span&gt;&lt;/span&gt;&lt;span style=&#34;display:flex;&#34;&gt;&lt;span&gt;}&#xA;&lt;/span&gt;&lt;/span&gt;&lt;/code&gt;&lt;/pre&gt;&lt;/td&gt;&lt;/tr&gt;&lt;/table&gt;&#xA;&lt;/div&gt;&#xA;&lt;/div&gt;&lt;p&gt;keyPrefix represents object type, e.g., coupon order.&lt;/p&gt;</description>
    </item>
    <item>
      <title>Redis Caching Patterns and Failure Modes</title>
      <link>https://ruokezhang.github.io/en/post/redis/caching_patterns/</link>
      <pubDate>Fri, 31 Jan 2025 00:00:00 +0000</pubDate>
      <guid>https://ruokezhang.github.io/en/post/redis/caching_patterns/</guid>
      <description>&lt;p&gt;References: &lt;a href=&#34;https://redis.io/learn/howtos/solutions/microservices/caching&#34;&gt;Redis query caching&lt;/a&gt;, &lt;a href=&#34;https://hazelcast.com/blog/a-hitchhikers-guide-to-caching-patterns/&#34;&gt;caching patterns&lt;/a&gt;, and &lt;a href=&#34;https://redis.io/docs/latest/develop/reference/eviction/&#34;&gt;Redis key eviction&lt;/a&gt;.&lt;/p&gt;&#xA;&lt;h2 id=&#34;caching-patterns&#34;&gt;Caching Patterns&lt;/h2&gt;&#xA;&lt;h3 id=&#34;cache-aside-lazy-loading&#34;&gt;Cache-Aside (Lazy Loading)&lt;/h3&gt;&#xA;&lt;p&gt;On a read, the application checks Redis first. A hit returns immediately. On a miss, it queries the database, stores the result in Redis, and returns it. The cache is filled only for requested data, which suits read-heavy workloads and keeps the cache smaller.&lt;/p&gt;&#xA;&lt;h3 id=&#34;read-through&#34;&gt;Read-Through&lt;/h3&gt;&#xA;&lt;p&gt;The application asks a cache provider for data. The provider performs a database read on a miss and manages filling the cache, so the application does not contain the miss-handling logic.&lt;/p&gt;</description>
    </item>
    <item>
      <title>JVM Basic</title>
      <link>https://ruokezhang.github.io/en/post/java/jvm/basic/</link>
      <pubDate>Thu, 30 Jan 2025 00:00:00 +0000</pubDate>
      <guid>https://ruokezhang.github.io/en/post/java/jvm/basic/</guid>
      <description>&lt;h2 id=&#34;classfile&#34;&gt;ClassFile&lt;/h2&gt;&#xA;&lt;p&gt;After a Java source file is compiled by javac, it becomes a .class bytecode file and then runs on the JVM. A ClassFile is a structured specification; all .class files must conform to this format.&#xA;&lt;img src=&#34;https://blog-ruoke.oss-cn-hongkong.aliyuncs.com/blog/images/classFile.png&#34; alt=&#34;Alt text&#34;&gt;&lt;/p&gt;&#xA;&lt;h3 id=&#34;basic-info&#34;&gt;Basic Info&lt;/h3&gt;&#xA;&lt;p&gt;&lt;img src=&#34;https://blog-ruoke.oss-cn-hongkong.aliyuncs.com/blog/images/general.png&#34; alt=&#34;Alt text&#34;&gt;&lt;/p&gt;&#xA;&lt;ol&gt;&#xA;&lt;li&gt;magic number: 0xCAFEBABE. Every .class must start with these 4 bytes.&lt;/li&gt;&#xA;&lt;li&gt;Version number, representing the compiler (javac) version.&lt;/li&gt;&#xA;&lt;li&gt;access flags&lt;/li&gt;&#xA;&lt;/ol&gt;&#xA;&lt;h3 id=&#34;constant-pool&#34;&gt;Constant Pool&lt;/h3&gt;&#xA;&lt;p&gt;&lt;img src=&#34;https://blog-ruoke.oss-cn-hongkong.aliyuncs.com/blog/images/constantPool.png&#34; alt=&#34;Alt text&#34;&gt;&#xA;There are 14 kinds of constants, grouped into literals and symbolic references. Literals are strings, final constants, etc. Symbolic references are things like method names and field names; they point to a string entry, i.e., a literal.&lt;/p&gt;</description>
    </item>
    <item>
      <title></title>
      <link>https://ruokezhang.github.io/en/post/leetcode/company_wise/</link>
      <pubDate>Mon, 01 Jan 0001 00:00:00 +0000</pubDate>
      <guid>https://ruokezhang.github.io/en/post/leetcode/company_wise/</guid>
      <description>&lt;h2 id=&#34;heap&#34;&gt;Heap&lt;/h2&gt;&#xA;&lt;ul&gt;&#xA;&lt;li&gt;&#xA;&lt;ol start=&#34;767&#34;&gt;&#xA;&lt;li&gt;Reorganize String (Roblox)&lt;/li&gt;&#xA;&lt;/ol&gt;&#xA;&lt;/li&gt;&#xA;&lt;li&gt;&#xA;&lt;ol start=&#34;621&#34;&gt;&#xA;&lt;li&gt;Task Scheduler (Roblox, Snowflake)&lt;/li&gt;&#xA;&lt;/ol&gt;&#xA;&lt;/li&gt;&#xA;&lt;li&gt;&#xA;&lt;ol start=&#34;692&#34;&gt;&#xA;&lt;li&gt;Top K Frequent Words (Adobe)&lt;/li&gt;&#xA;&lt;/ol&gt;&#xA;&lt;/li&gt;&#xA;&lt;li&gt;&#xA;&lt;ol start=&#34;347&#34;&gt;&#xA;&lt;li&gt;Top K Frequent Elements (Adobe, Bloomberg)&lt;/li&gt;&#xA;&lt;/ol&gt;&#xA;&lt;/li&gt;&#xA;&lt;li&gt;&#xA;&lt;ol start=&#34;1353&#34;&gt;&#xA;&lt;li&gt;Maximum Number of Events That Can Be Attended (Snowflake)&lt;/li&gt;&#xA;&lt;/ol&gt;&#xA;&lt;/li&gt;&#xA;&lt;li&gt;&#xA;&lt;ol start=&#34;373&#34;&gt;&#xA;&lt;li&gt;Find K Pairs with Smallest Sums (Linkedin, Google)&lt;/li&gt;&#xA;&lt;/ol&gt;&#xA;&lt;/li&gt;&#xA;&lt;li&gt;&#xA;&lt;ol start=&#34;1046&#34;&gt;&#xA;&lt;li&gt;Last Stone Weight (Nvidia)&lt;/li&gt;&#xA;&lt;/ol&gt;&#xA;&lt;/li&gt;&#xA;&lt;li&gt;&#xA;&lt;ol start=&#34;295&#34;&gt;&#xA;&lt;li&gt;Find Median from Data Stream (Snowflake)&lt;/li&gt;&#xA;&lt;/ol&gt;&#xA;&lt;/li&gt;&#xA;&lt;li&gt;Merge k Sorted Lists (Bloomberg, Snowflake, Nvidia, Microsoft)&lt;/li&gt;&#xA;&lt;li&gt;&#xA;&lt;ol start=&#34;2034&#34;&gt;&#xA;&lt;li&gt;Stock Price Fluctuation (Google)&lt;/li&gt;&#xA;&lt;/ol&gt;&#xA;&lt;/li&gt;&#xA;&lt;li&gt;&#xA;&lt;ol start=&#34;2402&#34;&gt;&#xA;&lt;li&gt;Meeting Rooms III&lt;/li&gt;&#xA;&lt;/ol&gt;&#xA;&lt;/li&gt;&#xA;&lt;/ul&gt;&#xA;&lt;h2 id=&#34;prefix-sum&#34;&gt;Prefix Sum&lt;/h2&gt;&#xA;&lt;ul&gt;&#xA;&lt;li&gt;&#xA;&lt;ol start=&#34;713&#34;&gt;&#xA;&lt;li&gt;Subarray Product Less Than K (Airbnb)&lt;/li&gt;&#xA;&lt;/ol&gt;&#xA;&lt;/li&gt;&#xA;&lt;li&gt;&#xA;&lt;ol start=&#34;1004&#34;&gt;&#xA;&lt;li&gt;Max Consecutive Ones III (Microsoft, Expedia)&lt;/li&gt;&#xA;&lt;/ol&gt;&#xA;&lt;/li&gt;&#xA;&lt;li&gt;&#xA;&lt;ol start=&#34;974&#34;&gt;&#xA;&lt;li&gt;Subarrays with K Different Integers (Expedia)&lt;/li&gt;&#xA;&lt;/ol&gt;&#xA;&lt;/li&gt;&#xA;&lt;li&gt;&#xA;&lt;ol start=&#34;304&#34;&gt;&#xA;&lt;li&gt;Range Sum Query 2D - Immutable (Snowflake)&lt;/li&gt;&#xA;&lt;/ol&gt;&#xA;&lt;/li&gt;&#xA;&lt;li&gt;Subarray Sum Equals K (Bloomberg)&lt;/li&gt;&#xA;&lt;li&gt;Product of Array Except Self (Bloomberg, Microsoft)&lt;/li&gt;&#xA;&lt;li&gt;Meeting Rooms II (Microsoft)&lt;/li&gt;&#xA;&lt;/ul&gt;&#xA;&lt;h2 id=&#34;trie&#34;&gt;Trie&lt;/h2&gt;&#xA;&lt;ul&gt;&#xA;&lt;li&gt;&#xA;&lt;ol start=&#34;211&#34;&gt;&#xA;&lt;li&gt;Add and Search Word - Data structure design (Docusign, LinkedIn, Snowflake, Rubrik, Tiktok)&lt;/li&gt;&#xA;&lt;/ol&gt;&#xA;&lt;/li&gt;&#xA;&lt;li&gt;&#xA;&lt;ol start=&#34;14&#34;&gt;&#xA;&lt;li&gt;Longest Common Prefix (Bloomberg)&lt;/li&gt;&#xA;&lt;/ol&gt;&#xA;&lt;/li&gt;&#xA;&lt;li&gt;&#xA;&lt;ol start=&#34;3043&#34;&gt;&#xA;&lt;li&gt;Find the Length of the Longest Common Prefix (Databricks)&lt;/li&gt;&#xA;&lt;/ol&gt;&#xA;&lt;/li&gt;&#xA;&lt;li&gt;Implement Trie (Prefix Tree) (Snowflake)&lt;/li&gt;&#xA;&lt;li&gt;&#xA;&lt;ol start=&#34;588&#34;&gt;&#xA;&lt;li&gt;Design In-Memory File System (Snowflake)&lt;/li&gt;&#xA;&lt;/ol&gt;&#xA;&lt;/li&gt;&#xA;&lt;li&gt;&#xA;&lt;ol start=&#34;1233&#34;&gt;&#xA;&lt;li&gt;Remove Sub-Folders (Snowflake, Google)&lt;/li&gt;&#xA;&lt;/ol&gt;&#xA;&lt;/li&gt;&#xA;&lt;li&gt;&#xA;&lt;ol start=&#34;1268&#34;&gt;&#xA;&lt;li&gt;Search Suggestions System (Docusign, Amazon)&lt;/li&gt;&#xA;&lt;/ol&gt;&#xA;&lt;/li&gt;&#xA;&lt;li&gt;&#xA;&lt;ol start=&#34;212&#34;&gt;&#xA;&lt;li&gt;Word Search II (Microsoft, Google, Airbnb)&lt;/li&gt;&#xA;&lt;/ol&gt;&#xA;&lt;/li&gt;&#xA;&lt;/ul&gt;&#xA;&lt;h2 id=&#34;stack&#34;&gt;Stack&lt;/h2&gt;&#xA;&lt;ul&gt;&#xA;&lt;li&gt;Basic Calculator II (Tesla)&lt;/li&gt;&#xA;&lt;li&gt;Max Stack (Linkedin)&lt;/li&gt;&#xA;&lt;li&gt;Nested List Weight Sum II (Linkedin)&lt;/li&gt;&#xA;&lt;li&gt;Valid Parentheses (Nvidia, Expedia)&lt;/li&gt;&#xA;&lt;li&gt;&#xA;&lt;ol start=&#34;150&#34;&gt;&#xA;&lt;li&gt;Evaluate Reverse Polish Notation (Microsoft)&lt;/li&gt;&#xA;&lt;/ol&gt;&#xA;&lt;/li&gt;&#xA;&lt;li&gt;&#xA;&lt;ol start=&#34;224&#34;&gt;&#xA;&lt;li&gt;Basic Calculator (Microsoft)&lt;/li&gt;&#xA;&lt;/ol&gt;&#xA;&lt;/li&gt;&#xA;&lt;li&gt;&#xA;&lt;ol start=&#34;20&#34;&gt;&#xA;&lt;li&gt;Valid Parentheses (Microsoft)&lt;/li&gt;&#xA;&lt;/ol&gt;&#xA;&lt;/li&gt;&#xA;&lt;li&gt;&#xA;&lt;ol start=&#34;32&#34;&gt;&#xA;&lt;li&gt;Longest Valid Parentheses (Tiktok)&lt;/li&gt;&#xA;&lt;/ol&gt;&#xA;&lt;/li&gt;&#xA;&lt;li&gt;&#xA;&lt;ol start=&#34;85&#34;&gt;&#xA;&lt;li&gt;Maximal Rectangle (Tiktok)&lt;/li&gt;&#xA;&lt;/ol&gt;&#xA;&lt;/li&gt;&#xA;&lt;li&gt;&#xA;&lt;ol start=&#34;84&#34;&gt;&#xA;&lt;li&gt;Largest Rectangle in Histogram (Microsoft)&lt;/li&gt;&#xA;&lt;/ol&gt;&#xA;&lt;/li&gt;&#xA;&lt;li&gt;&#xA;&lt;ol start=&#34;71&#34;&gt;&#xA;&lt;li&gt;Simplify Path (Snowflake, Tiktok)&lt;/li&gt;&#xA;&lt;/ol&gt;&#xA;&lt;/li&gt;&#xA;&lt;li&gt;&#xA;&lt;ol start=&#34;316&#34;&gt;&#xA;&lt;li&gt;Remove Duplicate Letters (Expedia)&lt;/li&gt;&#xA;&lt;/ol&gt;&#xA;&lt;/li&gt;&#xA;&lt;li&gt;&#xA;&lt;ol start=&#34;1944&#34;&gt;&#xA;&lt;li&gt;Number of Visible People in a Queue (Expedia)&lt;/li&gt;&#xA;&lt;/ol&gt;&#xA;&lt;/li&gt;&#xA;&lt;li&gt;&#xA;&lt;ol start=&#34;1963&#34;&gt;&#xA;&lt;li&gt;Minimum Number of Swaps to Make the String Balanced (Expedia)&lt;/li&gt;&#xA;&lt;/ol&gt;&#xA;&lt;/li&gt;&#xA;&lt;li&gt;&#xA;&lt;ol start=&#34;2104&#34;&gt;&#xA;&lt;li&gt;Sum of Subarray Ranges (Tiktok)&lt;/li&gt;&#xA;&lt;/ol&gt;&#xA;&lt;/li&gt;&#xA;&lt;/ul&gt;&#xA;&lt;h2 id=&#34;queue&#34;&gt;Queue&lt;/h2&gt;&#xA;&lt;ul&gt;&#xA;&lt;li&gt;&#xA;&lt;ol start=&#34;622&#34;&gt;&#xA;&lt;li&gt;Design Circular Queue (Tesla, Cloudflare)&lt;/li&gt;&#xA;&lt;/ol&gt;&#xA;&lt;/li&gt;&#xA;&lt;li&gt;&#xA;&lt;ol start=&#34;362&#34;&gt;&#xA;&lt;li&gt;Design Hit Counter (Snowflake, Cloudflare, Databricks)&lt;/li&gt;&#xA;&lt;/ol&gt;&#xA;&lt;/li&gt;&#xA;&lt;li&gt;&#xA;&lt;ol start=&#34;1438&#34;&gt;&#xA;&lt;li&gt;Longest Continuous Subarray With Absolute Diff Less Than or Equal to Limit (Google)&lt;/li&gt;&#xA;&lt;/ol&gt;&#xA;&lt;/li&gt;&#xA;&lt;/ul&gt;&#xA;&lt;h3 id=&#34;common-mistakes&#34;&gt;Common Mistakes&lt;/h3&gt;&#xA;&lt;ul&gt;&#xA;&lt;li&gt;&#xA;&lt;ol start=&#34;622&#34;&gt;&#xA;&lt;li&gt;Design Circular Queue (Tesla, Cloudflare)&lt;/li&gt;&#xA;&lt;/ol&gt;&#xA;&lt;/li&gt;&#xA;&lt;/ul&gt;&#xA;&lt;h2 id=&#34;hash&#34;&gt;Hash&lt;/h2&gt;&#xA;&lt;ul&gt;&#xA;&lt;li&gt;&#xA;&lt;ol start=&#34;41&#34;&gt;&#xA;&lt;li&gt;First Missing Positive (Tesla)&lt;/li&gt;&#xA;&lt;/ol&gt;&#xA;&lt;/li&gt;&#xA;&lt;li&gt;&#xA;&lt;ol start=&#34;268&#34;&gt;&#xA;&lt;li&gt;Missing Number (Meta, Microsoft, Bloomberg)&lt;/li&gt;&#xA;&lt;/ol&gt;&#xA;&lt;/li&gt;&#xA;&lt;/ul&gt;&#xA;&lt;h2 id=&#34;sort&#34;&gt;Sort&lt;/h2&gt;&#xA;&lt;ul&gt;&#xA;&lt;li&gt;&#xA;&lt;ol start=&#34;215&#34;&gt;&#xA;&lt;li&gt;Kth Largest Element in an Array (Microsoft)&lt;/li&gt;&#xA;&lt;/ol&gt;&#xA;&lt;/li&gt;&#xA;&lt;/ul&gt;&#xA;&lt;h2 id=&#34;sliding-window&#34;&gt;Sliding Window&lt;/h2&gt;&#xA;&lt;ul&gt;&#xA;&lt;li&gt;&#xA;&lt;ol start=&#34;1004&#34;&gt;&#xA;&lt;li&gt;Max Consecutive Ones III (SAP, Salesforce, LinkedIn, Meta, Google)&lt;/li&gt;&#xA;&lt;/ol&gt;&#xA;&lt;/li&gt;&#xA;&lt;li&gt;&#xA;&lt;ol start=&#34;424&#34;&gt;&#xA;&lt;li&gt;Longest Repeating Character Replacement (Adobe, Amazon, Bytedance, Bloomberg)&lt;/li&gt;&#xA;&lt;/ol&gt;&#xA;&lt;/li&gt;&#xA;&lt;li&gt;&#xA;&lt;ol start=&#34;1297&#34;&gt;&#xA;&lt;li&gt;Maximum Number of Occurrences of a Substring (Hubspot, Salesforce)&lt;/li&gt;&#xA;&lt;/ol&gt;&#xA;&lt;/li&gt;&#xA;&lt;li&gt;&#xA;&lt;ol start=&#34;159&#34;&gt;&#xA;&lt;li&gt;Longest Substring with At Most Two Distinct Characters (Ebay, Google, Tiktok)&lt;/li&gt;&#xA;&lt;/ol&gt;&#xA;&lt;/li&gt;&#xA;&lt;li&gt;&#xA;&lt;ol start=&#34;340&#34;&gt;&#xA;&lt;li&gt;Longest Substring with At Most K Distinct Characters (Microsoft)&lt;/li&gt;&#xA;&lt;/ol&gt;&#xA;&lt;/li&gt;&#xA;&lt;li&gt;&#xA;&lt;ol start=&#34;713&#34;&gt;&#xA;&lt;li&gt;Subarray Product Less Than K (Paypal, Oracle, Salesforce)&lt;/li&gt;&#xA;&lt;/ol&gt;&#xA;&lt;/li&gt;&#xA;&lt;li&gt;&#xA;&lt;ol start=&#34;632&#34;&gt;&#xA;&lt;li&gt;Smallest Range Covering Elements from K Lists (Lyft, Databricks)&lt;/li&gt;&#xA;&lt;/ol&gt;&#xA;&lt;/li&gt;&#xA;&lt;li&gt;&#xA;&lt;ol start=&#34;1343&#34;&gt;&#xA;&lt;li&gt;Number of Subarrays of Size K and Average Greater than or Equal to Threshold (LinkedIn)&lt;/li&gt;&#xA;&lt;/ol&gt;&#xA;&lt;/li&gt;&#xA;&lt;/ul&gt;</description>
    </item>
  </channel>
</rss>
