You are viewing a single comment's thread. Return to all comments →
Perl:
sub workbook { my ($n, $k, $arr) = @_; my @tmp; my $cnt = 0; my $j = 0; for (my $i = 0; $i < scalar(@$arr); $i++) { if ($arr->[$i] > $k) { for ($j = 1; $j <= $arr->[$i] - ($arr->[$i] % $k); $j += $k) { push(@tmp, [ $j..$j + $k - 1]); } push(@tmp, [$j..$arr->[$i]]) if ($arr->[$i] % $k != 0); } else { push(@tmp, [1..$arr->[$i]]); } } for (my $i = 0; $i <scalar(@tmp); $i++) { $cnt += grep { $_ == $i + 1} @{$tmp[$i]}; } return $cnt; }
Seems like cookies are disabled on this browser, please enable them to open this website
An unexpected error occurred. Please try reloading the page. If problem persists, please contact support@hackerrank.com
Lisa's Workbook
You are viewing a single comment's thread. Return to all comments →
Perl: