Monthly Archives: February 2022

C# || How To Find The Difference Between Two Strings Using C#

The following is a module with functions which demonstrates how to find the difference between two strings using C#.


1. Find The Difference – Problem Statement

You are given two strings s and t.

String t is generated by random shuffling string s and then add one more letter at a random position.

Return the letter that was added to t.

Example 1:


Input: s = "abcd", t = "abcde"
Output: "e"
Explanation: 'e' is the letter that was added.

Example 2:


Input: s = "", t = "y"
Output: "y"


2. Find The Difference – Solution

The following is a solution which demonstrates how to find the difference between two strings.

QUICK NOTES:
The highlighted lines are sections of interest to look out for.

The code is heavily commented, so no further insight is necessary. If you have any questions, feel free to leave a comment below.

Once compiled, you should get this as your output for the example cases:


"e"
"y"