You are viewing a single comment's thread. Return to all comments →
Perl:
sub weightedUniformStrings { my ($s, $queries) = @_; my %weights; my $prev_char = ''; my $current_weight = 0; foreach my $char (split //, $s) { my $char_weight = ord($char) - ord('a') + 1; if ($char eq $prev_char) { $current_weight += $char_weight; } else { $current_weight = $char_weight; } $weights{$current_weight} = 1; $prev_char = $char; } my @results; foreach my $query (@$queries) { push @results, exists $weights{$query} ? "Yes" : "No"; } return @results; }
Seems like cookies are disabled on this browser, please enable them to open this website
Weighted Uniform Strings
You are viewing a single comment's thread. Return to all comments →
Perl: