mirror of
https://github.com/donnemartin/interactive-coding-challenges
synced 2026-01-08 10:28:03 +00:00
Polish remove duplicates challenge and solution
Update constraints and algorithm discussion.
This commit is contained in:
@@ -38,9 +38,11 @@
|
|||||||
" * Singly\n",
|
" * Singly\n",
|
||||||
"* Can you insert None values in the list?\n",
|
"* Can you insert None values in the list?\n",
|
||||||
" * No\n",
|
" * No\n",
|
||||||
"* Can you use additional data structures?\n",
|
|
||||||
" * Implement both solutions\n",
|
|
||||||
"* Can we assume we already have a linked list class that can be used for this problem?\n",
|
"* Can we assume we already have a linked list class that can be used for this problem?\n",
|
||||||
|
" * Yes\n",
|
||||||
|
"* Can we use additional data structures?\n",
|
||||||
|
" * Implement both solutions\n",
|
||||||
|
"* Can we assume this fits in memory?\n",
|
||||||
" * Yes"
|
" * Yes"
|
||||||
]
|
]
|
||||||
},
|
},
|
||||||
@@ -193,7 +195,7 @@
|
|||||||
"name": "python",
|
"name": "python",
|
||||||
"nbconvert_exporter": "python",
|
"nbconvert_exporter": "python",
|
||||||
"pygments_lexer": "ipython3",
|
"pygments_lexer": "ipython3",
|
||||||
"version": "3.4.3"
|
"version": "3.5.0"
|
||||||
}
|
}
|
||||||
},
|
},
|
||||||
"nbformat": 4,
|
"nbformat": 4,
|
||||||
|
|||||||
@@ -38,9 +38,11 @@
|
|||||||
" * Singly\n",
|
" * Singly\n",
|
||||||
"* Can you insert None values in the list?\n",
|
"* Can you insert None values in the list?\n",
|
||||||
" * No\n",
|
" * No\n",
|
||||||
"* Can you use additional data structures?\n",
|
|
||||||
" * Implement both solutions\n",
|
|
||||||
"* Can we assume we already have a linked list class that can be used for this problem?\n",
|
"* Can we assume we already have a linked list class that can be used for this problem?\n",
|
||||||
|
" * Yes\n",
|
||||||
|
"* Can we use additional data structures?\n",
|
||||||
|
" * Implement both solutions\n",
|
||||||
|
"* Can we assume this fits in memory?\n",
|
||||||
" * Yes"
|
" * Yes"
|
||||||
]
|
]
|
||||||
},
|
},
|
||||||
@@ -62,6 +64,8 @@
|
|||||||
"source": [
|
"source": [
|
||||||
"## Algorithm: Hash Map Lookup\n",
|
"## Algorithm: Hash Map Lookup\n",
|
||||||
"\n",
|
"\n",
|
||||||
|
"Loop through each node\n",
|
||||||
|
"\n",
|
||||||
"* For each node\n",
|
"* For each node\n",
|
||||||
" * If the node's value is in the hash map\n",
|
" * If the node's value is in the hash map\n",
|
||||||
" * Delete the node\n",
|
" * Delete the node\n",
|
||||||
@@ -70,10 +74,7 @@
|
|||||||
"\n",
|
"\n",
|
||||||
"Complexity:\n",
|
"Complexity:\n",
|
||||||
"* Time: O(n)\n",
|
"* Time: O(n)\n",
|
||||||
"* Space: O(n)\n",
|
"* Space: O(n)"
|
||||||
"\n",
|
|
||||||
"Note:\n",
|
|
||||||
"* Deletion requires two pointers, one to the previous node and one to the current node"
|
|
||||||
]
|
]
|
||||||
},
|
},
|
||||||
{
|
{
|
||||||
@@ -84,17 +85,13 @@
|
|||||||
"\n",
|
"\n",
|
||||||
"* For each node\n",
|
"* For each node\n",
|
||||||
" * Compare node with every other node\n",
|
" * Compare node with every other node\n",
|
||||||
" * If the node's value is in the hash map\n",
|
" * Delete nodes that match current node\n",
|
||||||
" * Delete the node\n",
|
|
||||||
" * Else\n",
|
|
||||||
" * Add node's value to the hash map\n",
|
|
||||||
"\n",
|
"\n",
|
||||||
"Complexity:\n",
|
"Complexity:\n",
|
||||||
"* Time: O(n^2)\n",
|
"* Time: O(n^2)\n",
|
||||||
"* Space: O(1)\n",
|
"* Space: O(1)\n",
|
||||||
"\n",
|
"\n",
|
||||||
"Note:\n",
|
"Note:\n",
|
||||||
"* Deletion requires two pointers, one to the previous node and one to the current node\n",
|
|
||||||
"* We'll need to use a 'runner' to check every other node and compare it to the current node"
|
"* We'll need to use a 'runner' to check every other node and compare it to the current node"
|
||||||
]
|
]
|
||||||
},
|
},
|
||||||
@@ -258,7 +255,7 @@
|
|||||||
"name": "python",
|
"name": "python",
|
||||||
"nbconvert_exporter": "python",
|
"nbconvert_exporter": "python",
|
||||||
"pygments_lexer": "ipython3",
|
"pygments_lexer": "ipython3",
|
||||||
"version": "3.4.3"
|
"version": "3.5.0"
|
||||||
}
|
}
|
||||||
},
|
},
|
||||||
"nbformat": 4,
|
"nbformat": 4,
|
||||||
|
|||||||
Reference in New Issue
Block a user