Trains the technique from
LeetCode 1657Determine if Two Strings Are CloseThis is an original problem, written from a brief that listed the technique, the difficulty, the topics, the function shape and the input bounds — none of that problem's wording, examples, hints or editorials. The link is there so you can map your practice onto the standard set.
Same function shape, different story and different numbers.
Two words first and second hold only lowercase letters. Two moves are allowed on a word, each usable as often as you like:
Call the words kin when some run of moves turns first into second.
Return true when they are kin.
Example 1
Exchanging every a with every b turns the first word into three b and two a, and rearranging those gives the second word.
Example 2
Both words use only a and b, but the first holds three a and one b while the second holds two of each, and no move can change a tally's value.
Example 3
The first word uses an a and the second does not, and no move can bring in a letter that is not already present.
The editor is preloaded with this. It matches the parent problem's shape, so a solution that works here transfers to a judge unchanged.
def close_strings(first: str, second: str) -> bool:public boolean closeStrings(String first, String second)See the step-by-step animation, the intuition, and clean code in every language — free, no credit card.