Skip to content

Commit 8ad81ec

Browse files
authored
Merge pull request jmportilla#26 from damtur/master
Fix trailing spaces folder names to make it possible to checkout in Windows
2 parents 321eb07 + 7cb4ecd commit 8ad81ec

File tree

70 files changed

+6034
-0
lines changed

Some content is hidden

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

70 files changed

+6034
-0
lines changed
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,67 @@
1+
{
2+
"cells": [
3+
{
4+
"cell_type": "markdown",
5+
"metadata": {},
6+
"source": [
7+
"# Implement a Doubly Linked List\n",
8+
"\n",
9+
"For this interview problem, implement a node class and show how it can be used to create a doubly linked list."
10+
]
11+
},
12+
{
13+
"cell_type": "code",
14+
"execution_count": 1,
15+
"metadata": {
16+
"collapsed": true
17+
},
18+
"outputs": [],
19+
"source": [
20+
"class Node(object):\n",
21+
" pass"
22+
]
23+
},
24+
{
25+
"cell_type": "code",
26+
"execution_count": 2,
27+
"metadata": {
28+
"collapsed": true
29+
},
30+
"outputs": [],
31+
"source": [
32+
"# Create a Doubly Linked List here"
33+
]
34+
},
35+
{
36+
"cell_type": "markdown",
37+
"metadata": {},
38+
"source": [
39+
"# Test Your Solution\n",
40+
"Note that there is no test for this solution (because it would give away the answer structure).\n",
41+
"\n",
42+
"Check out the Implement a Linked List Solution Notebook for the answer to this interview problem, as well as the answer for the implementation of a singly linked list."
43+
]
44+
}
45+
],
46+
"metadata": {
47+
"kernelspec": {
48+
"display_name": "Python 2",
49+
"language": "python",
50+
"name": "python2"
51+
},
52+
"language_info": {
53+
"codemirror_mode": {
54+
"name": "ipython",
55+
"version": 2
56+
},
57+
"file_extension": ".py",
58+
"mimetype": "text/x-python",
59+
"name": "python",
60+
"nbconvert_exporter": "python",
61+
"pygments_lexer": "ipython2",
62+
"version": "2.7.11"
63+
}
64+
},
65+
"nbformat": 4,
66+
"nbformat_minor": 0
67+
}
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,68 @@
1+
{
2+
"cells": [
3+
{
4+
"cell_type": "markdown",
5+
"metadata": {},
6+
"source": [
7+
"# Implement a Singly Linked List\n",
8+
"\n",
9+
"For this interview problem, create a node class and show how it can be used to create a Singly Linked List"
10+
]
11+
},
12+
{
13+
"cell_type": "code",
14+
"execution_count": 1,
15+
"metadata": {
16+
"collapsed": true
17+
},
18+
"outputs": [],
19+
"source": [
20+
"class Node(object):\n",
21+
" pass"
22+
]
23+
},
24+
{
25+
"cell_type": "code",
26+
"execution_count": null,
27+
"metadata": {
28+
"collapsed": true
29+
},
30+
"outputs": [],
31+
"source": [
32+
"# Create a Singly Linked List here"
33+
]
34+
},
35+
{
36+
"cell_type": "markdown",
37+
"metadata": {},
38+
"source": [
39+
"# Test Your Solution\n",
40+
"\n",
41+
"Note that there is no test for this solution (because it would give away the answer structure).\n",
42+
"\n",
43+
"Check out the Implement a Linked List Solution Notebook for the answer to this interview problem, as well as the answer for the implementation of a doubly linked list."
44+
]
45+
}
46+
],
47+
"metadata": {
48+
"kernelspec": {
49+
"display_name": "Python 2",
50+
"language": "python",
51+
"name": "python2"
52+
},
53+
"language_info": {
54+
"codemirror_mode": {
55+
"name": "ipython",
56+
"version": 2
57+
},
58+
"file_extension": ".py",
59+
"mimetype": "text/x-python",
60+
"name": "python",
61+
"nbconvert_exporter": "python",
62+
"pygments_lexer": "ipython2",
63+
"version": "2.7.11"
64+
}
65+
},
66+
"nbformat": 4,
67+
"nbformat_minor": 0
68+
}
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,186 @@
1+
{
2+
"cells": [
3+
{
4+
"cell_type": "markdown",
5+
"metadata": {},
6+
"source": [
7+
"# Linked List Nth to Last Node \n",
8+
"\n",
9+
"## Problem Statement\n",
10+
"Write a function that takes a head node and an integer value **n** and then returns the nth to last node in the linked list. For example, given:"
11+
]
12+
},
13+
{
14+
"cell_type": "code",
15+
"execution_count": 1,
16+
"metadata": {
17+
"collapsed": true
18+
},
19+
"outputs": [],
20+
"source": [
21+
"class Node:\n",
22+
"\n",
23+
" def __init__(self, value):\n",
24+
" self.value = value\n",
25+
" self.nextnode = None"
26+
]
27+
},
28+
{
29+
"cell_type": "markdown",
30+
"metadata": {},
31+
"source": [
32+
"**Example Input and Output:**"
33+
]
34+
},
35+
{
36+
"cell_type": "code",
37+
"execution_count": 6,
38+
"metadata": {
39+
"collapsed": false
40+
},
41+
"outputs": [],
42+
"source": [
43+
"a = Node(1)\n",
44+
"b = Node(2)\n",
45+
"c = Node(3)\n",
46+
"d = Node(4)\n",
47+
"e = Node(5)\n",
48+
"\n",
49+
"a.nextnode = b\n",
50+
"b.nextnode = c\n",
51+
"c.nextnode = d\n",
52+
"d.nextnode = e\n",
53+
"\n",
54+
"# This would return the node d with a value of 4, because its the 2nd to last node.\n",
55+
"target_node = nth_to_last_node(2, a) "
56+
]
57+
},
58+
{
59+
"cell_type": "code",
60+
"execution_count": 7,
61+
"metadata": {
62+
"collapsed": false
63+
},
64+
"outputs": [
65+
{
66+
"data": {
67+
"text/plain": [
68+
"4"
69+
]
70+
},
71+
"execution_count": 7,
72+
"metadata": {},
73+
"output_type": "execute_result"
74+
}
75+
],
76+
"source": [
77+
"target_node.value"
78+
]
79+
},
80+
{
81+
"cell_type": "markdown",
82+
"metadata": {},
83+
"source": [
84+
"## Solution\n",
85+
"Fill out your solution below:"
86+
]
87+
},
88+
{
89+
"cell_type": "code",
90+
"execution_count": 1,
91+
"metadata": {
92+
"collapsed": true
93+
},
94+
"outputs": [],
95+
"source": [
96+
"def nth_to_last_node(n, head):\n",
97+
"\n",
98+
" pass"
99+
]
100+
},
101+
{
102+
"cell_type": "markdown",
103+
"metadata": {},
104+
"source": [
105+
"# Test Your Solution"
106+
]
107+
},
108+
{
109+
"cell_type": "code",
110+
"execution_count": 9,
111+
"metadata": {
112+
"collapsed": false
113+
},
114+
"outputs": [
115+
{
116+
"name": "stdout",
117+
"output_type": "stream",
118+
"text": [
119+
"ALL TEST CASES PASSED\n"
120+
]
121+
}
122+
],
123+
"source": [
124+
"\"\"\"\n",
125+
"RUN THIS CELL TO TEST YOUR SOLUTION AGAINST A TEST CASE \n",
126+
"\n",
127+
"PLEASE NOTE THIS IS JUST ONE CASE\n",
128+
"\"\"\"\n",
129+
"\n",
130+
"from nose.tools import assert_equal\n",
131+
"\n",
132+
"a = Node(1)\n",
133+
"b = Node(2)\n",
134+
"c = Node(3)\n",
135+
"d = Node(4)\n",
136+
"e = Node(5)\n",
137+
"\n",
138+
"a.nextnode = b\n",
139+
"b.nextnode = c\n",
140+
"c.nextnode = d\n",
141+
"d.nextnode = e\n",
142+
"\n",
143+
"####\n",
144+
"\n",
145+
"class TestNLast(object):\n",
146+
" \n",
147+
" def test(self,sol):\n",
148+
" \n",
149+
" assert_equal(sol(2,a),d)\n",
150+
" print 'ALL TEST CASES PASSED'\n",
151+
" \n",
152+
"# Run tests\n",
153+
"t = TestNLast()\n",
154+
"t.test(nth_to_last_node)"
155+
]
156+
},
157+
{
158+
"cell_type": "markdown",
159+
"metadata": {},
160+
"source": [
161+
"## Good Job!"
162+
]
163+
}
164+
],
165+
"metadata": {
166+
"kernelspec": {
167+
"display_name": "Python 2",
168+
"language": "python",
169+
"name": "python2"
170+
},
171+
"language_info": {
172+
"codemirror_mode": {
173+
"name": "ipython",
174+
"version": 2
175+
},
176+
"file_extension": ".py",
177+
"mimetype": "text/x-python",
178+
"name": "python",
179+
"nbconvert_exporter": "python",
180+
"pygments_lexer": "ipython2",
181+
"version": "2.7.11"
182+
}
183+
},
184+
"nbformat": 4,
185+
"nbformat_minor": 0
186+
}

0 commit comments

Comments
 (0)