SalesforceOA #37
Same Substring
Estimated MediumJudge-ready
Topics (AI-labelled)Two Pointers
s and t have equal length and contain only lowercase letters. The cost of changing s[i] to t[i] is the absolute difference of their ASCII codes. Find a contiguous interval whose total position-by-position conversion cost is ≤K, and return the maximum interval length; return 0 if no non-empty interval qualifies.
Input
The input is a JSON array [s,t,K]. The original has no numeric bounds; this site adds 0≤|s|=|t|≤200000, 0≤K≤10^9; the total encoded input is ≤401000 bytes.
Output
Output one integer answer.
Example 1
Input:
["abcd","bcdf",3]
Output:
3
Example 2
Input:
["az","za",0]
Output:
0
Example 3
Input:
["","",0]
Output:
0
Example notes
The outputs of the three public examples are, in order: 3; 0; 0. They have been checked by independent enumeration or direct simulation.
Editorial
Loading solution…