logo Mr.Robota 具身智能学习手册 中文
Chapter 12: 12 Interview Questions

I. Research Methodology and Engineering Practice

In technical interviews, the evaluation of papers and projects usually focuses on logical closed loop and engineering implementation.

1. Key Points for Deep Analysis of the Paper

  • Research Motivation: Clearly state why this approach is chosen. For example, in action generation policies, single-step generation has a latency advantage over autoregressive in real-time control.
  • Ablation Study: Verify the effectiveness of each module.
  • Safety and Robustness: Such as the defense mechanisms and data construction of the VLA (Visual-Language-Action) model against adversarial attacks (e.g., Backdoor attacks).
  • Preparation for Academic Critiques: Practice responses regarding Baseline selection, generalization boundaries, and Sim-to-Real loss.

2. LLM and Embodied Systems Engineering

  • Computing power optimization: Address memory constraints and parallel sampling efficiency issues when deploying in a simulation platform (such as Isaac Lab/Gym).
  • Feature extraction: Conduct feature analysis using methods like sparse autoencoders (SAE).
  • Inference optimization: Introduce an inference-time search mechanism to mitigate instruction drift caused by the generation of long model sequences.

II. Core Theoretical Knowledge Base

1. Transformer Architecture

  • Self-Attention mechanism:

    Attention(Q,K,V)=softmax(QKTdk)V\text{Attention}(Q, K, V) = \text{softmax}\left(\frac{QK^T}{\sqrt{d_k}}\right)V
  • The role of dkd_k scaling factor: It prevents the dot product result from being too large, which could cause Softmax to enter the saturated region of gradient vanishing.

  • Rotation Position Encoding (RoPE):

Achieve relative positions through rotation at absolute positions. The two-dimensional rotation manipulation is as follows:

fq(xm,m)=(cos⁡(mθ)−sin⁡(mθ)sin⁡(mθ)cos⁡(mθ))(q0q1)f_q(x_m, m) = \begin{pmatrix} \cos(m\theta) & -\sin(m\theta) \\ \sin(m\theta) & \cos(m\theta) \end{pmatrix} \begin{pmatrix} q_0 \\ q_1 \end{pmatrix}

2. Embodied AI and Robot Control

  • Contact force model (impedance control):

    Fcontact=Kp(xref−x)+Kd(x˙ref−x˙)F_{contact} = K_p (x_{ref} - x) + K_d (\dot{x}_{ref} - \dot{x})
  • Kp,KdK_p, K_d represent stiffness and damping coefficients, respectively. In multimodal models, tactile signals are often processed as embeddings that align with visual and auditory features.

  • Policy Gradient Theorem:

    ∇θJ(θ)=Eπθ[∑t=0T∇θlog⁡πθ(at∣st)R(τ)]\nabla_\theta J(\theta) = \mathbb{E}_{\pi_\theta} \left[ \sum_{t=0}^T \nabla_\theta \log \pi_\theta(a_t|s_t) R(\tau) \right]

3. Generation Model: Flow Matching

The goal is to recover the optimal transmission vector field utu_t from the noise p0p_0 to the data p1p_1:

  • Linear path: xt=tx1+(1−t)x0x_t = t x_1 + (1 - t) x_0
  • Target vector field: ut(xt∣x1)=x1−x0u_t(x_t | x_1) = x_1 - x_0
  • Loss function: L(θ)=Et,x0,x1[∣∣vθ(xt,t)−ut(xt∣x1)∣∣2]\mathcal{L}(\theta) = \mathbb{E}_{t, x_0, x_1} [ || v_\theta(x_t, t) - u_t(x_t | x_1) ||^2 ]

III. Technical Interview Code-Shattering Set

1. Core components of deep learning

Multi-Head Attention (with causal mask and temperature coefficient)

Pythonimport torch
import torch.nn as nn
import math

