bytedance-frontend-eg-camp-en

Multiple choice plus coding—jotting down the main topics.

Multiple choice

Mostly data structures & algorithms, computer networks, and HTML/CSS/JS basics.

Data structures & algorithms

Felt like a freshman/sophomore DS&A exam…

Several sorting questions—bubble, quicksort, etc.

One very easy complexity question.

Two or three binary tree traversal questions.

One stack question.

Computer networks

Which transport-layer protocol is unreliable?

UDP.

A DNS message question

I only remember option A: QR=0 means query, QR=1 means response.

HTML, CSS, JS

How to normalize margin/padding across browsers?

CSS reset:

* {
  margin: 0;
  padding: 0;
}

There’s also Normalize.css—I should study that.

A CSS float question asking which usage is wrong

Options included
A. float: **
B. float: none
C. float: left
D. float: right

Pick A.

How to fix parent height collapse after floats

I forgot the exact options. Common fixes:

  1. ::after clearfix.
  2. Modern: display: flow-root.
  3. BFC via overflow—but overflow: hidden hides intentional overflow (dropdowns, shadows, tooltips).

Which option is a BFC application?

BFC (block formatting context)—applications:

  1. Contain floats (classic): parent has floated children → collapse; give the parent overflow: hidden or display: flow-root.
  2. Stop vertical margin collapse between adjacent blocks: wrap in a new parent that establishes a BFC.
  3. Two/three-column layouts: e.g. left float: left (fixed width), right column BFC (overflow: hidden / flow-root) fills the rest.

Interview variants: “which property can establish a BFC?”

  • overflow: hidden / auto / scroll
  • display: flow-root
  • float: left / right
  • position: absolute / fixed
  • display: inline-block
  • display: table-cell
  • flex/grid items

When you see overflow: hidden or flow-root fixing collapse, margins, or columns—that’s BFC.

requestAnimationFrame in JS

Skimmed the red book—still fuzzy; revisit later.

setTimeout vs Promise.then() ordering

JS schedules three kinds of work:

  • Synchronous: runs on the call stack immediately.
  • Microtasks: after current sync code, before the next macrotask—Promise.then() / .catch() callbacks.
  • Macrotasks: after sync + all microtasks, one at a time—setTimeout / setInterval callbacks.
console.log('1. sync: start');

setTimeout(() => {
  console.log('2. macro: setTimeout 1');
}, 0);

new Promise((resolve, reject) => {
  console.log('3. sync: Promise executor');

  setTimeout(() => {
    console.log('4. macro: setTimeout 2 (inside Promise)');
    resolve();
  }, 0);

}).then(() => {
  console.log('5. micro: Promise.then 1');
});

Promise.resolve().then(() => {
  console.log('6. micro: Promise.then 2');
});

console.log('7. sync: end');
  1. Log 1.
  2. Schedule macrotask setTimeout 1.
  3. Run Promise executor synchronously → log 3.
  4. Schedule macrotask setTimeout 2.
  5. Promise.resolve().then → enqueue microtask.
  6. Log 7.
  7. Drain microtasks → 6.
  8. Run first macrotask → … and so on through 4, microtasks, etc.

Coding

ACM-style I/O is still unfamiliar—need more NowCoder practice.

Given equations with parameters A, B, C, count real solutions to
X² + A²Y² + C = 0
Y² + Z² + B = 0
Z² + A = 0

Feels like pure math—solve and case-split.

Among k-digit integers, how many have digit-sum m?
e.g. k=2, m=3 → 12, 21, 30.

import functools

def solve_digit_sum(k:int,m:int)->int:
	@functools.lru_cache(None)
	def count_sequences(digits:int,target_sum:int)->int:
		if target_sum < 0:
			return 0
			
		if target_sum > 9*digits:
			return 0
			
		if digits == 0:
			return 1 if target_sum==0 else 0
			
		total_ways = 0
		for d in range(10):
			total_ways += count_sequences(digits - 1,target_sum - d)
		
		return total_ways
		
		
	if k<=0:
		return 0
		
	final_count = 0
	
	for d1 in range(1,10):
		final_count += count_sequences(k-1,m-d1)
		
	return final_count

Another problem (paraphrased): define “cost” of a simple path as the maximum edge weight on that path. In a connected undirected weighted simple graph, count ordered pairs (u, v) whose minimum such cost equals k. Felt too hard for now—I’ll park it.