Search⌘ K
AI Features

Find the Difference

Understand how to find the index of the extra character in one string compared to another using bitwise manipulation. Explore efficient problem-solving methods involving strings and learn to implement your solution step-by-step in a hands-on coding environment.

Statement

Given two strings, str1 and str2, find the index of the extra character that is present in only one of the strings.

Note: If multiple instances of the extra character exist, return the index of the first occurrence of the character in the longer string.

Constraints:

  • 00 \leq str1.length, str2.length 1000\leq 1000
  • Either str2.length == str1.length + 1, or, str1.length == str2.length + 1
  • The strings consist of lowercase English letters.

Examples

Understand the problem

Let’s take a moment to make sure you’ve correctly understood the problem. The quiz below helps you check if you’re solving the correct problem:

Find the Difference

1.

Find the index of the extra character that is present in only one of the strings.

string 1 = “pqr”

string 2 = “psrq”

A.

0

B.

1

C.

2

D.

3


1 / 3

Figure it out!

We have a game for you to play. Rearrange the logical building blocks to develop a clearer understanding of how to solve this problem.

Sequence - Vertical
Drag and drop the cards to rearrange them in the correct sequence.

1
2
3
4

Try it yourself

Implement your solution in the following coding playground.

JavaScript
usercode > main.js
export function extraCharacterIndex(str1, str2){
// Replace this placeholder return statement with your code
return -1
}
Find the Difference