class CausalTemperatureMHA(nn.Module):
    def __init__(self, d_model: int, num_heads: int):
        super().__init__()
        self.num_heads = num_heads
        self.d_k = d_model // num_heads
        self.W_q = nn.Linear(d_model, d_model)
        self.W_k = nn.Linear(d_model, d_model)
        self.W_v = nn.Linear(d_model, d_model)
        self.W_o = nn.Linear(d_model, d_model)

    def forward(self, x, mask=None, temperature=1.0):
        batch_size, seq_len, _ = x.size()

        # 投影并分头
        Q = self.W_q(x).view(batch_size, seq_len, self.num_heads, self.d_k).transpose(1, 2)
        K = self.W_k(x).view(batch_size, seq_len, self.num_heads, self.d_k).transpose(1, 2)
        V = self.W_v(x).view(batch_size, seq_len, self.num_heads, self.d_k).transpose(1, 2)

        # 缩放点积注意力 + 温度系数
        scores = torch.matmul(Q, K.transpose(-2, -1)) / (temperature * math.sqrt(self.d_k))

        # 因果掩码 (Causal Mask)
        causal_mask = torch.triu(torch.ones(seq_len, seq_len, device=x.device), diagonal=1).bool()
        scores = scores.masked_fill(causal_mask, float('-inf'))

        attn = torch.softmax(scores, dim=-1)
        out = torch.matmul(attn, V).transpose(1, 2).contiguous().view(batch_size, seq_len, -1)
        return self.W_o(out)

LayerNorm Implementation

Pythonclass LayerNorm(nn.Module):
    def __init__(self, shape, eps=1e-5):
        super().__init__()
        self.gamma = nn.Parameter(torch.ones(shape))
        self.beta = nn.Parameter(torch.zeros(shape))
        self.eps = eps

    def forward(self, x):
        mean = x.mean(dim=-1, keepdim=True)
        var = x.var(dim=-1, unbiased=False, keepdim=True)
        return self.gamma * (x - mean) / torch.sqrt(var + self.eps) + self.beta

2. Algorithm and Mathematics Problem Questions

Binary Search for Square Root (Real Domain)

Pythondef mySqrt(x: float, epsilon: float = 1e-7) -> float:
    if x < 0: return None
    left, right = 0.0, max(x, 1.0)
    while right - left > epsilon:
        mid = (left + right) / 2
        if mid * mid > x:
            right = mid
        else:
            left = mid
    return left

Double Pointers: Collecting Rainwater

1. Background and Objectives of the Topic

Problem Description:

Given a non-negative integer array height, where each element represents the height of the pillar at that position, and the width of each pillar is 1, calculate how much water can be collected between these pillars after it rains.


2. Core Physical Principle: Barrel Effect (Shortest Plank Theory)

To determine how much water can be stored at a specific location i, it depends on the highest pillar on the left side and the highest pillar on the right side.

  • Calculation formula: The water volume at this position = min⁡(左边最高,右边最高)−当前高度\min(\text{左边最高}, \text{右边最高}) - \text{当前高度}.
  • Intuitive understanding: Water flows to a lower level, but the amount it can be stored depends on the “shorter” side of the baffles (i.e., the barrel effect).

3. Line-by-line analysis of code logic

The code you provided uses the double pointer method with optimal space complexity:

Python

def trap(height: list[int]) -> int:
    # 1. 初始化
    left, right = 0, len(height) - 1  # 左右指针分别指向数组两端
    l_max, r_max = 0, 0              # 记录左侧和右侧遍历过程中的最大高度
    res = 0                          # 总体积

    # 2. 循环遍历
    while left < right:
        # 更新左右侧已知的最大高度
        l_max = max(l_max, height[left])
        r_max = max(r_max, height[right])

        # 3. 核心决策:哪边矮就处理哪边
        if l_max < r_max:
            # 如果左边最大值更小,说明左边是“短板”
            # 此时 height[left] 处的蓄水量完全由 l_max 决定
            res += l_max - height[left]
            left += 1
        else:
            # 如果右边最大值更小或相等,右边是“短板”
            res += r_max - height[right]
            right -= 1

    return res

