swadhinbiswas feat: add Netflix L5 interview playbook · 2/2/2026
41c1cbb
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
/**
* LeetCode Database Client
*
* This module provides functions to query the LeetCode problems database.
* It can work with either:
* - Turso (remote) if TURSO_DATABASE_URL is set
* - Local SQLite file as fallback
*/
import { createClient, type Client } from "@libsql/client";
let dbClient: Client | null = null;
export function getDbClient(): Client {
if (!dbClient) {
// Check for Turso credentials in environment
const tursoUrl =
import.meta.env.TURSO_DATABASE_URL || process.env.TURSO_DATABASE_URL;
const tursoToken =
import.meta.env.TURSO_AUTH_TOKEN || process.env.TURSO_AUTH_TOKEN;
if (tursoUrl && tursoToken) {
// Use Turso remote database
dbClient = createClient({
url: tursoUrl,
authToken: tursoToken,
});
} else {
// Use local file database
dbClient = createClient({
url: "file:./data/leetcode.db",
});
}
}
return dbClient;
}
export interface Problem {
id: number;
title: string;
url: string;
difficulty: "Easy" | "Medium" | "Hard";
acceptance?: string;
frequency?: number;
}
export interface Company {
id: number;
name: string;
displayName: string;
totalProblems?: number;
timeframes?: string[];
}
export interface CompanyProblems {
company: Company;
problems: Problem[];
timeframe: string;
}
// Get all companies
export async function getAllCompanies(): Promise<Company[]> {
const db = getDbClient();
const result = await db.execute(`
SELECT
c.id,
c.name,
c.display_name as displayName,
COUNT(DISTINCT cp.problem_id) as totalProblems
FROM companies c
LEFT JOIN company_problems cp ON c.id = cp.company_id
GROUP BY c.id
ORDER BY totalProblems DESC
`);
return result.rows.map((row) => ({
id: row.id as number,
name: row.name as string,
displayName: row.displayName as string,
totalProblems: row.totalProblems as number,
}));
}
// Get problems for a specific company and timeframe
export async function getCompanyProblems(
companyName: string,
timeframe: string = "alltime",
): Promise<CompanyProblems | null> {
const db = getDbClient();
// Get company info
const companyResult = await db.execute({
sql: `SELECT id, name, display_name as displayName FROM companies WHERE name = ?`,
args: [companyName],
});
if (companyResult.rows.length === 0) {
return null;
}
const company = companyResult.rows[0] as unknown as Company;
// Get problems for this company and timeframe
const problemsResult = await db.execute({
sql: `
SELECT
p.id,
p.title,
p.url,
p.difficulty,
cp.acceptance,
cp.frequency
FROM problems p
JOIN company_problems cp ON p.id = cp.problem_id
JOIN companies c ON cp.company_id = c.id
WHERE c.name = ? AND cp.timeframe = ?
ORDER BY cp.frequency DESC
`,
args: [companyName, timeframe],
});
const problems: Problem[] = problemsResult.rows.map((row) => ({
id: row.id as number,
title: row.title as string,
url: row.url as string,
difficulty: row.difficulty as "Easy" | "Medium" | "Hard",
acceptance: row.acceptance as string,
frequency: row.frequency as number,
}));
return {
company,
problems,
timeframe,
};
}
// Get available timeframes for a company
export async function getCompanyTimeframes(
companyName: string,
): Promise<string[]> {
const db = getDbClient();
const result = await db.execute({
sql: `
SELECT DISTINCT cp.timeframe
FROM company_problems cp
JOIN companies c ON cp.company_id = c.id
WHERE c.name = ?
ORDER BY
CASE cp.timeframe
WHEN '6months' THEN 1
WHEN '1year' THEN 2
WHEN '2year' THEN 3
WHEN 'alltime' THEN 4
ELSE 5
END
`,
args: [companyName],
});
return result.rows.map((row) => row.timeframe as string);
}
// Search problems by title
export async function searchProblems(
query: string,
limit: number = 50,
): Promise<Problem[]> {
const db = getDbClient();
const result = await db.execute({
sql: `
SELECT DISTINCT id, title, url, difficulty
FROM problems
WHERE title LIKE ?
ORDER BY title
LIMIT ?
`,
args: [`%${query}%`, limit],
});
return result.rows.map((row) => ({
id: row.id as number,
title: row.title as string,
url: row.url as string,
difficulty: row.difficulty as "Easy" | "Medium" | "Hard",
}));
}
// Get problem statistics
export async function getStats(): Promise<{
totalCompanies: number;
totalProblems: number;
byDifficulty: Record<string, number>;
}> {
const db = getDbClient();
const companiesResult = await db.execute(
`SELECT COUNT(*) as count FROM companies`,
);
const problemsResult = await db.execute(
`SELECT COUNT(*) as count FROM problems`,
);
const difficultyResult = await db.execute(`
SELECT difficulty, COUNT(*) as count
FROM problems
GROUP BY difficulty
`);
return {
totalCompanies: companiesResult.rows[0]?.count as number,
totalProblems: problemsResult.rows[0]?.count as number,
byDifficulty: Object.fromEntries(
difficultyResult.rows.map((row) => [
row.difficulty as string,
row.count as number,
]),
),
};
}
// Get top FAANG companies
export async function getFAANGCompanies(): Promise<Company[]> {
const db = getDbClient();
const faangNames = [
"google",
"amazon",
"apple",
"meta",
"facebook",
"netflix",
"microsoft",
];
const result = await db.execute(`
SELECT
c.id,
c.name,
c.display_name as displayName,
COUNT(DISTINCT cp.problem_id) as totalProblems
FROM companies c
LEFT JOIN company_problems cp ON c.id = cp.company_id
WHERE c.name IN (${faangNames.map(() => "?").join(",")})
GROUP BY c.id
ORDER BY totalProblems DESC
`);
return result.rows.map((row) => ({
id: row.id as number,
name: row.name as string,
displayName: row.displayName as string,
totalProblems: row.totalProblems as number,
}));
}