Ad
  • Custom User Avatar

    Below Powershell 7.2 answer should work. Returns the correct answer locally, but returns 0 on here.

    function maxTriSum ([int[]]$numbers)
    {
      [int[]]$intArray = @()
      
      $numbers = $numbers | sort -descending
      
      for($i=0;$i -lt $numbers.length -and $intArray.length -lt 3;$i++)
      {
        if($numbers[$i] -ne $numbers[$i -1])
        {
          $intArray += $numbers[$i]
        }
      }
      
      return ($intArray | Measure-Object -sum).sum
    }