Skip to content
Open
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
72 changes: 63 additions & 9 deletions 02_activities/assignments/assignment_2.ipynb
Original file line number Diff line number Diff line change
Expand Up @@ -27,17 +27,25 @@
},
{
"cell_type": "code",
"execution_count": null,
"execution_count": 1,
"metadata": {},
"outputs": [],
"outputs": [
{
"name": "stdout",
"output_type": "stream",
"text": [
"3\n"
]
}
],
"source": [
"import hashlib\n",
"\n",
"def hash_to_range(input_string: str) -> int:\n",
" hash_object = hashlib.sha256(input_string.encode())\n",
" hash_int = int(hash_object.hexdigest(), 16)\n",
" return (hash_int % 3) + 1\n",
"input_string = \"your_first_name_here\"\n",
"input_string = \"ashwinder\"\n",
"result = hash_to_range(input_string)\n",
"print(result)\n"
]
Expand Down Expand Up @@ -159,7 +167,7 @@
"\n",
" # Question Three: Missing Number in Range\n",
" \n",
" 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",
" You are given a list of non-negative integers. Return a list of numbers that are missing from the range [0, maximum value]. If there is no missing number, return -1. Note, all the integers in the list may not be unique.\n",
" \n",
" ## Examples\n",
"\n",
Expand Down Expand Up @@ -188,14 +196,51 @@
},
{
"cell_type": "code",
"execution_count": null,
"execution_count": 14,
"metadata": {
"scrolled": true
},
"outputs": [],
"outputs": [
{
"data": {
"text/plain": [
"[2, 3, 4]"
]
},
"execution_count": 14,
"metadata": {},
"output_type": "execute_result"
}
],
"source": [
"from typing import List\n",
"\n",
"def missing_num(nums: List) -> int:\n",
" # TODO"
" #todo\n",
" if len(nums) == 0:\n",
" return -1\n",
" \n",
" # take the maximum value to create a bool present list\n",
" max_number = max(nums)\n",
" present = [False] * (max_number + 1)\n",
" \n",
" # now set the present list indices true for the values present in nums\n",
" for num in nums:\n",
" if 0 <= num <= max_number:\n",
" present[num] = True\n",
"\n",
" # collect the missing numbers\n",
" missing = []\n",
" # to collect missing number\n",
" # check for the range 0 to max\n",
" for i in range(max_number + 1):\n",
" if present[i] != True:\n",
" missing.append(i)\n",
"\n",
" return missing\n",
"\n",
"nums = [5,0,1]\n",
"missing_num(nums)"
]
},
{
Expand All @@ -209,6 +254,15 @@
"You and your partner must share each other's Assignment 1 submission."
]
},
{
"cell_type": "markdown",
"metadata": {},
"source": [
"I got the assignment below:\n",
"\n",
"https://github.com/VinuShan4/algorithms_and_data_structures/pulls"
]
},
{
"cell_type": "markdown",
"metadata": {},
Expand Down Expand Up @@ -396,7 +450,7 @@
],
"metadata": {
"kernelspec": {
"display_name": "Python 3 (ipykernel)",
"display_name": "dsi_participant",
"language": "python",
"name": "python3"
},
Expand All @@ -410,7 +464,7 @@
"name": "python",
"nbconvert_exporter": "python",
"pygments_lexer": "ipython3",
"version": "3.11.5"
"version": "3.9.23"
}
},
"nbformat": 4,
Expand Down