People browsing Amazon frequently rely on product feedback to make buying decisions. They may narrow down their search using specific phrases, but spelling errors often appear in reviews. To handle this issue, Amazon's system also considers review sections that contain words nearly matching the search phrase.
A text fragment phrase is nearly identical to another string target if you can swap two neighboring characters in phrase at most once to make it identical to target.
Your task is to determine the number of continuous sections within content that are nearly identical to target.
Note: A continuous section means consecutive characters inside a string. Two sections are distinct if they start from different indices.
target = "moon" content = "monomon" return = 2
target = "aaa" content = "aaaa" return = 2
targetandcontentwill consist solely of lowercase English letters.1 ≤ |target| ≤ |content| ≤ 50, where|s|denotes the length of a strings.
- Count Promotional PeriodsOA · Seen Jun 2026
- Find Maximum Total Amount (SDE I, Fungible :)Seen Jun 2026
- Get Minimum AmountOA · Seen Jun 2026
- Find Minimum CostOA · Seen Jun 2026
- Get Smallest Base SegmentOA · Seen Jun 2026
- Select Least Resource TasksOA · Seen Jun 2026
- Product Category Group SizesPHONE SCREEN · Seen May 2026
- Count Connected ComponentsPHONE SCREEN · Seen May 2026
public int similarTextSubstringCount(String target, String content) {
// write your code here
}