Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
144 changes: 82 additions & 62 deletions 02_activities/assignments/assignment_1.ipynb
Original file line number Diff line number Diff line change
Expand Up @@ -10,17 +10,20 @@
"\n",
"This assignment aims to demonstrate how to study a data structures or algorithms question in depth to prepare for an industry coding interview. Leetcode is a popular coding practice site that many use to practice for technical interviews. Like behavioral interviews, it's important to practice and keep your skills sharp.\n",
"\n",
"## Group Size\n",
"\n",
"Please complete this individually.\n",
"## Instructions\n",
"Please complete this assignment individually.\n",
"\n",
"## Parts:\n",
"- Part 1: Figure out the problem you have been assigned, and understand the problem\n",
"- Part 2: Answer the questions about your assigned problem (including solving it)\n",
"- Part 1: Use the provided function to identify your assigned problem. You are only required to solve one out of the three problems in this notebook.\n",
"- Part 2: Answer a set of questions about your assigned problem.\n",
"\n",
"## Part 1:\n",
"\n",
"_*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"
"You will be assigned one of three problems based of your first name. Enter your first name as the `input_string`, 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",
"\n",
"💡 We are using a hash function here.\n",
"\n",
"Note: you will code your solution in Part 2.\n"
]
},
{
Expand All @@ -37,32 +40,40 @@
" return (hash_int % 3) + 1\n",
"input_string = \"your_first_name_here\"\n",
"result = hash_to_range(input_string)\n",
"print(result)\n"
"print(f\"Your assigned problem is: {result}\")"
]
},
{
"cell_type": "markdown",
"metadata": {},
"source": [
"## Question One: First Duplicate in List\n",
"## Problem One: First Duplicate in List\n",
"**Description** \n",
"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",
"Given a list of non-negative integers, return the first value that appears more than once. If there are multiple duplicates, return the one whose duplicate appears first in the list (see example 4). If no duplicate exists, return -1.\n",
"\n",
"**Examples**\n",
"```python\n",
"Input: nums = [3, 1, 4, 2, 5, 1, 6]\n",
"Output: 1\n",
"```\n",
"```python\n",
"Input: nums = [7, 8, 9, 10]\n",
"Output: -1\n",
"```\n",
"```python\n",
"Input: nums = [4, 5, 6, 4, 6]\n",
"Output: 4\n",
"```\n",
"\n",
"**Question 1 Starter Code**"
"* Example 1: one duplicate\n",
" ```python\n",
" Input: nums = [3, 1, 4, 2, 5, 1, 6]\n",
" Output: 1\n",
" ```\n",
"* Example 2: no duplicate\n",
" ```python\n",
" Input: nums = [7, 8, 9, 10]\n",
" Output: -1\n",
" ```\n",
"* Example 3: multiple duplicates\n",
" ```python\n",
" Input: nums = [4, 5, 6, 4, 6]\n",
" Output: 4\n",
" ```\n",
"* Example 4: multiple duplicates \n",
" ```python\n",
" Input: nums = [0, 1, 2, 1, 0]\n",
" Output: 1\n",
" ```\n",
"\n",
"**Problem 1 Starter Code**"
]
},
{
Expand All @@ -82,32 +93,37 @@
"cell_type": "markdown",
"metadata": {},
"source": [
"## Question Two: Valid Bracket Sequence\n",
"## Problem Two: Valid Bracket Sequence\n",
"**Description** \n",
"Given a string containing only the characters `'('`, `')'`, `'{'`, `'}'`, `'['`, and `']'`, determine if the input string is a **valid bracket sequence**. \n",
"A string is valid if:\n",
"Given a string containing only the characters `'('`, `')'`, `'{'`, `'}'`, `'['`, and `']'`, determine if the input string is a valid bracket sequence.\n",
"\n",
"A sequence is valid if:\n",
"- Open brackets are closed by the same type of brackets, and\n",
"- Open brackets are closed in the correct order.\n",
"\n",
"**Examples**\n",
"```python\n",
"Input: s = \"([]{})\"\n",
"Output: True\n",
"```\n",
"```python\n",
"Input: s = \"([)]\"\n",
"Output: False\n",
"```\n",
"```python\n",
"Input: s = \"()[]{}\"\n",
"Output: True\n",
"```\n",
"```python\n",
"Input: s = \"[{]}\"\n",
"Output: False\n",
"```\n",
"\n",
"**Question 2 Starter Code**"
"* Example 1:\n",
" ```python\n",
" Input: s = \"([]{})\"\n",
" Output: True\n",
" ```\n",
"* Example 2:\n",
" ```python\n",
" Input: s = \"([)]\"\n",
" Output: False\n",
" ```\n",
"* Example 3:\n",
" ```python\n",
" Input: s = \"()[]{}\"\n",
" Output: True\n",
" ```\n",
"* Example 4:\n",
" ```python\n",
" Input: s = \"[{]}\"\n",
" Output: False\n",
" ```\n",
"\n",
"**Problem 2 Starter Code**"
]
},
{
Expand All @@ -125,19 +141,23 @@
"cell_type": "markdown",
"metadata": {},
"source": [
"## Question Three: Move All Zeros to End\n",
"## Problem Three: Move All Zeros to End\n",
"**Description** \n",
"Given a list of integers, move all zeros to the end while maintaining the relative order of the non-zero elements. \n",
"\n",
"**Examples**\n",
"```python\n",
"Input: nums = [0, 1, 0, 3, 12]\n",
"Output: [1, 3, 12, 0, 0]\n",
"```\n",
"```python\n",
"Input: nums = [4, 0, 5, 0, 0, 6]\n",
"Output: [4, 5, 6, 0, 0, 0]\n",
"```\n"
"* Example 1:\n",
" ```python\n",
" Input: nums = [0, 1, 0, 3, 12]\n",
" Output: [1, 3, 12, 0, 0]\n",
" ```\n",
"* Example 2:\n",
" ```python\n",
" Input: nums = [4, 0, 5, 0, 0, 6]\n",
" Output: [4, 5, 6, 0, 0, 0]\n",
" ```\n",
"\n",
"**Problem 3 Starter Code**"
]
},
{
Expand All @@ -160,7 +180,7 @@
"\n",
"## Part 2:\n",
"\n",
"- Paraphrase the problem in your own words\n"
"1. Paraphrase the assigned problem in your own words.\n"
]
},
{
Expand All @@ -176,7 +196,7 @@
"cell_type": "markdown",
"metadata": {},
"source": [
"- In this .ipynb file, there are examples that illustrate how the code should work (the examples provided above). Create 2 new examples for the question you have been assigned, that demonstrate you understand the problem. For question 1 and 2, you don't need to create the tree demonstration, just the input and output.\n"
"2. In your assigned problem, there are a few provided examples with their expected outputs. Create two new examples with corresponding outputs for your assigned problem to demonstrate that you have understood the problem."
]
},
{
Expand All @@ -192,8 +212,7 @@
"cell_type": "markdown",
"metadata": {},
"source": [
"\n",
"- 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"
"3. Based on the provided starter code, code the solution to your assigned problem here in Python. Note: each problem can be solved more simply if you use an abstract data type that is suitable for that problem. Try to find the solution with best time and space complexity."
]
},
{
Expand All @@ -210,7 +229,7 @@
"metadata": {},
"source": [
"\n",
"- Explain why your solution works\n"
"4. Walk through your Python code in plain words and explain why your solution works.\n"
]
},
{
Expand All @@ -227,7 +246,7 @@
"metadata": {},
"source": [
"\n",
"- Explain the problem’s time and space complexity\n"
"5. Explain the time and space complexity of your solution.\n"
]
},
{
Expand All @@ -244,7 +263,7 @@
"metadata": {},
"source": [
"\n",
"- Explain the thinking to an alternative solution (no coding required, but a classmate reading this should be able to code it up based off your text)\n"
"6. Describe an alternative solution to your problem in plain words, e.g., with a different data structure or time/space complexities. Note: you don't need to code your alternative solution, but a classmate reading this should be able to code it based on your description.\n"
]
},
{
Expand Down Expand Up @@ -282,20 +301,21 @@
"🚨 **Please review our [Assignment Submission Guide](https://github.com/UofT-DSI/onboarding/blob/main/onboarding_documents/submissions.md)** 🚨 for detailed instructions on how to format, branch, and submit your work. Following these guidelines is crucial for your submissions to be evaluated correctly.\n",
"\n",
"### Submission Parameters:\n",
"* Submission Due Date: `HH:MM AM/PM - DD/MM/YYYY`\n",
"* Submission Due Date: `2026-10-26 11:59PM ET`\n",
"* The branch name for your repo should be: `assignment-1`\n",
"* What to submit for this assignment:\n",
" * This Jupyter Notebook (assignment_1.ipynb) should be populated and should be the only change in your pull request.\n",
"* What the pull request link should look like for this assignment: `https://github.com/<your_github_username>/algorithms_and_data_structures/pull/<pr_id>`\n",
" * Open a private window in your browser. Copy and paste the link to your pull request into the address bar. Make sure you can see your pull request properly. This helps the technical facilitator and learning support staff review your submission easily.\n",
"* Please do not merge your pull request until one of the learning support staff has approved it. Closed or merged pull requests will not be reviewed. If changes are suggested, please follow the instructions in the thread and revise your submission. \n",
"\n",
"Checklist:\n",
"- [ ] Create a branch called `assignment-1`.\n",
"- [ ] Ensure that the repository is public.\n",
"- [ ] Review [the PR description guidelines](https://github.com/UofT-DSI/onboarding/blob/main/onboarding_documents/submissions.md#guidelines-for-pull-request-descriptions) and adhere to them.\n",
"- [ ] Verify that the link is accessible in a private browser window.\n",
"\n",
"If you encounter any difficulties or have questions, please don't hesitate to reach out to our team via our Slack at `#cohort-3-help`. Our Technical Facilitators and Learning Support staff are here to help you navigate any challenges."
"If you encounter any difficulties or have questions, please don't hesitate to reach out to our team via our Slack at `#mlf2-help`. Our Technical Facilitators and Learning Support staff are here to help you navigate any challenges."
]
}
],
Expand Down
Loading