Skip to content

Instantly share code, notes, and snippets.

@zeuschild
zeuschild / Answer4.md
Created September 10, 2017 12:41
Oursky Developer Pre-Test

//createArrayOfFunctions

function createArrayOfFunctions(y) {

var arr = [];

for(var i = 0; i<y; i++) {

arr[i] = function(x) { return x + i; }

@zeuschild
zeuschild / Answer3.cpp
Created September 10, 2017 07:40
Oursky Developer Pre-Test
// Write a function that takes an array of integers as input. For each integer, output the next
// fibonacci number.
// Fibonacci number of Fn is defined by:
// Fn = Fn-1 + Fn-2
// F1 = 1, F2 = 1
// Your program should run correctly for the first 60 Fibonacci Numbers.
// For example:
// nextFibonacci([1,9,22])
// Output:
// 2
@zeuschild
zeuschild / Answer2.md
Created September 10, 2017 07:15
Oursky Developer Pre-Test

The computational complexity of my answer in Question 1:

  1. Time complexity : O(n). I iterate the n elements vector two times. Because the look up time in map is O(1), the time complexity is O(n).
  2. Space complexity : O(n). The needed space is based on the elements number in the map, which is n.
@zeuschild
zeuschild / Answer1.cpp
Created September 10, 2017 07:14
Oursky Developer Pre-test
// Write a function that takes two arrays as input, each array contains a list of A-Z; Your program
// should return True if the 2nd array is a subset of 1st array, or False if not.
// For example:
// isSubset([A,B,C,D,E], [A,E,D]) = true
// isSubset([A,B,C,D,E], [A,D,Z]) = false
// isSubset([A,D,E], [A,A,D,E]) = true
bool isSubset(vector<int> &arr1, vector<int> &arr2) {
map<int,bool> m;