forked from JimmyJimJamJamvilleJam/fa18-hw-ref
-
Notifications
You must be signed in to change notification settings - Fork 0
/
hw3.py
75 lines (59 loc) · 1.44 KB
/
hw3.py
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
"""
matrix_multiply
Given two 2-D input arrays `arr0`, `arr1`, return the matrix product arr0 * arr1.
Return None if the matrix product does not exist.
As with math, assume that indices are in [row][column] format, so each inner list is a row.
"""
def matrix_multiply(arr0, arr1):
pass
"""
nth_largest_element
Given an input list `arr`, and index `n`, return the nth largest element.
Avoid using built-in sorting methods.
"""
def nth_largest_element(arr, n):
pass
"""
reverse_block
Given an input list `arr`, and a block size `n` > 0, reverse the list in blocks of n.
Example:
Arguments:
[1,2,3, 4,5,6, 7], 3
Return:
[3,2,1, 6,5,4, 7]
(spacing added for emphasis)
"""
def reverse_block(arr, n):
pass
"""
subset_sum
Given an input list `arr`, and a number `target`, return whether or not any possible subset of the values in `arr` could sum to `target`.
Example 1:
Arguments:
[1,2,3,4,5,7], 13
7 + 4 + 2 = 13
Return:
True
Example 2:
Arguments:
[1,2,-1,5,4,-196], 196
Return:
False
"""
def subset_sum(arr, target):
pass
"""
spiral_matrix
Given an input 2-D array, return a list with the values obtained by following a clockwise spiral path, starting from [0][0], then proceeding to [0][n], [m][n], [m][0], then going inwards:
Example:
Argument:
[[a,b,c,d,e],
[f,g,h,i,j],
[k,l,m,n,o],
[p,q,r,s,t],
[u,v,w,x,y]]
Return:
[a,b,c,d,e, j,o,t,y, x,w,v,u, p,k,f, g,h,i, n,s, r,q, l, m]
"""
def spiral_matrix(arr):
pass