@itsik const means constant binding, not necessarily constant and not necessarily immutable - you can alter const variables but not reassign them.

res can start at anything >= nums.length since any subarray is going to be smaller than that and operate correctly with Math.min.