Added Java program Get_Equal_Substring_Within_Budget #455
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
Program Description: Get Equal Substring Within Budget
The "Get Equal Substring Within Budget" program is designed to calculate the maximum length of a substring of two given strings, s and t, that can be changed to match each other within a specified cost limit (maxCost). The cost of changing a character from one string to another is determined by the absolute difference between their ASCII values.
Functionality:
The program takes three inputs:
The first string s.
The second string t.
The maximum cost maxCost.
It iterates through the characters of both strings simultaneously and calculates the cost of changing each character from s to t.
It maintains a sliding window approach to find the maximum length of a substring that can be changed within the specified cost limit.
The program then returns the maximum length of the valid substring.
**// Sample input
String s = "abcd";
String t = "bcdf";
int maxCost = 3;
// Output
int maxLength = obj.equalSubstring(s, t, maxCost);
System.out.println("Maximum length of valid substring: " + maxLength);
**
Expected Output:
Maximum length of valid substring: 3