Task 5 — Configurable Range Grouping
Objective
Create a function that first selects integer values inside a configurable search range and then separates those values into three groups using two additional split boundaries.
The resulting groups must contain only values that satisfy the search boundaries.
Values inside each group must be sorted in ascending order.
Input
The function has five input arguments.
Conceptually:
CreateGroups(
list,
lowerBoundary,
higherBoundary,
firstSplit,
secondSplit,
)
First Argument — Input Values
The first argument is:
[]int
Example:
list := []int{
6, 45, 17, 81, 32,
55, 95, 50, 24, 72,
62, 38, 28, 68, 33,
89, 11, 49, 77, 99,
}
Second Argument — Lower Boundary
The second argument is an int representing the lower search boundary.
The original task defines the possible values as:
20
30
Third Argument — Higher Boundary
The third argument is an int representing the higher search boundary.
The original task defines the possible values as:
80
90
Together, the second and third arguments define which values from the input collection are eligible for grouping.
Fourth Argument — First Split Boundary
The fourth argument defines the upper boundary of the first result group.
The original task defines the possible values as:
40
60
Fifth Argument — Second Split Boundary
The fifth argument defines the upper boundary of the second result group.
The original task defines the possible values as:
50
70
The second split boundary also determines where the third group begins.
Grouping Rules
After applying the lower and higher search boundaries, the selected values must be divided into three groups.
Given:
firstSplit = 40
secondSplit = 70
the groups are:
Group 1
value <= 40
Group 2
value > 40 && value <= 70
Group 3
value > 70
Only values that already satisfy the lower and higher search boundaries are considered for these groups.
Example
Given:
list := []int{
6, 45, 17, 81, 32,
55, 95, 50, 24, 72,
62, 38, 28, 68, 33,
89, 11, 49, 77, 99,
}
call:
CreateGroups(list, 30, 90, 40, 70)
The search boundaries are:
LowerBoundary = 30
HigherBoundary = 90
Therefore, values outside the selected search range are excluded before grouping.
The selected values are:
32
33
38
45
49
50
55
62
68
72
77
81
89
They are then divided using:
firstSplit = 40
secondSplit = 70
Group 1
Condition:
value <= 40
Result:
[]int{
32, 33, 38,
}
Group 2
Condition:
value > 40 && value <= 70
Result:
[]int{
45, 49, 50, 55, 62, 68,
}
Group 3
Condition:
value > 70
Result:
[]int{
72, 77, 81, 89,
}
Expected Result
[][]int{
{32, 33, 38},
{45, 49, 50, 55, 62, 68},
{72, 77, 81, 89},
}
Boundary Processing
The lower and higher boundaries define the values that are eligible for grouping.
For:
CreateGroups(list, 30, 90, 40, 70)
values below the lower boundary are excluded.
For example:
6
11
17
24
28
Values above the higher boundary are also excluded:
95
99
The remaining values are classified using the two split boundaries.
Requirements
The function must:
- receive the source
[]int - apply the lower and higher search boundaries
- exclude values outside the selected search range
- divide the remaining values into three groups
- use the fourth and fifth arguments as split boundaries
- sort the values inside every resulting group
- return the result as
[][]int
Boundary Validation
A valid configuration should maintain a logical relationship between the boundaries.
Conceptually:
lowerBoundary <= firstSplit
firstSplit < secondSplit
secondSplit <= higherBoundary
This ensures that the three grouping ranges remain inside the selected search interval.
The original task provides predefined possible values that produce valid configurations, but does not explicitly define behavior for invalid combinations.
An implementation should validate or reject invalid boundary configurations rather than silently producing ambiguous groups.
Inclusive and Exclusive Boundaries
The grouping rules explicitly define:
Group 1: value <= firstSplit
Group 2: value > firstSplit && value <= secondSplit
Group 3: value > secondSplit
The original example also demonstrates that values outside the lower and higher search boundaries are excluded.
The exact inclusive/exclusive wording for the outer search boundaries is not explicitly stated in the original text.
The implementation should therefore define this behavior consistently.
For the provided example, this distinction does not change the expected result because neither 30 nor 90 appears in the input collection.
Implementation Notes
The filtering stage and grouping stage represent two different operations.
Conceptually:
Input
↓
Apply search boundaries
↓
Eligible values
↓
Apply split boundaries
↓
Three groups
↓
Sort
↓
Result
Keeping these responsibilities logically separated can make the implementation easier to understand and test.
The implementation should work for all valid boundary combinations defined by the task and should not depend on the specific example values.