Same Substring

Problem Overview

  • Find the maximum-length substring of s that can be changed into the corresponding substring of t with total ASCII cost <= K.
  • Input: two equal-length lowercase strings s, t, and integer K; per-index cost is abs(si - ti). Output: the max length, or 0 if none; n up to 2e5, K up to 1e6.
  • Domain: budgeted text transformation/string similarity under a cost limit.
  • Asked in Ibm interviews; a classic coding interview problem and interview question.

Example

Unlock to view complete problem details

and practice with sample input/output

Was this article helpful?

View Test Cases & Run Code requires membership

Input Variables
Execution Result: