Stock Analysis
Problem statement
In data analysis, the eliminate algorithm determines the single final value to use for each data parameter. The eliminate algorithm works in the following way:
- Data is acquired from multiple sources in order from least to most preferred, i.e if a parameter P is present in both source 1 and source 2, the parameter from the higher priority source, source 2, is used in the final parameter list, and any value from an earlier source is superseded.
- As new parameters arrive, they are added to the list.
- If a parameter P is present only in one of the sources, it is directly added to the final parameter list.
Hence,
- The result of performing the above operations until all parameters from source 1 and source 2 are exhausted is the result of Eliminate-algorithm(source 1, source 2).
- Each time a new value for a parameter is encountered from a higher preferred site, the old data is superseded.
-
Assuming three sources
S₁, S₂, S₃:-
Eliminate-algorithm(S₁, S₂, S₃) = Eliminate-algorithm (Eliminate-algorithm(S₁, S₂), S₃).
-
Given a list of sources S₁, S₂...Sₙ, find the final parameter list given by Eliminate-algorithm(S₁, S₂...Sₙ). Maintain your results in the order a key was first encountered.
For example, a rating parameter of buy, sell or hold from three sources in increasing order of preference: [buy, sell, hold], where buy is from S₁, immediately superseded by sell S₂, immediately superseded by hold S₃. The final rating is the only one that hasn't been superseded, so you use 'hold' as the final rating.
Function
computeParameterValue(sources: String[][]) → String[]
Complete the function computeParameterValue in the editor.
computeParameterValue has the following parameter(s):
-
String[][] sources: A 2-dimensional array of key: value pairs, each row is one source's data, sources presented from lowest to highest preference.
Examples
Example 1
sources = [["P1:a", "P3:b", "P5:x"], ["P1:b", "P2:q", "P5:x"]]return = ["b", "b", "x", "q"]Final parameter list:
- P1 b (Source 2)
- P3 b (Source 1)
- P5 x (Source 2)
- P2 q (Source 2)
Constraints
- 1 ≤ n < 100
- 1 ≤ p < 1000