from typing import Optional
from typing import List


def merge_dictionaries(a: dict, b: dict, path: Optional[List[str]] = None) -> dict:
    """ Merges dictionary b into a, prefering keys in b over keys in a.

    Args:
        a: The destination dictionary
        b: The source dictionary
        path: The full path in the destination dictionary (for recursion)

    Returns:
        merged: The merged dictionaries
    """

    if path is None:
        path = []
    for key in b:
        if key in a:
            if isinstance(a[key], dict) and isinstance(b[key], dict):
                merge_dictionaries(a[key], b[key], path + [key])
            elif a[key] == b[key]:
                pass
            else:
                a[key] = b[key]
        else:
            a[key] = b[key]
    return a