def URLify_solution(input_string):
    """Same goal as URLify, but using more efficient solution from book.

    Same input and output as URLify.
    """
    # First, count number of spaces in string
    space_count = 0
    for char in input_string:
        if char == ' ':
            space_count += 1

    # Check that there are spaces
    if space_count == 0:
        return input_string

    # Turn input_string into char array, with extra space for the chars we will
    # add
    chars = list(input_string) + [None] * space_count * 2

    # Get index of last element in chars, which represents highest unused index
    # in chars array
    index = len(chars) - 1
    # Iterate through indices of original input_string, backwards
    for i in range(len(input_string) - 1, -1, -1):
        # If char is a space, insert '%20' into highest unused (not None) at
        # back of chars array
        if chars[i] == ' ':
            chars[index - 2: index + 1] = '%20'
            # Update highest unused index at back of chars array
            index -= 3

        # If char is not a space, insert char value into highest unused (not
        # None) at back of chars array
        else:
            chars[index] = chars[i]
            # Update highest unused index at back of chars array
            index -= 1

    return ''.join(chars)