Check if a string can be split into substrings starting with N followed by N characters

Given a string str, the task is to check if it can be split into substrings such that each substring starts with a numeric value followed by a number of characters represented by that numeric integer.

Examples:

Input: str = “4g12y6hunter”
Output: Yes
Explanation:
Substrings “4g12y” and “6hunter” satisfy the given condition

Input: str = “31ba2a”
Output: No
Explanation:
The entire string cannot be split into substrings of desired types

Approach: