• + 46 comments

    A simple DP approach works. For example, a = "aBbdD" b = "BBD" since the last character in a is upper case and last character in b is also upper case and both are equal, f(a,b) = f("aBbd","BB")

    Now d can never be made equal to B therfore- f("aBbd","BB") = f("aBb","BB")

    Now b can be capitalized to B,therfore we have two options - either capitalize b to B or dont capitalize b. f("aBb","BB") = f("aB","B") or f("aB","BB") #Note that this is the 'or' operator. f is a boolean value.

    if we have something like a = 'C' and b = 'D' then f(a,b) evaluates to False (boolean value).

    Lastly (for initialization of the dp array)-

    if a is non-empty and b is empty, then f(a,b) is True only if all the characters in a are lower case.

    if a is empty and b is non-empty, then f(a,b) is always False.

    if both are empty then f(a,b) = True

    Good Luck !!