from typing import Dict
from typing import Any
from typing import List
from typing import Optional


def get_sub_schema(schema: Dict[Any, Any], keys: List[str]) -> Optional[Dict[Any, Any]]:
    """Retrieve subschema for nested object types."""
    sub_schema = schema
    for key in keys:
        try:
            if sub_schema["type"] == "object":
                sub_schema = sub_schema["properties"][key]
            elif sub_schema["type"] == "array":
                sub_schema = sub_schema[key]
        except KeyError:
            return None

    return sub_schema