Mock 09 — Runtime / Language Deep Dive

Interview type: Mid-coding language/runtime probe (Bloomberg, Stripe, hedge funds, infra-heavy teams) Target role: Senior / Staff backend or systems Time limit: 45 minutes Format: ONE medium problem, interrupted by language/runtime probes during/after coding Hints policy: Hints on the probes are -1 each; on the algorithm, standard. Primary goal: Demonstrate that you understand your language at a level deeper than syntax.


What This Mock Tests

Some companies will deliberately interrupt your coding with “what does this line cost?” or “what happens if two threads call this concurrently?” or “where does this object get allocated?” The signal: senior engineers don’t just write code; they know what the runtime does with it.

Scoring weights: Language/Runtime (#12) is doubled. Other dimensions normal.

Pick a language you claim to know well. The probes are language-specific.


Pick One Problem (any language)

Problem A — Implement a Concurrent Counter

Build a thread-safe counter with incr(), decr(), read(). Discuss the tradeoffs of locking vs atomic vs sharded.

Problem B — Producer-Consumer Queue

Implement a bounded blocking queue: put(item) blocks if full; get() blocks if empty.

Problem C — Implement flatten(nested_list) Lazily

Given an arbitrarily nested list (e.g., [1, [2, [3, 4]], 5, [[6]]]), return an iterator yielding flat elements lazily (constant memory).


Probes by Language (interviewer fires these mid-coding)

Python

  • “What does list.append(x) cost? When does it resize?”
  • “How does Python implement dict? What’s the lookup cost in the worst case?”
  • “What happens to your concurrent counter under the GIL? Is += atomic?”
  • “What’s reference counting? When does the cyclic GC run?”
  • “What does with lock: desugar to?”
  • “Why is multiprocessing different from threading? When would you use which?”
  • “Difference between asyncio.sleep(0) and time.sleep(0)?”
  • “What’s an __slots__ and when does it matter?”
  • “Generators vs iterators vs async iterators — implement flatten as each.”
  • “Where does the GIL hurt your code most?”

Java

  • “What’s the difference between volatile int and AtomicInteger?”
  • “Explain the Java Memory Model — happens-before relationship.”
  • “When does synchronized use biased locking / thin lock / fat lock?”
  • “What does String s = a + b; compile to?”
  • “How does HashMap resize? What’s the cost?”
  • “Difference between G1, ZGC, Shenandoah?”
  • “What’s a MethodHandle?”
  • “When does escape analysis kick in?”
  • “What’s Unsafe, why does it exist?”
  • “Implement the queue using ReentrantLock vs synchronized — what differs?”

Go

  • “What does a goroutine cost (stack, scheduler)?”
  • “Explain GMP — goroutines, M (OS thread), P (processor).”
  • “How does select work under the hood?”
  • “What’s escape analysis? Show me an example of stack vs heap allocation.”
  • “Difference between sync.Mutex and sync.RWMutex?”
  • “What’s the cost of channels? When to prefer mutex?”
  • “Explain Go’s GC — what generation? What pause time?”
  • “What does defer cost?”
  • “Implement the bounded queue using channels vs using a mutex — which and why?”

C++

  • “Explain RAII.”
  • “What’s the difference between std::atomic<int> and std::mutex-protected int?”
  • “Memory orders: relaxed, acquire, release, acq_rel, seq_cst — when to use which?”
  • “What does std::vector::push_back cost? Amortized vs worst-case?”
  • “Move semantics — when is the move constructor called?”
  • “Difference between std::shared_ptr and std::unique_ptr?”
  • “What’s std::launder?”
  • “Implement the bounded queue using std::condition_variable.”
  • “What’s the cost of a virtual call?”

Rust

  • “Borrow checker rules — one mutable XOR many immutable references.”
  • “When do you need Arc<Mutex<T>> vs Rc<RefCell<T>>?”
  • “Explain Send and Sync traits.”
  • “What does async fn desugar to?”
  • “Difference between tokio::spawn and tokio::task::spawn_blocking?”
  • “What’s a Pin<T>? Why does it exist?”
  • “When does lifetime elision apply?”
  • “Implement the bounded queue using tokio::sync::mpsc.”

Node.js / JavaScript

  • “Explain the event loop — phases, microtasks vs macrotasks.”
  • “What’s the difference between process.nextTick and setImmediate?”
  • “When is a Promise resolved synchronously vs asynchronously?”
  • “What’s V8’s hidden class / inline cache?”
  • “Why does obj.x = 1 after obj.y = 2 behave differently than the reverse order in terms of perf?”
  • “What’s a WeakRef? When is the value collected?”
  • “Implement the queue using async / await.”

Expected Communication Style

  1. Restate problem.
  2. Ask clarifying questions (including language-specific ones — “should read() return a snapshot or be consistent with concurrent updates?”).
  3. Code the algorithm.
  4. Engage with probes as they come. Don’t say “I’ll come back to that.” Pause coding, answer, resume.
  5. After coding, walk through tests.
  6. End with a senior-level reflection on what could change with different runtime characteristics (“if we moved this to Go, the channel-based design would replace the lock-based one”).

Common Failure Modes

  1. Memorized the algorithm but didn’t know how the language implements its data structures.
  2. “I don’t know” to a basic probe. A senior should know how the language’s main collections perform.
  3. Implemented the concurrent counter with int and += in Python, thinking GIL makes it safe. GIL ensures bytecode atomicity but x += 1 is read-modify-write across bytecodes. Use threading.Lock or Atomic* types.
  4. In Java, used ++ on volatile int thinking it’s atomic. It’s not — volatile ensures visibility but not atomicity.
  5. In Go, used a channel for a single shared counter. Slower than sync/atomic.AddInt64; mismatched tool.

Passing Bar

  • Total score: 53/70 (average 3.8)
  • Language/Runtime (#12): ≥ 4 (mandatory)
  • Algorithm: correct and at expected complexity
  • Answered ≥ 4 of 5–6 probes substantively
  • Code idiomatic for the language

Follow-up Questions (post-coding)

  • “Now port your solution to [other language]. What changes?”
  • “Profile this in production — what tool, what metrics?”
  • “Where would you put the metric instrumentation?”
  • “If this is the hot path of a service handling 1M qps, what’s the bottleneck?”

Required Tests

  • Algorithm correctness (basic)
  • Concurrent stress test (≥ 4 threads/goroutines, hammering)
  • Boundary timing (empty queue blocks; full queue blocks; producer wakes consumer)
  • Resource cleanup / shutdown semantics

Required Runtime Discussion

State, for your solution:

  • What allocations occur per operation (heap vs stack)
  • Lock granularity and contention behavior
  • GC implications (Python ref count, Java GC pause, Go STW, etc.)
  • What the worst-case latency is and why

Self-Evaluation Template

Mock 09 — Runtime / Language
Date: _______
Language: _______
Problem: _______
Time: ___ / 45 min

Scores (1–5):
___ Total /70

Language/Runtime (#12): ___ (need ≥ 4)
Probes asked: ___
Probes answered well: ___

Probes I bombed (write each verbatim, drill before next mock):
1.
2.
3.

Action item:

What to Do If You Fail

  • Probe score below 4: Spend the next week with Phase 9 — your language directory. Read the language’s runtime/perf docs cover to cover.
  • Couldn’t answer 50% of probes: You don’t know the language as well as you claim. Pick a different language to claim, OR invest 2+ weeks.
  • Pass twice consecutively before Mock 10.