You are viewing a single comment's thread. Return to all comments →
Perl solution:
sub hackerrankInString { my $str = shift; my @s = split("", $str); my @t = split("", "hackerrank"); my $pos = -1; my @res_arr; for (my $i = 0; $i <= scalar(@t) - 1; $i++) { for (my $j = 0; $j <= scalar(@s) - 1; $j++) { if ($t[$i] eq $s[$j] && $pos < $j) { $pos = $j; push(@res_arr, $s[$j]); last; } } } if (join("", @res_arr) eq "hackerrank") { return "YES"; } else { return "NO"; } }
Seems like cookies are disabled on this browser, please enable them to open this website
HackerRank in a String!
You are viewing a single comment's thread. Return to all comments →
Perl solution: