-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathserver.js
More file actions
240 lines (219 loc) · 7.4 KB
/
Copy pathserver.js
File metadata and controls
240 lines (219 loc) · 7.4 KB
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
// server.js
// Backend for LockedInterview – returns questions from in-memory banks (no scraping)
const express = require("express");
const cors = require("cors");
const path = require("path");
const app = express();
const PORT = process.env.PORT || 3000;
app.use(cors());
app.use(express.json());
// Serve your frontend.html (and any other static files) from this folder
app.use(express.static(__dirname));
/* ------------------------------------------------------------------ */
/* QUESTION BANKS */
/* ------------------------------------------------------------------ */
// Behavioral – generic for any role
const BEHAVIORAL_GENERIC = [
{
text: "Tell me about a time you disagreed with a teammate and how you resolved it.",
tags: ["Behavioral", "Conflict"],
},
{
text: "Describe a project you’re most proud of. What was your role and what was the outcome?",
tags: ["Behavioral", "Ownership"],
},
{
text: "Tell me about a time you had to learn something quickly to succeed.",
tags: ["Behavioral", "Learning"],
},
{
text: "Walk me through a time when you made a mistake at work or school. What did you do afterwards?",
tags: ["Behavioral", "Failure"],
},
{
text: "Give an example of working under a tight deadline. How did you manage priorities?",
tags: ["Behavioral", "Pressure"],
},
{
text: "Tell me about a time you had to influence someone without direct authority.",
tags: ["Behavioral", "Influence"],
},
{
text: "Describe a time you received tough feedback. How did you respond?",
tags: ["Behavioral", "Feedback"],
},
{
text: "Tell me about a situation where you had to deal with ambiguity.",
tags: ["Behavioral", "Ambiguity"],
},
];
// Technical – SWE / FAANG-ish, Intern / Junior flavor
const TECH_SWE_FAANG_INTERN = [
{
text:
"Given an array of integers and a target value, return indices of any two numbers whose sum equals the target.",
tags: ["Technical", "Arrays"],
},
{
text:
"Given a string, determine if it contains all unique characters. Try solving it with and without extra data structures.",
tags: ["Technical", "Strings"],
},
{
text:
"Given a singly linked list, reverse the list in place and return the new head.",
tags: ["Technical", "Linked List"],
},
{
text:
"Given an array of integers, move all zeros to the end while keeping the relative order of non-zero elements.",
tags: ["Technical", "Arrays", "Two Pointers"],
},
{
text:
"Implement a function that checks whether two strings are anagrams of each other.",
tags: ["Technical", "Strings", "Hash Map"],
},
{
text:
"Given a sorted array of integers and a target, return the index of the target or the position where it should be inserted.",
tags: ["Technical", "Binary Search"],
},
{
text:
"Design a data structure that supports push, pop, top, and retrieving the minimum element in constant time.",
tags: ["Technical", "Stack", "Design"],
},
{
text:
"Given the root of a binary tree, return its level-order traversal (values by level).",
tags: ["Technical", "Trees", "BFS"],
},
{
text:
"Given an array of stock prices, compute the maximum profit from a single buy and a single sell.",
tags: ["Technical", "Arrays"],
},
{
text:
"You are given a staircase with n steps and you can climb 1 or 2 steps at a time. How many distinct ways can you climb to the top?",
tags: ["Technical", "Dynamic Programming"],
},
];
// Technical – SWE generic (non-FAANG / fallback)
const TECH_SWE_GENERIC = [
{
text:
"Implement a basic LRU (least recently used) cache with get and put operations.",
tags: ["Technical", "Design", "Hash Map"],
},
{
text:
"Given an unsorted array, return the length of the longest consecutive elements sequence.",
tags: ["Technical", "Arrays"],
},
{
text:
"Given a matrix, return its elements in spiral order starting from the top-left corner.",
tags: ["Technical", "Matrix"],
},
{
text:
"Given an array of meeting time intervals, determine if a single person could attend all meetings.",
tags: ["Technical", "Intervals"],
},
{
text:
"Given a string containing parentheses, determine if the sequence is valid (properly opened and closed).",
tags: ["Technical", "Stack"],
},
];
// Technical – Data Scientist
const TECH_DS_GENERIC = [
{
text:
"Explain how you would detect outliers in a univariate dataset. What techniques can you use?",
tags: ["Technical", "Statistics"],
},
{
text:
"Describe the bias-variance tradeoff. How does it influence your choice of model complexity?",
tags: ["Technical", "ML Theory"],
},
{
text:
"You have imbalanced classes in a classification problem. What approaches can you use to handle this?",
tags: ["Technical", "ML Practice"],
},
];
// Technical – PM or others (light system design style)
const TECH_PM_GENERIC = [
{
text:
"Design a system to send notifications to millions of users when a friend posts an update. What components would you include?",
tags: ["Technical", "System Design"],
},
{
text:
"How would you instrument a new feature to understand whether it is successful? Which metrics would you track?",
tags: ["Technical", "Product Sense"],
},
];
/* Helper: choose the right pool based on type / role / level / style */
function getQuestionPool(type, role, level, style) {
const normalizedType = (type || "behavioral").toLowerCase();
const normalizedRole = (role || "SWE").toLowerCase();
const normalizedStyle = (style || "Generic").toLowerCase();
if (normalizedType === "technical") {
if (normalizedRole === "swe") {
if (normalizedStyle === "faang") {
return TECH_SWE_FAANG_INTERN;
}
return TECH_SWE_GENERIC;
}
if (normalizedRole === "data scientist") {
return TECH_DS_GENERIC;
}
if (normalizedRole === "product manager") {
return TECH_PM_GENERIC;
}
// anything else → generic SWE technical set
return TECH_SWE_GENERIC;
}
// Behavioral for any role
return BEHAVIORAL_GENERIC;
}
/* Helper: random sample from a pool */
function sampleQuestions(pool, count = 5) {
const arr = [...pool];
for (let i = arr.length - 1; i > 0; i--) {
const j = Math.floor(Math.random() * (i + 1));
[arr[i], arr[j]] = [arr[j], arr[i]];
}
return arr.slice(0, Math.min(count, arr.length));
}
/* ------------------------------------------------------------------ */
/* API ENDPOINTS */
/* ------------------------------------------------------------------ */
// Health check
app.get("/api/health", (_req, res) => {
res.json({ ok: true });
});
// Main questions endpoint
// GET /api/questions?type=&role=&level=&style=
app.get("/api/questions", (req, res) => {
const {
type = "behavioral",
role = "SWE",
level = "Intern",
style = "Generic",
} = req.query;
const pool = getQuestionPool(type, role, level, style);
const questions = sampleQuestions(pool, 5);
res.json({ questions });
});
/* ------------------------------------------------------------------ */
app.listen(PORT, () => {
console.log(`LockedInterview API listening on http://localhost:${PORT}`);
console.log(`Open http://localhost:${PORT}/frontend.html in your browser`);
});