The solutions are wtih file name question-1.js
, question-2.js
and question-3.js
This solution O(2n) with n is record's length.
- This solution O(n) with n is total users while get
totalPlayerByStages
. - This solution O(n) with n is total stages (N) while get
failureRateByStages
. - This solution O(n) with n is total stages (N) while map list of stages.
- I don't know time complexity for sort function
- Maybe for this case I think more efficient with looping, with lopping 'easier' to cache / memoize, but I think it will hard to naming and validate the rule, so for this solution I separate unique column and non unique column.
- After separate change non unique column to unique column with combine / join value for each two column, with minimality rule, I think / intepret it just needs two key to candidates key, e.g:
[
[
'COL#2 - COL#3',
'ryan - music',
'apeach - math',
'tube - computer',
'con - computer',
'muzi - music',
'apeach - music'
],
[
'COL#2 - COL#4',
'ryan - 2',
'apeach - 2',
'tube - 3',
'con - 4',
'muzi - 3',
'apeach - 2'
],
...
]
- Using this new column list / matrix we just need check unique column.
- This solution O(n) with n is total rows, when to get list of value by column, for each array I set COL#i with i is index column started 1 to columns length, I need this as array to simplify the process instead of as object with column inex as key / property.
- Then O(n) with n is total columns, when separate uniqueColumnNames and nonUniqueColumns.
- Then O(n!) with n is total non unique column, when get joined columns to make easier check unique or not.
- Then O(n) with n is total joined columns, when get unique columns to get relation keys for candidate besides column name from unique keys that get in step 2, because I use the function that same in step-2 I sacriface space complexity because actually we didn't need non uniques columns in step-5
- Actually because I want to make it same with example, although that needed is just total cadidate key, and I wanted to simplify filter and map by using reduce, the code is not sweet as before, you can jump to https://github.com/detikpw/take-home-test/commit/80437c059207c517cbee69cb1e24bacdc4c5a574
- Already tested using Firefox 85.0.2 (64-bit) and google chrome Version 76.0.3809.100 (Official Build) (64-bit), for node js minimum version is 12
- Just ignore generator js, It just needed to make dummy records and relation for question#1 and qustion#3 with break some limitation in each question, and I want to test faker js and snapshot test