• + 0 comments

    Perl:

    sub twoStrings {
        my @str1 = split("", shift);
        my @str2 = split("", shift);
        my %h;
        for (my $k = 0; $k <= scalar(@str1) - 1; $k++) {
            $h{$str1[$k]} = 0;
        }
        for (my $i = 0; $i <= scalar(@str2) - 1; $i++) {
            if (exists($h{$str2[$i]})) {
                return "YES";
            }
            
        }
        return "NO";
    }