Task 3 — Fixed Range Grouping
Objective
Create a function that separates a collection of integers into three groups according to predefined numeric ranges.
The values inside each resulting group must be sorted in ascending order.
Input
The input slice contains:
list := []int{
20, 40, 10, 50, 80,
60, 90, 70, 30, 100,
}
Result Type
The result must be:
[][]int
containing exactly three groups.
Grouping Rules
Group 1
The first group contains values:
value <= 30
Group 2
The second group contains values:
value > 30 && value <= 60
Group 3
The third group contains values:
value > 60 && value <= 100
Requirements
Process every value from the input slice.
For each value:
- determine which range it satisfies
- place it into the corresponding group
- sort the values inside each group in ascending order
The result must preserve the group order:
Group 1
Group 2
Group 3
Example
Given:
list := []int{
20, 40, 10, 50, 80,
60, 90, 70, 30, 100,
}
the values are classified as:
Group 1:
10, 20, 30
Group 2:
40, 50, 60
Group 3:
70, 80, 90, 100
Expected Result
[][]int{
{10, 20, 30},
{40, 50, 60},
{70, 80, 90, 100},
}
Values Outside the Defined Range
The original task defines the third group only up to and including 100:
value > 60 && value <= 100
It does not specify how values greater than 100 should be handled.
It also does not explicitly define a lower boundary for the first group, so values below zero still satisfy:
value <= 30
An implementation should preserve these stated range rules unless additional validation requirements are introduced.
Implementation Notes
The implementation should not depend on the original ordering of the input values.
The final values inside each group must be sorted.
The task can be approached by grouping first and sorting afterward, or by maintaining sorted groups while processing the input.
The choice of algorithm is left to the developer.