sub twosum_NetWallah{ my ($inp, $target)=@_; my %targ_idx = map { $inp->[$_] => $_ } 0..$#$inp; for (0..$#$inp){ next unless defined ( my $other=$targ_idx{ $target - $inp->[$_] } ); next if $other == $_; return [ $other > $_ ? ($_, $other) : ($other, $_) ]; } return undef; } # Test NetWallah.. for my $test (@tests) { is_deeply sort_arrayref(twosum_NetWallah ($test->[INPUT], $test->[TARGET])), sort_arrayref($test->[EXPECTED]); } #### [[-5,-3,1,4,7], 1, [1,3]],