Leetcode

mail@pastecode.io avatar
unknown
python
a year ago
1.4 kB
7
Indexable
Never
# 1. Last and Second Last
def lastLatters(word: str) -> str:
    return f"{word[-1]}  {word[-2]}"


assert lastLatters("bat") == "t  a"
assert lastLatters("APPLE") == "E  L"


# 2. Eliminate Substring
def getFinalString(string: str) -> str:
    keyword = "AWS"
    while keyword in string:
        string = string.replace(keyword, "", 1)

    if string == "":
        return "-1"
    else:
        return string


assert getFinalString("AWAWSSG") == "G"
assert getFinalString("AAWSWS") == "-1"


# 3. Are they Pangrams
def isPangram(pangram: list[str]) -> str:
    return "".join(["1" if len(set(s)) == 27 else "0" for s in pangram])


assert isPangram(["pack my box with five dozen liquor jugs", "this is not a pangram"]) == "10"
assert (
    isPangram(
        [
            "we promptly judged antique ivory buckles for the next prize",
            "we promptly judged antique ivory buckles for the prizes",
            "the quick brown fox jumps over the lazy dog",
            "the quick brown fox jump over the lazy dog",
        ]
    )
    == "1010"
)
assert (
    isPangram(
        [
            "cfchcfcvpalpqxenhbytcwazpxtthjumliiobcznbefnofyjfsrwfecxcbmoafes tnulqkvx",
            "oxhctvhybtikkgeptqulzukfmmavacshugpouxoliggcomykdnfayayqutgwivwldrkp",
            "gpecfrak zzaxrigltstcrdyhelhz rasrzibduaqcnpuommogatqem",
            "hbybsegucruhxkebrvmrmwhweirx mbkluwhfapjtgaliiylfphmzkq",
        ]
    )
    == "0000"
)