Ice Cream Parlor

  • + 0 comments

    Mega easy Perl solution:

    sub icecreamParlor {
        my $m = shift;
        my $arr = shift;
    
        my @res_arr;
    
        for (my $i = 0; $i < scalar(@$arr); $i++){
            for (my $j = $i + 1; $j < scalar(@$arr); $j++) {
                if ($m == ($arr->[$i] + $arr->[$j])) {
                    push(@res_arr, $i+1, $j+1);
                    return sort {$a <=> $b} @res_arr;
                }
                
            }
        }
    }