Skip to content

Commit 1bf7719

Browse files
committed
Merge branch 'develop' of github.com:NSS-Workshops/data-structures-and-algorithms into develop
2 parents c6833b8 + f137d47 commit 1bf7719

65 files changed

Lines changed: 8145 additions & 22 deletions

File tree

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

.gitignore

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -4,6 +4,7 @@
44
.env.development.local
55
.env.test.local
66
.env.production.local
7+
.npmrc
78

89
# Dependencies
910
node_modules

README.md

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -64,11 +64,11 @@ Chapters are individual lessons within a section:
6464
previousChapterId: null,
6565
nextChapterId: 'arrays-indices',
6666
content: `## Arrays (a.k.a. collections of things)...`,
67-
exercise: {
67+
exercises: [{
6868
starterCode: `// Example starter code...`,
6969
solution: `// Example solution...`,
7070
tests: [/* tests */]
71-
}
71+
}]
7272
}
7373
```
7474

@@ -354,11 +354,11 @@ The application will be available at http://localhost:5173/data-structures-and-a
354354
previousChapterId: 'previous-chapter',
355355
nextChapterId: 'next-chapter',
356356
content: `## Markdown Content...`,
357-
exercise: {
357+
exercises: [{
358358
starterCode: `// Starter code...`,
359359
solution: `// Solution...`,
360360
tests: [/* tests */]
361-
}
361+
}]
362362
}
363363
```
364364

62.4 KB
Loading
53.6 KB
Loading
Lines changed: 187 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,187 @@
1+
import { TestResult } from "@nss-workshops/nss-core";
2+
3+
export default {
4+
id: 'a1cc999d',
5+
title: 'Two Sum',
6+
sectionId: 'introduction',
7+
previousChapterId: null,
8+
content: `
9+
Hi 👋,
10+
You'll be guiding your partner through the coding problem on the right side of your screen.
11+
12+
⚠️ **Please do not share this URL / problem before class.**
13+
Revealing the question early defeats the purpose of simulating a real-world interview, where candidates do not know the problem in advance. Let's give your partner the chance to experience the challenge authentically.
14+
15+
🧠 **Before class:**
16+
Take time to study the problem. During the session, you'll have 90 minutes in your breakout room to run a mock interview with your partner. Be sure to take turns acting as the interviewer and interviewee.
17+
18+
🗣️ **As the interviewer, your responsibilities are:**
19+
- Send this URL to your partner (copy and past the whole url and slack it directly to you partner)
20+
- Briefly introduce the problem
21+
- Never give away the answer
22+
- Take notes and provide feedback
23+
- Fill out this [solving guide](https://docs.google.com/forms/d/e/1FAIpQLSfKHRJlZSUR-lKnQgfIWhe5GzM1CcMmO6Lf8ECvAY8DsFh1FA/viewform)
24+
25+
🗣️ **As the interviewee, your responsibilities are:**
26+
- Ask clarifying questions
27+
- Follow the steps in the [solving guide](https://docs.google.com/forms/d/e/1FAIpQLSfKHRJlZSUR-lKnQgfIWhe5GzM1CcMmO6Lf8ECvAY8DsFh1FA/viewform):
28+
Step 1: Clarify
29+
Step 2: Plan
30+
Step 3: Implement
31+
Step 4: Test
32+
Step 5: Optimize
33+
34+
🪞 **After the first interview:**
35+
Leave 10–15 minutes to reflect, share feedback, and then switch roles.
36+
37+
Best of luck, and enjoy the practice! 🚀
38+
## Problem: Two Sum
39+
40+
Given an array of integers \`nums\` and an integer \`target\`, return indices of the two numbers such that they add up to target.
41+
42+
You may assume that each input would have exactly one solution, and you may not use the same element twice.
43+
44+
You can return the answer in any order.
45+
46+
**Note:** Values can be duplicated, you can short circuit, and it's guaranteed to have a solution.
47+
48+
### Examples:
49+
50+
**Example 1:**
51+
- Input: nums = [2,7,11,15], target = 9
52+
- Output: [0,1]
53+
- Explanation: Because nums[0] + nums[1] == 9, we return [0, 1].
54+
55+
**Example 2:**
56+
- Input: nums = [3,2,4], target = 6
57+
- Output: [1,2]
58+
59+
**Example 3:**
60+
- Input: nums = [3,3], target = 6
61+
- Output: [0,1]
62+
63+
### Follow-up Questions:
64+
- What is the time and space complexity of your solution?
65+
- How would you optimize this if the array was sorted?
66+
- What if we needed to find all pairs that sum to the target?
67+
`,
68+
exercises: [{
69+
starterCode:`
70+
/*
71+
Problem: Two Sum
72+
73+
Given an array of integers nums and an integer target,
74+
return indices of the two numbers such that they add up to target.
75+
76+
You may assume that each input would have exactly one solution,
77+
and you may not use the same element twice.
78+
79+
You can return the answer in any order.
80+
*/
81+
function twoSum(nums, target) {
82+
// Your code here
83+
}`,
84+
solution:`
85+
/*
86+
Problem: Two Sum
87+
88+
Given an array of integers nums and an integer target,
89+
return indices of the two numbers such that they add up to target.
90+
91+
You may assume that each input would have exactly one solution,
92+
and you may not use the same element twice.
93+
94+
You can return the answer in any order.
95+
*/
96+
function twoSum(nums, target) {
97+
const map = new Map();
98+
99+
for (let i = 0; i < nums.length; i++) {
100+
const complement = target - nums[i];
101+
102+
if (map.has(complement)) {
103+
return [map.get(complement), i];
104+
}
105+
106+
map.set(nums[i], i);
107+
}
108+
109+
// This should never be reached given the problem constraints
110+
return [];
111+
}`,
112+
tests:[
113+
{
114+
name: "Two Sum - Example 1",
115+
test: (code) => {
116+
try {
117+
const twoSum = new Function(`${code}; return twoSum;`)();
118+
const nums = [2, 7, 11, 15];
119+
const target = 9;
120+
const result = twoSum(nums, target);
121+
const expected = [0, 1];
122+
return JSON.stringify(result.sort()) === JSON.stringify(expected.sort())
123+
? new TestResult({ passed: true })
124+
: new TestResult({ passed: false, message: `Expected ${JSON.stringify(expected)}, got ${JSON.stringify(result)}` });
125+
} catch (e) {
126+
return new TestResult({ passed: false, message: e.message });
127+
}
128+
},
129+
message: "Should return [0,1] for nums=[2,7,11,15], target=9"
130+
},
131+
{
132+
name: "Two Sum - Example 2",
133+
test: (code) => {
134+
try {
135+
const twoSum = new Function(`${code}; return twoSum;`)();
136+
const nums = [3, 2, 4];
137+
const target = 6;
138+
const result = twoSum(nums, target);
139+
const expected = [1, 2];
140+
return JSON.stringify(result.sort()) === JSON.stringify(expected.sort())
141+
? new TestResult({ passed: true })
142+
: new TestResult({ passed: false, message: `Expected ${JSON.stringify(expected)}, got ${JSON.stringify(result)}` });
143+
} catch (e) {
144+
return new TestResult({ passed: false, message: e.message });
145+
}
146+
},
147+
message: "Should return [1,2] for nums=[3,2,4], target=6"
148+
},
149+
{
150+
name: "Two Sum - Example 3 (Duplicates)",
151+
test: (code) => {
152+
try {
153+
const twoSum = new Function(`${code}; return twoSum;`)();
154+
const nums = [3, 3];
155+
const target = 6;
156+
const result = twoSum(nums, target);
157+
const expected = [0, 1];
158+
return JSON.stringify(result.sort()) === JSON.stringify(expected.sort())
159+
? new TestResult({ passed: true })
160+
: new TestResult({ passed: false, message: `Expected ${JSON.stringify(expected)}, got ${JSON.stringify(result)}` });
161+
} catch (e) {
162+
return new TestResult({ passed: false, message: e.message });
163+
}
164+
},
165+
message: "Should return [0,1] for nums=[3,3], target=6"
166+
},
167+
{
168+
name: "Two Sum - Negative Numbers",
169+
test: (code) => {
170+
try {
171+
const twoSum = new Function(`${code}; return twoSum;`)();
172+
const nums = [-1, -2, -3, -4, -5];
173+
const target = -8;
174+
const result = twoSum(nums, target);
175+
const expected = [2, 4];
176+
return JSON.stringify(result.sort()) === JSON.stringify(expected.sort())
177+
? new TestResult({ passed: true })
178+
: new TestResult({ passed: false, message: `Expected ${JSON.stringify(expected)}, got ${JSON.stringify(result)}` });
179+
} catch (e) {
180+
return new TestResult({ passed: false, message: e.message });
181+
}
182+
},
183+
message: "Should handle negative numbers correctly"
184+
}
185+
]
186+
}]
187+
};

src/sections/01-introduction/index.js

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -15,4 +15,4 @@ const config = {
1515

1616
const chapters = Object.values(chapterModules).map(chapter => ({ ...chapter.default, sectionId: config.id }) )
1717

18-
export { chapters, config }
18+
export { chapters, config }

src/sections/02-just-enough-math/04-glossary/index.jsx

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -27,7 +27,7 @@ export default {
2727
id: "just-enough-math-glossary",
2828
title: "Glossary",
2929
previousChapterId: "combinations-permutations",
30-
nextChapterId: null,
30+
nextChapterId: "module-feedback",
3131
content: `${formatGlossary(data)}`,
3232
exercises: [],
3333
quiz: null
Lines changed: 81 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,81 @@
1+
import { Checkpoint, QUESTION_TYPES } from "@nss-workshops/nss-core";
2+
3+
const questions = [
4+
{
5+
type: QUESTION_TYPES.RADIO,
6+
questionJsx: <p>Your company is hiring four software development engineers from a pool of 12 candidates. The order in which the candidates are hired has no effect. How many distinct groups of four SDEs are there?</p>,
7+
answers: [
8+
"495",
9+
"11,880",
10+
"24",
11+
"12"
12+
],
13+
correctAnswer: 0
14+
},
15+
{
16+
type: QUESTION_TYPES.RADIO,
17+
questionJsx: <p>You have an office with four unique walls ordered by N-S-E-W. You have enough room to hang 4 paintings, one on each wall. If you have 6 paintings to choose from, how many arrangements are there to hang the 4 paintings?</p>,
18+
answers: [
19+
"24",
20+
"15",
21+
"360",
22+
"6"
23+
],
24+
correctAnswer: 2
25+
},
26+
{
27+
type: QUESTION_TYPES.RADIO,
28+
questionJsx: <p>Which of the following statements accurately describes combinations?</p>,
29+
answers: [
30+
"Combinations are groupings of items in which the order of the grouping matters.",
31+
"Combinations are groupings of items in which the order of the grouping does not matter.",
32+
"Combinations are the number of ways to arrange a certain number of objects.",
33+
"Combinations are calculated by multiplying the number of available possibilities."
34+
],
35+
correctAnswer: 1
36+
},
37+
{
38+
type: QUESTION_TYPES.RADIO,
39+
questionJsx: <p>Your company issues each employee a five-letter ID code. The code is composed of the letters A, B, C, D, E, F, G, and H. The same letter cannot appear twice in a single ID code. How many unique three-letter ID codes are there?</p>,
40+
answers: [
41+
"56",
42+
"512",
43+
"40,320",
44+
"336",
45+
],
46+
correctAnswer: 3
47+
},
48+
{
49+
type: QUESTION_TYPES.RADIO,
50+
questionJsx: <p>Given a list of 9 elements, how many combinations of 5 are there?</p>,
51+
answers: [
52+
"120",
53+
"15,120",
54+
"59,049",
55+
"126",
56+
],
57+
correctAnswer: 3
58+
},
59+
{
60+
type: QUESTION_TYPES.RADIO,
61+
questionJsx: <p>Which of the following statements accurately describes permutations?</p>,
62+
answers: [
63+
"Permutations are groupings of items in which the order does not matter.",
64+
"Permutations are groupings of items in which the order matters",
65+
"There are generally more combinations than permutations for the same data set.",
66+
"Permutations are calculated by adding up all the elements in a data set."
67+
],
68+
correctAnswer: 1
69+
}
70+
];
71+
72+
export default {
73+
id: 'c9d3a5b8',
74+
title: 'Combinations and Permutations Quiz',
75+
sectionId: 'just-enough-math',
76+
previousChapterId: null,
77+
content: `Test your understanding of combinations, permutations, and their applications in organizing and counting data.`,
78+
quiz: {
79+
component: () => <Checkpoint questions={questions}/>
80+
}
81+
};

0 commit comments

Comments
 (0)