Skip to content

Instantly share code, notes, and snippets.

@Ephraimiyanda
Created February 16, 2026 13:24
Show Gist options
  • Select an option

  • Save Ephraimiyanda/98adbb9f9e0dabb4ab32b699b820ec82 to your computer and use it in GitHub Desktop.

Select an option

Save Ephraimiyanda/98adbb9f9e0dabb4ab32b699b820ec82 to your computer and use it in GitHub Desktop.
Find the Difference

Question

Approach

i loop through an alphabetically sorted t. if a letter in t is an extra as compared to alphabetically sorted s i return the alphabet.

Complexity

  • Time complexity: O(Nlogn)

  • Space complexity:O(N)

Code

function findTheDifference(s: string, t: string): string {
    let ss = s.split("").sort()
    let ts = t.split("").sort()
    for (let i = 0; i < ts.length; i++) {
        if (ts[i] !== ss[i]) {
            return ts[i]
        }
    }
};
scrnli_oK4228CAZ7EBWk
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment