Skip to content

From Small to BIGGER

Menu
  • Home
  • About Us
  • Portofolio
  • Contact
Menu

HackerRank – Min Max Sum

Posted on May 29, 2022January 16, 2023 by kura

Sample Input:
1 2 3 4 5

Sample Output:
10 14

<?php

function miniMaxSum($arr) {
    // Write your code here
    $tmp = $arr; 
    $result = []; 

    foreach ($arr as $key => $row) { 
        unset($tmp[$key]);
        $result[] = array_sum($tmp);
        $tmp = $arr;
    } 

    echo min($result) . ' ' . max($result);
}

$arr_temp = rtrim(fgets(STDIN));

$arr = array_map('intval', preg_split('/ /', $arr_temp, -1, PREG_SPLIT_NO_EMPTY));

miniMaxSum($arr);
FacebookTweetLinkedIn

Leave a Reply Cancel reply

Your email address will not be published. Required fields are marked *

Recent Posts

  • Laravel & Datatables – Server Side Manualy
  • Linux – User Login Set Directory & Set Permission
  • Javascript Call Function From iFrame
  • Python – Create data dummy attendance
  • PHPWord Convert HTML + PDF

Categories

  • Apache
  • Database
  • Freeradius
  • Javascript
  • Mikrotik
  • Mysql
  • Networking
  • PHP
  • Postgresql
  • Programming
  • Python
  • Server
©2025 From Small to BIGGER | Built using WordPress and Responsive Blogily theme by Superb