Grokking the Engineering Manager Coding Interview
Ask Author
Back to course home

0% completed

Solution: Determine if Two Strings Are Close
Table of Contents

Contents are not accessible

Contents are not accessible

Contents are not accessible

Contents are not accessible

Contents are not accessible

Problem Statement:

Two strings are considered similar if you can make one string look like the other using the following two operations:

  1. Swap any two characters.
    • For example, abde -> aedb (e and b swapped).
  2. Replace every occurrence of one character with another, and replace the other character with the first one.
    • For example, acabbb -> bcbaaa (all a's turn into b's, and all b's turn into a's)

Given two strings, word1 and word2, return true if they can be made similar, otherwise return false.

Examples

Example 1:

  • Input:

.....

.....

.....

Like the course? Get enrolled and start learning!

Table of Contents

Contents are not accessible

Contents are not accessible

Contents are not accessible

Contents are not accessible

Contents are not accessible