Standard Finite-State-Machine (FSM) Implementation - II
There are multiple ways to solve this problem, but I find a state machine implementation very intuitive, even if we have to leave some of the state transitions empty (no-op). The state manages whether you're in "same char" mode or "different char". Code is down below, cheers, ACC. Find Mismatched Segments Between Two Strings - LeetCode You are given two strings s1 and s2 of the same length. A mismatched segment is a maximal contiguous range of indices where the characters of s1 and s2 differ at every index. Return a 2D array containing [sub1, sub2] for each mismatched segment, where sub1 and sub2 are the corresponding substrings from s1 and s2 , respectively. Return the segments in increasing order of their starting indices. If there are no mismatched segments, return an empty array. A substring is a contiguous non-empty sequence of characters within a string. Example 1: Input: s1 = "earth", s2 = "empty" Output: [["ar...