# Problem Description
The problem requires us to determine the minimum number of steps needed to convert one string (`str1`) to another string (`str2`). Each step involves changing the first lowercase character in the string to its corresponding uppercase character. If the conversion is not possible, the function should return -1.

# Visual Facts
1. **Initial Strings**: Each example starts with an initial string that contains a mix of uppercase and lowercase letters.
2. **Step-by-Step Conversion**: Each step involves converting the first lowercase letter in the string to its uppercase form.
3. **Final Strings**: The process continues until the string matches the target string or all characters are uppercase.
4. **Number of Steps**: The number of steps is equal to the number of lowercase letters in the initial string that need to be converted to match the target string.

# Visual Patterns
1. **First Lowercase Conversion**: In each step, only the first lowercase letter from the left is converted to uppercase.
2. **Sequential Steps**: The steps are sequential, meaning each step builds on the previous one by converting the next lowercase letter.
3. **Matching Target String**: The process stops once the string matches the target string.
4. **Step Count**: The number of steps required is equal to the number of lowercase letters in the initial string that need to be converted to match the target string.
5. **Impossibility Condition**: If the target string has more uppercase letters than the initial string can provide through conversion, the conversion is impossible.

Based on these observations, the function needs to:
1. Iterate through the initial string, converting the first lowercase letter to uppercase in each step.
2. Count the number of steps taken.
3. Check if the resulting string matches the target string after each step.
4. Return the number of steps if the conversion is successful, or -1 if it is not possible.

# Solution
def solution(str1: str, str2: str) -> int:
    """
    Returns the minimum number of steps needed to convert the first string to the second string.
    Returns -1 if the conversion is not possible.

    Parameters:
        str1 (str): The source string to convert from
        str2 (str): The target string to convert to

    Returns:
        int: Minimum number of steps required for the conversion, or -1 if not possible
    """
    def find_first_lower(str1):
        for i in range(len(str1)):
            if str1[i].islower():
                # change to the upper case

                str1 = str1[:i] +str1[i].upper() + str1[i+1:]
                return str1
        return -1

    if len(str1) != len(str2):
        return -1
    for i in range(len(str1)):
        str1 = find_first_lower(str1)
        if str1 == -1:
            break
        if str1 == str2:
            return i + 1
    return -1


# Test Script
def test():
    test_cases = [
        ("openai", "OPenai", 2),
        ("openai", "Openai", 1),
        ("ababa", "ABaba", 2),
        ("aBaAa", "ABAAa", 2),
        ("aBaAb", "ABAAB", 3),
        ("Trump","Susan", -1),
        ("Trump","trump", -1),
        ("Trump","TRUMP", 4),
        ("abacbv","ABACbv", 4),
        ("oPenAI", "OPEnAI", 2)
    ]

    for str1, str2, expected_output in test_cases:
        try:
            output = solution(str1, str2)
        except Exception as e:
            error_message = (
                f"An exception occurred while running the test case:\n"
                f"`str1`: {str1}\n"
                f"`str2`: {str2}\n\n"
                f"Exception: '{str(e)}'"
            )
            assert False, error_message
            
        if output != expected_output:
            error_message = (
                f"The following Test Case failed:\n"
                f"`str1`: {str1}\n"
                f"`str2`: {str2}\n\n"
                f"Actual Output: {output}\n"
                f"Expected Output: {expected_output}"
            )
            assert False, error_message

test()