-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathamazonRound2.js
90 lines (64 loc) · 1015 Bytes
/
amazonRound2.js
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
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
[
{
query 1
},
{
query2 2
},
{
},
{
}
]
///////////////////////////
16 MB
{
arr : [
{} ,{}
]
}
//////////////////////////
{
},
{
}
//A man is walking up a set of stairs. He can either take 1, 2 or 3 steps at a time.
//Given n number of stairs, find out how many combinations of steps he can take to reach the top of the stairs.
// n = 5
// 3, 2 or 2, 3 or
// n = 4
n = 1
1
f(1) = 1
n = 2
1,1 or 2 -> f(2) = 2
n = 3
1,1,1 or 1,2 or 2,1 or 3
f(3) = 4
n = 4
f(4-1) + f(1) +
f(4-2) + f(2) +
f(4-3) + f(3)
n = 5
f(n-1) + f(n-2) + f(n-3)
// 1, 3 or 3, 1
// 1, 1, 1, 1 or 1, 1, 2, or 2, 1, 1, or 2, 2
// 6
// n = 3
// 1,1,1 or 1, 2 or 2, 1 or 3
// 4
// n = 2
// 1, 1 or 2
// 2
// n = 1
// 1
// stepValue == n value
table[row][col] = table[row][col-1] +1
// step value > n vlaue
table[row][col] = table[row][col-1]
//
space O(N values)(steps values)
time O(N values)(steps values)
sn = 4
steps = {1, 2, 3}
O(4*3)