- Prereq Node and NPM are installed
- Extract Files to Drive
- Run
npm install
- Run
npm start
- Follow instructions on screen
Identify any drug to drug interaction that might occur based in a set of inputs
- Allow for command line input that can potentially have multiple drugs per line
- Allow for multiple lines per execution (Need a closing key -- maybe a double line break?)
- Allow for case-insensitive inputs
- Must return most Major severity
- There is a 4th severity called
contraindication
which is synonymous tomajor
- Ignore duplicates
- The interactions.json file is free of any duplicates and is objectively correct
- What happens when multiple major severity is found with the input combination, do we just show 1 or show all of them?
Step 1: Preprocessing
Upon the starting of the application, we should preprocess the data included in the interactions.json
in order to create a hashmap/dict that points to the array index for quick lookups. The time this will take is O(n), with n as # of objects in the interactions array.
Hashmap Structure
{
wordA: int[],
wordB: int[],
wordAwordB: int,
...
}
Hashmap will have a worst-case space complexity of O(3n) given that we need to store the individual drug as well as the pair combination.
Step 2: Input Processing
Since the input is not always a fixed length, it will add complexity to our solution. In order to accommodate min=1;max=20 input, we will need a quick and efficient way to find all relevant information based on the given input and to skip any potential duplicate.
Given the format is word1 word2 word3 word4 ... wordn
We will need to do pair-processing such that: word1word2 word1word3 word1word4 ... word1wordn
In the preprocessing step, we needed to pre-sort the key which will eliminate any variances based on word permutation. With that important key concept in mind, we can also pre-sort the input line/row to the same effect. This will provide 2 benefits:
- Support for variances/permutations
- Skips duplicate work
Assuming that all words are unique, then no duplicate work is done. If words are not unique, then there will be duplicate work. Best way to combat this is to pre-sort the input and then any duplicates will be next to each other. A duplicate is identified such that word[i] === word[i-1] ? skip : continue
Step 3: Lookup
We have our pair, the lookup should be simple thanks to our hashmap. For each pair, do a hashmap lookup, and depending on severity, we can modify the return output.
There's one of two ways we can have a efficient return:
- A simple POJO with key = severity; val = string[]
- A array that is kept pre-sorted with quick-insertion (pivot)
For the sake of time, the simpler way is Option #1 but shall we run into performance bottlenecks, we can use Option #2.
Step 4: Display Results
sildenafil
sildenafil thalidomide ibuprofen zopiclone nitroglycerin
sil
Sildenafil NitrogLYCERIN
$%^
sildenafil sildenafil
Caching We can potentially cache previous answers since if we know we've seen this pair before in the new combination. Since we are only looking at the most severe reaction, we can cache these answers and retrieve them whenever the pair in the permutation has been detected.