-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathseedProblem.js
More file actions
150 lines (140 loc) · 3.18 KB
/
seedProblem.js
File metadata and controls
150 lines (140 loc) · 3.18 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
import prisma from "./config/prisma.js";
async function main() {
console.log("Start seeding for LC-70 problem...");
// 1. Upsert Categories
const categoriesData = [{ name: "Dynamic Programming" }, { name: "Math" }, { name: "Fibonacci" }];
const categoryUpserts = categoriesData.map((cat) =>
prisma.category.upsert({
where: { name: cat.name },
update: {},
create: { name: cat.name },
})
);
const categories = await Promise.all(categoryUpserts);
console.log("Categories seeded:", categories.map((c) => c.name).join(", "));
const categoryIds = categories.map((c) => ({ id: c.id }));
// 2. Get Round 1 (assuming it already exists)
const round = await prisma.round.findUnique({
where: { roundNumber: 1 },
});
if (!round) {
throw new Error("Round 1 not found in database. Please ensure rounds are seeded first.");
}
console.log(`Using existing Round ${round.roundNumber}.`);
// 3. Define the Problem Data
const problemTitle = "Climbing Stairs"; // LC-70
const problemData = {
title: problemTitle,
description:
"You are climbing a staircase with n steps. Each time you can either climb 1 or 2 steps. " +
"Return the number of distinct ways to reach the top.\n\n" +
"Input Format:\n" +
"A single integer n.\n\n" +
"Output Format:\n" +
"A single integer: the number of distinct ways to climb to the top.\n",
difficulty: "R1_EASY",
constraints: [
"1 <= n <= 45",
],
hints: [
"Let f[i] be ways to reach step i; then f[i] = f[i-1] + f[i-2] with f[0]=1, f[1]=1.",
"Space-opt: keep only the last two values while iterating up to n.",
"This is the Fibonacci sequence shifted by one index.",
],
boilerplate: {
python: ``,
cpp: ``,
java: ``,
c: ``,
},
sampleTestCases: [
{
"stdin": "1\n",
"expected_output": "1\n"
},
{
"stdin": "2\n",
"expected_output": "2\n"
}
],
hiddenTestCases: [
{
"stdin": "3\n",
"expected_output": "3\n"
},
{
"stdin": "4\n",
"expected_output": "5\n"
},
{
"stdin": "5\n",
"expected_output": "8\n"
},
{
"stdin": "6\n",
"expected_output": "13\n"
},
{
"stdin": "7\n",
"expected_output": "21\n"
},
{
"stdin": "8\n",
"expected_output": "34\n"
},
{
"stdin": "9\n",
"expected_output": "55\n"
},
{
"stdin": "10\n",
"expected_output": "89\n"
},
{
"stdin": "20\n",
"expected_output": "10946\n"
},
{
"stdin": "25\n",
"expected_output": "121393\n"
},
{
"stdin": "30\n",
"expected_output": "1346269\n"
},
{
"stdin": "35\n",
"expected_output": "14930352\n"
},
{
"stdin": "40\n",
"expected_output": "165580141\n"
}
],
avgTimeComplexity: "O(n)",
avgSpaceComplexity: "O(1)",
roundId: round.roundNumber,
};
// 4. Upsert the problem, connecting it to the categories
await prisma.problem.upsert({
where: { title: problemTitle },
update: {
...problemData,
categories: { set: categoryIds },
},
create: {
...problemData,
categories: { connect: categoryIds },
},
});
console.log(`Successfully seeded problem: \"" + problemTitle + "\"`);
}
main()
.catch((e) => {
console.error(e);
process.exit(1);
})
.finally(async () => {
await prisma.$disconnect();
console.log("Seeding finished.");
});