String Mismatch Finder

Easy
0/40
1 upvote
Asked in company
EPAM Systems

Problem statement

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.


Detailed explanation ( Input/output format, Notes, Images )
Input Format:
The first line of input contains the string s1.

The second line of input contains the string s2.


Output Format:
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.


Note:
The comparison is case-sensitive. 'a' and 'A' are considered different.

The strings are guaranteed to have the same length.
Sample Input 1:
apple
apply


Sample Output 1:
4


Explanation for Sample 1:
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.


Sample Input 2:
test
test


Sample Output 2:
-1


Explanation for Sample 2:
The strings are identical. Since there are no mismatches, the output is -1.


Expected Time Complexity:
The expected time complexity is O(N), where N is the length of the strings.


Constraints:
1 <= length of s1, s2 <= 10^5
s1.length == s2.length

Time limit: 1 sec
Approaches (1)
Time Complexity
Space Complexity
Code Solution
(100% EXP penalty)
String Mismatch Finder
Full screen
Console