I have the following objects defined:
public class MyGroup
{
public MyItem[] Items;
}
public class MyItem
{
public int Val;
}
Say I have a list as List where each MyGroup object contains a varying number of MyItems; which in turn contains a varying value for Val.
How can I find the subset of MyGroup objects that contains the lowest Val across all MyGroup objects.
E.g:
If I define the list with following values
- MyGroup1 contains a MyItem for each of the following values: 1, 5 and
7 - MyGroup2 contains a MyItem for each of the following values: 3 and,
8 - MyGroup3 contains a MyItem for each of the following values: 2, 4,
5 and, 7
Then the returned value will be MyGroup1 (as a single item list) because it contains the value 1 which is the lowest across all values.
However, if there are multiple values with the lowest value like:
- MyGroup1 contains a MyItem for each of the following values: 1, 5 and 7
- MyGroup2 contains a MyItem for each of the following values: 3 and, 8
- MyGroup3 contains a MyItem for each of the following values: 1, 4, 5 and, 7
Then it will return MyGroup1 and MyGroup3 in a list.
Thanks in advance.
This will be a two pass algorithm. If you were suitably motivated you could do it in a single pass by keeping track of all of the items containing the min value while searching for that min value.