Clip Values

EasyMachine LearningArray

Description

Given an array and a lower and upper bound, clip every value into the [lower, upper] range: values below the lower bound become the lower bound and values above the upper bound become the upper bound.

Examples

Input:[1,5,-3,8], 0, 5
Output:[1,5,0,5]
Explanation:

Anything under the lower bound is pulled up to it and anything over the upper bound is pulled down to it, leaving in-range values untouched.

Input:[-1,2,3], 1, 2
Output:[1,2,2]
Explanation:

Anything under the lower bound is pulled up to it and anything over the upper bound is pulled down to it, leaving in-range values untouched.

Input:[5,5], 0, 10
Output:[5,5]
Explanation:

Anything under the lower bound is pulled up to it and anything over the upper bound is pulled down to it, leaving in-range values untouched.

Constraints

  • 1 ≤ length ≤ 10⁴
  • lower ≤ upper

Ready to solve this problem?

Practice solo and sharpen your skills for technical interviews.