← 返回 doordash 的题目列表Check if Two Names Are Similar Within at Most Two Swaps
类型:online_judge
Problem: Similar Restaurant Names Within at Most Two Swaps
Given two strings s and t (restaurant names), determine whether you can transform s into t using at most 2 swap operations within s.
A swap operation is defined as selecting two indices i != j in s and swapping s[i] and s[j].
Output true if s can become t with no more than 2 swaps; otherwise output false.
Input Format
Line 1: string s
Line 2: string t
Output Format
One line: true or false
Constraints
1 <= len(s), len(t) <= 2 * 10^5
s and t contain only lowercase English letters
If len(s) != len(t), output false
Examples (5)
s = "ab", t = "ab" -> true
s = "ab", t = "ba" -> true
s = "abcd", t = "abdc" -> true
s = "abcd", t = "badc" -> true
s = "abcd", t = "bcad" -> false
Example
Input
ab
ab
Output
true