Design client-side logic for a live streaming application with adaptive quality control.
Available APIs:
// Manifest API
interface QualityLevel {
bitrate: number;
resolution: string;
segments: string[];
}
getManifest(): Promise<QualityLevel[]>
// Video Segment API
interface Segment {
data: Uint8Array;
duration: number;
}
fetchSegment(url: string): Promise<Segment>
// Player Control API
interface Player {
play(): void;
seek(time: number): void;
switchQuality(level: QualityLevel): void;
}
Requirements:
Design and implement the classic Snake game with path-finding optimization.
Game Components:
interface Position {
x: number;
y: number;
}
interface GameState {
board: number[][];
snake: Position[];
apple: Position;
score: number;
direction: Direction;
}
enum Direction {
UP,
DOWN,
LEFT,
RIGHT
}
Requirements:
Follow-up: Path Finding
interface PathFinder {
findOptimalPath(
snake: Position[],
apple: Position,
board: number[][]
): Direction[];
}
Optimization Considerations:
Implement a text editor backend with cursor and selection management.
Core Data Structures:
interface Cursor {
position: number;
selection: Selection | null;
}
interface Selection {
start: number;
end: number;
}
interface TextEditor {
// Core Operations
insert(text: string): void;
delete(): void;
select(start: number, end: number): void;
copy(): string;
paste(): void;
// State Management
getCursor(): Cursor;
getText(): string;
}
Operation Requirements:
- Insert at cursor position
- Replace selected text if selection exists
- Update cursor position after insert
- Delete selected text if selection exists
- Delete character before cursor if no selection
- Update cursor and selection state
- Set selection range
- Clear selection
- Validate selection bounds
- Handle cursor updates
- Copy selected text
- Handle empty selection
- Paste at cursor position
- Replace selected text on paste
Implementation Considerations: