Show previous contentFinally-- if at any time, we encounter a mismatch, we know it's an invalid string.The time complexity is O(n), as we iterate through all the characters of the string. Show following content