diff options
-rw-r--r-- | entries/kevindhir/aws/Solution.java | 21 | ||||
-rw-r--r-- | entries/kevindhir/ts/fib.ts | 8 | ||||
-rw-r--r-- | people.json | 15 |
3 files changed, 44 insertions, 0 deletions
diff --git a/entries/kevindhir/aws/Solution.java b/entries/kevindhir/aws/Solution.java new file mode 100644 index 0000000..602d1b1 --- /dev/null +++ b/entries/kevindhir/aws/Solution.java @@ -0,0 +1,21 @@ +package entries.kevindhir.aws; + +import java.util.Arrays; + +class Solution { + public int fib(int N) { + int[] storage = new int[9999]; + Arrays.fill(storage, -1); + storage[0] = 0; + storage[1] = 1; + return fibMemoized(N, storage); + } + + private int fibMemoized(int N, int[] storage){ + if (storage[N] != -1) return storage[N]; + int calculated = fibMemoized(N-1, storage) + fibMemoized(N-2, storage); + storage[N] = calculated; + return calculated; + } + +}
\ No newline at end of file diff --git a/entries/kevindhir/ts/fib.ts b/entries/kevindhir/ts/fib.ts new file mode 100644 index 0000000..f126a8b --- /dev/null +++ b/entries/kevindhir/ts/fib.ts @@ -0,0 +1,8 @@ +let memo = {1: 1}; + +function fib(n: number): number { + if(n <= 0) return 0; + if(memo[n]) return memo[n]; + memo[n] = fib(n-1) + fib(n-2); + return memo[n]; +}; diff --git a/people.json b/people.json index 38744c3..b2a3b69 100644 --- a/people.json +++ b/people.json @@ -118,6 +118,21 @@ ] }, { + "github": "kevindhir", + "name": "Kevin Dhir", + "title": "BCom, UBC", + "entries": [ + { + "name": "online-assessment", + "link": "./entries/kevindhir/aws/Solution.java" + }, + { + "name": "ts", + "link": "./entries/kevindhir/ts/fib.ts" + } + ] + }, + { "github": "rctcwyvrn", "name": "Lily Lin", "title": "BSc, UBC", |