Skip to content

Commit a498d51

Browse files
Merge pull request #55 from UofT-DSI/cohort-6-updates
Updated README, Added Lecture 5 material, updated assignment 1 and 2 …
2 parents b4b279d + f1e6bfa commit a498d51

File tree

14 files changed

+891
-12620
lines changed

14 files changed

+891
-12620
lines changed

01_materials/slides/5_slow_code.ipynb

Lines changed: 590 additions & 0 deletions
Large diffs are not rendered by default.

02_activities/assignments/assignment_1.ipynb

Lines changed: 80 additions & 117 deletions
Original file line numberDiff line numberDiff line change
@@ -14,6 +14,10 @@
1414
"\n",
1515
"Please complete this individually.\n",
1616
"\n",
17+
"## Parts:\n",
18+
"- Part 1: Figure out the problem you have been assigned, and understand the problem\n",
19+
"- Part 2: Answer the questions about your assigned problem (including solving it)\n",
20+
"\n",
1721
"## Part 1:\n",
1822
"\n",
1923
"_*You will be assigned one of three problems based of your first name. Enter your first name, in all lower case, execute the code below, and that will tell you your assigned problem. Include the output as part of your submission (do not clear the output). The problems are based-off problems from Leetcode.*_\n"
@@ -40,42 +44,25 @@
4044
"cell_type": "markdown",
4145
"metadata": {},
4246
"source": [
43-
"<details>\n",
44-
" <summary>Question 1</summary>\n",
45-
"\n",
46-
" # Question One: Check Duplicates in Tree\n",
47-
"\n",
48-
" Given the `root` of a binary tree, check whether it is contains a duplicate value. If a duplicate exists, return the duplicate value. If there are multiple duplicates, return the one with the closest distance to the root. If no duplicate exists, return -1.\n",
49-
"\n",
50-
" ## Examples\n",
51-
"\n",
52-
" ### Example 1\n",
53-
"\n",
54-
" ![](./images/q1_ex1.png)\n",
55-
"\n",
56-
" Input: `root = [1, 2, 2, 3, 5, 6, 7]` *What traversal method is this?*\n",
57-
"\n",
58-
" Output: 2\n",
59-
"\n",
60-
" ### Example 2\n",
61-
"\n",
62-
" ![](./images/q1_ex2.png)\n",
63-
"\n",
64-
" Input: `root = [1, 10, 2, 3, 10, 12, 12]`\n",
65-
"\n",
66-
" Output: 10\n",
67-
"\n",
68-
" ### Example 3\n",
69-
"\n",
70-
" ![](./images/q1_ex3.png)\n",
71-
"\n",
72-
" Input: `root = [10, 9, 8, 7]`\n",
73-
"\n",
74-
" Output: -1\n",
75-
"\n",
76-
"</details>\n",
77-
"\n",
78-
"#### Starter Code for Question 1"
47+
"## Question One: First Duplicate in List\n",
48+
"**Description** \n",
49+
"Given a list of integers, return the **first value that appears more than once**. If there are multiple duplicates, return the one that appears **first** in the list. If no duplicate exists, return `-1`.\n",
50+
"\n",
51+
"**Examples**\n",
52+
"```python\n",
53+
"Input: nums = [3, 1, 4, 2, 5, 1, 6]\n",
54+
"Output: 1\n",
55+
"```\n",
56+
"```python\n",
57+
"Input: nums = [7, 8, 9, 10]\n",
58+
"Output: -1\n",
59+
"```\n",
60+
"```python\n",
61+
"Input: nums = [4, 5, 6, 4, 6]\n",
62+
"Output: 4\n",
63+
"```\n",
64+
"\n",
65+
"**Question 1 Starter Code**"
7966
]
8067
},
8168
{
@@ -84,100 +71,73 @@
8471
"metadata": {},
8572
"outputs": [],
8673
"source": [
87-
"# Definition for a binary tree node.\n",
88-
"# class TreeNode(object):\n",
89-
"# def __init__(self, val = 0, left = None, right = None):\n",
90-
"# self.val = val\n",
91-
"# self.left = left\n",
92-
"# self.right = right\n",
93-
"def is_duplicate(root: TreeNode) -> int:\n",
94-
" # TODO"
74+
"from typing import List\n",
75+
"\n",
76+
"def first_duplicate(nums: List[int]) -> int:\n",
77+
" # TODO\n",
78+
" pass"
9579
]
9680
},
9781
{
9882
"cell_type": "markdown",
9983
"metadata": {},
10084
"source": [
101-
"<details>\n",
102-
" <summary>Question 2</summary>\n",
103-
"\n",
104-
" # Question Two: Path to Leaves\n",
105-
"\n",
106-
" Given the `root` of a binary tree, return all root to leaf paths in any order.\n",
107-
"\n",
108-
" ## Examples\n",
109-
"\n",
110-
" ### Example 1\n",
111-
"\n",
112-
" ![](./images/q1_ex1.png)\n",
113-
"\n",
114-
" Input: `root = [1, 2, 2, 3, 5, 6, 7]` *What traversal method is this?*\n",
115-
"\n",
116-
" Output: [[1, 2, 3], [1, 2, 5], [1, 2, 6], [1, 2, 7]]\n",
117-
"\n",
118-
" ### Example 2\n",
119-
"\n",
120-
" ![](./images/q1_ex3.png)\n",
121-
"\n",
122-
" Input: `root = [10, 9, 7, 8]`\n",
123-
"\n",
124-
" Output: [[10, 7], [10, 9, 8]]\n",
125-
"\n",
126-
"</details>\n",
127-
"\n",
128-
"#### Starter Code for Question 2"
85+
"## Question Two: Valid Bracket Sequence\n",
86+
"**Description** \n",
87+
"Given a string containing only the characters `'('`, `')'`, `'{'`, `'}'`, `'['`, and `']'`, determine if the input string is a **valid bracket sequence**. \n",
88+
"A string is valid if:\n",
89+
"- Open brackets are closed by the same type of brackets, and\n",
90+
"- Open brackets are closed in the correct order.\n",
91+
"\n",
92+
"**Examples**\n",
93+
"```python\n",
94+
"Input: s = \"([]{})\"\n",
95+
"Output: True\n",
96+
"```\n",
97+
"```python\n",
98+
"Input: s = \"([)]\"\n",
99+
"Output: False\n",
100+
"```\n",
101+
"```python\n",
102+
"Input: s = \"()[]{}\"\n",
103+
"Output: True\n",
104+
"```\n",
105+
"```python\n",
106+
"Input: s = \"[{]}\"\n",
107+
"Output: False\n",
108+
"```\n",
109+
"\n",
110+
"**Question 2 Starter Code**"
129111
]
130112
},
131113
{
132114
"cell_type": "code",
133-
"execution_count": null,
115+
"execution_count": 1,
134116
"metadata": {},
135117
"outputs": [],
136118
"source": [
137-
"# Definition for a binary tree node.\n",
138-
"# class TreeNode(object):\n",
139-
"# def __init__(self, val = 0, left = None, right = None):\n",
140-
"# self.val = val\n",
141-
"# self.left = left\n",
142-
"# self.right = right\n",
143-
"def bt_path(root: TreeNode) -> List[List[int]]:\n",
144-
" # TODO"
119+
"def is_valid_brackets(s: str) -> bool:\n",
120+
" # TODO\n",
121+
" pass"
145122
]
146123
},
147124
{
148125
"cell_type": "markdown",
149126
"metadata": {},
150127
"source": [
151-
"<details>\n",
152-
" <summary>Question 3</summary>\n",
153-
"\n",
154-
" # Question Three: Missing Number in Range\n",
155-
" \n",
156-
" You are given a list containing `n` integers in the range `[0, n]`. Return a list of numbers that are missing from the range `[0, n]` of the array. If there is no missing number, return -1. Note, all the integers in the list may not be unique.\n",
157-
" \n",
158-
" ## Examples\n",
159-
"\n",
160-
" ### Example 1\n",
161-
"\n",
162-
" Input: `lst = [0, 2]`\n",
163-
"\n",
164-
" Output: [1]\n",
165-
"\n",
166-
" ### Example 2\n",
167-
"\n",
168-
" Input: `lst = [5, 0, 1]`\n",
169-
"\n",
170-
" Output: [2, 3, 4]\n",
171-
"\n",
172-
" ### Example 3\n",
173-
"\n",
174-
" Input: `lst = [6, 8, 2, 3, 5, 7, 0, 1, 10]`\n",
175-
"\n",
176-
" Output: [4, 9]\n",
177-
"\n",
178-
"</details>\n",
179-
"\n",
180-
"#### Starter Code for Question 3\n"
128+
"## Question Three: Move All Zeros to End\n",
129+
"**Description** \n",
130+
"Given a list of integers, move all zeros to the end while maintaining the relative order of the non-zero elements. \n",
131+
"\n",
132+
"**Examples**\n",
133+
"```python\n",
134+
"Input: nums = [0, 1, 0, 3, 12]\n",
135+
"Output: [1, 3, 12, 0, 0]\n",
136+
"```\n",
137+
"```python\n",
138+
"Input: nums = [4, 0, 5, 0, 0, 6]\n",
139+
"Output: [4, 5, 6, 0, 0, 0]\n",
140+
"```\n"
181141
]
182142
},
183143
{
@@ -186,8 +146,11 @@
186146
"metadata": {},
187147
"outputs": [],
188148
"source": [
189-
"def missing_num(nums: List) -> int:\n",
190-
" # TODO"
149+
"from typing import List\n",
150+
"\n",
151+
"def move_zeros_to_end(nums: List[int]) -> List[int]:\n",
152+
" # TODO\n",
153+
" pass"
191154
]
192155
},
193156
{
@@ -230,7 +193,7 @@
230193
"metadata": {},
231194
"source": [
232195
"\n",
233-
"- Code the solution to your assigned problem in Python (code chunk). Try to find the best time and space complexity solution!\n"
196+
"- Code the solution to your assigned problem in Python (code chunk). Note: each problem can be solved more simply if you use an abstract data type that is suitable for that problem. Using that try to find the best time and space complexity solution!\n"
234197
]
235198
},
236199
{
@@ -338,7 +301,7 @@
338301
],
339302
"metadata": {
340303
"kernelspec": {
341-
"display_name": "Python 3",
304+
"display_name": "Python 3 (ipykernel)",
342305
"language": "python",
343306
"name": "python3"
344307
},
@@ -352,9 +315,9 @@
352315
"name": "python",
353316
"nbconvert_exporter": "python",
354317
"pygments_lexer": "ipython3",
355-
"version": "3.11.7"
318+
"version": "3.11.5"
356319
}
357320
},
358321
"nbformat": 4,
359-
"nbformat_minor": 2
322+
"nbformat_minor": 4
360323
}

0 commit comments

Comments
 (0)