Untitled

mail@pastecode.io avatar
unknown
python
a year ago
743 B
1
Indexable
Never
def checkSimilarPasswords(newPasswords, oldPasswords):
    def is_similar(new_password, old_password):
        i, j = 0, 0
        while i < len(new_password) and j < len(old_password):
            if new_password[i] == old_password[j]:
                i += 1
            j += 1
        return i == len(new_password)

    results = []
    for new_password, old_password in zip(newPasswords, oldPasswords):
        if is_similar(new_password, old_password):
            results.append("YES")
        else:
            results.append("NO")
    return results

# Test case
newPasswords = ["baacbab", "accdb", "baacba"]
oldPasswords = ["abdbc", "ach", "abb"]
print(checkSimilarPasswords(newPasswords, oldPasswords))  # Output: ["YES", "NO", "YES"]