Ad
  • Custom User Avatar

    Such a solution would pass the tests and be more efficient.
    But it wouldn't be correct by the requirements: "Return None if it is not possible to define only one of such values".
    So if the array is [5, 3, 3, 1] we should return 1 as closest to zero and we can only do that if we cover the whole array.
    If we stop for any number at equal distance to the current closest to zero we would stop for 3 and return None.
    It's what dinglemouse complains about at my first solution that did what you suggested.