
You are given two strings, s1 and s2, which are guaranteed to be of the same length.
Your task is to compare these two strings character by character and identify all the positions (indices) where they differ. You need to return a list of these 0-indexed positions.
The first line of input contains the string s1.
The second line of input contains the string s2.
Print a single line containing the 0-indexed positions where the characters differ, sorted in ascending order and separated by single spaces.
If the two strings are identical (no mismatches), print a single line with the value -1.
The comparison is case-sensitive. 'a' and 'A' are considered different.
The strings are guaranteed to have the same length.
apple
apply
4
Comparing "apple" and "apply":
- Index 0: 'a' == 'a' (Match)
- Index 1: 'p' == 'p' (Match)
- Index 2: 'p' == 'p' (Match)
- Index 3: 'l' == 'l' (Match)
- Index 4: 'e' != 'y' (Mismatch)
The only mismatch occurs at index 4.
test
test
-1
The strings are identical. Since there are no mismatches, the output is -1.
The expected time complexity is O(N), where N is the length of the strings.
1 <= length of s1, s2 <= 10^5
s1.length == s2.length
Time limit: 1 sec