Why is this logic correct?

When you find l_max < r_max, although you may not know whether there is a pillar higher than r_max on the right side of left pointer, you have determined that for the current left position, the upper limit of water it can hold must be l_max. Therefore, you can confidently calculate the water volume at that point and move the pointer.


4. Complexity Analysis

  • Time complexity: O(n)O(n)
    • Only one pass through the array is required, and the left and right pointers move towards the center.
  • Space complexity: O(1)O(1)
    • Only constant-level additional variables (l_max, r_max, res, etc.) are used; no additional array storage is required.

5. Common Interview Questions

  1. Dynamic programming solution: If double pointers are not used, can space be traded for time? (The left_max and right_max arrays can be preprocessed first, making the space complexity become O(n)O(n)).
  2. Monotonic stack solution: How to use a stack to solve this problem? (By maintaining a stack with decreasing height, the water volume is calculated layer by layer).
  3. Practical applications: In computer vision or robotics, this logic of “finding local extreme gaps” is often used to analyze the uneven terrain in LiDAR point cloud data.
Pythondef trap(height: list[int]) -> int:
    left, right = 0, len(height) - 1
    l_max, r_max = 0, 0
    res = 0
    while left < right:
        l_max = max(l_max, height[left])
        r_max = max(r_max, height[right])
        if l_max < r_max:
            res += l_max - height[left]
            left += 1
        else:
            res += r_max - height[right]
            right -= 1
    return res

Let’s take the array height = [4, 2, 0, 3, 2, 5] as an example for step-by-step breakdown.

1. Preparation of the simulation environment

  • Initial state:
    • left = 0 (pointing to height 4), right = 5 (pointing to height 5)
    • l_max = 0, r_max = 0, res = 0

2. Step-by-step execution process

The algorithm moves the left and right pointers to always process the “short side” to ensure accurate calculation of the water storage.

Step Pointer Position Current Height (h[l], h[r]) Updated Maximum (l_max, r_max) Condition Check and Calculation Cumulative Water Volume (res) Next Step
1 l=0, r=5 4, 5 l_max=4, r_max=5 l_max < r_max (4 < 5) is true.res += 4 - 4 = 0 0 left++
2 l=1, r=5 2, 5 l_max=4, r_max=5 l_max < r_max (4 < 5) is true.res += 4 - 2 = 2 2 left++
3 l=2, r=5 0, 5 l_max=4, r_max=5 l_max < r_max (4 < 5) is true.res += 4 - 0 = 4 6 left++
4 l=3, r=5 3, 5 l_max=4, r_max=5 l_max < r_max (4 < 5) is true.res += 4 - 3 = 1 7 left++
5 l=4, r=5 2, 5 l_max=4, r_max=5 l_max < r_max (4 < 5) is true.res += 4 - 2 = 2 9 left++
End l=5, r=5 - - The loop condition left < right is no longer satisfied 9 -

3. Summary of Calculation Results

In this example, the actual water storage at each index position is as follows:

  • Index 1: min⁡(4,5)−2=2\min(4, 5) - 2 = 2
  • Index 2: min⁡(4,5)−0=4\min(4, 5) - 0 = 4
  • Index 3: min⁡(4,5)−3=1\min(4, 5) - 3 = 1
  • Index 4: min⁡(4,5)−2=2\min(4, 5) - 2 = 2

Final total water storage is:

∑water=2+4+1+2=9\sum \text{water} = 2 + 4 + 1 + 2 = 9

Key tips:

When l_max < r_max is present, we** don’t need to know** how many columns exist between left and right. Since r_max is already larger than l_max, the amount of water that can be stored at left depends entirely on the barrier l_max on its left side.