I have a collection of sets in the format (a,b) which are as follows:
(2,4) (1,3) (4,5) (1,2)
If I am given a pair like <2,1>, I want to identify all sets in the collection where 2 or 1 is the first element. In this case, it would be (2,4), (1,3), and (1,2) and then determine the maximum value for the second element, so here it would be 4.
What is the most efficient way to achieve this?
My initial approach was to extract all 'a' values from the sets, intersect them with <2,1>, and then find the max value of 'b'. However, this method may not perform well with larger datasets. Additionally, we can consider restructuring the data or performing preprocessing if necessary.
I am using plain JavaScript, and my data is stored as arrays of tuples or objects with two integer properties.
Thank you for any suggestions!