10. Exactly One Swap
β GFG solution to the Exactly One Swap problem: count distinct strings after one swap. Uses hashing & counting. π
π§© Problem Description
π Examples
Example 1
Input: s = "geek"
Output: 6
Explanation: After one swap, there are 6 distinct strings possible:
"egek", "eegk", "geek", "geke", "gkee", and "keeg".Example 2
Input: s = "aaaa"
Output: 1
Explanation: Only one distinct string is possible after any swap ("aaaa").π Constraints
β
My Approach
π‘ Idea
βοΈ Algorithm Steps:
π Time and Auxiliary Space Complexity
π§βπ» Code (C++)
π§βπ» Code (Java)
π Code (Python)
π§ Contribution and Support
πVisitor Count
Last updated