Feature Range Validation
~15 mincode completion
Implement validate_ranges(X, schema) returning a list of violation dicts.
Examples
One value above max: single violation returned
- Input
- validate_ranges([[1, 200], [3, 4]], [{"max": 5, "min": 0}, {"max": 100, "min": 0}])
- Output
- [{"col": 1, "row": 0, "value": 200}]
All values in range: empty violation list
- Input
- validate_ranges([[0.5, 0.5], [0.1, 0.9]], [{"max": 1, "min": 0}, {"max": 1, "min": 0}])
- Output
- []
Value exactly at boundary is valid (inclusive bounds)
- Input
- validate_ranges([[0, 1]], [{"max": 1, "min": 0}, {"max": 1, "min": 0}])
- Output
- []
Hints
Hint 1
gives you the index and the value together.
Hint 2
Watch for this: used exclusive bounds flagging boundary values.
Requirements
X: 2D list or array of shape (n, d)schema: List of d dicts, each with keys "min" and "max"Return List of {"row": int, "col": int, "value": float} dicts in row-major order.
Constraints
Standard library only, no imports required
Time limit: 200 ms, Memory: 64 MB
Where this shows up
~15 min
••••••••••••••••
8 employers weight this skill
3 big tech firms, 2 enterprise vendors, 1 defense company, 1 AI product company, 1 health and bio company. Top match scores 87.
Python
def validate_ranges(X: list, schema: list) -> list:
"""
Find all out-of-range values in X given per-column min/max schema.
Args:
X: 2D list or array of shape (n, d)
schema: List of d dicts, each with keys "min" and "max"
Returns:
List of {"row": int, "col": int, "value": float} dicts in row-major order.
"""
# YOUR CODE HERE
pass