Calculate Difference Value π§
As an assignment, students at HackerLand High School are to find a subsequence using two strings by performing the below-mentioned operation. Given two strings firstString of length n and secondString of length m, the goal is to make secondString a subsequence of firstString by applying the operation any number of times.
In one operation, any single character can be removed from the secondString. The goal is to find the minimum possible difference value which is calculated as:
| maximum index of all the characters removed from the string secondString | - | minimum index of all the characters removed from the string secondString | + 1. Removing a character from secondString does not affect the indices of the other characters and an empty string is always a subsequence of firstString.
Note: A subsequence of a string is a new string formed deleting some (can be none) of the characters from a string without changing the relative positions of the remaining characters. "ace" is a subsequence of "abcde" but "aec" is not.
Complete the function findDifferenceValue in the editor.
firstString = "HACKERRANK" secondString = "HACKERMAN" return = 1
secondString to "HACKERAN", a subsequence of firstString. The difference value is 7 - 7 + 1 = 1. Return 1.Unknown for now π°- Maximize Total Profit by Assigning Chefs to DishesPHONE SCREEN Β· Seen May 2026
- Closest DashMartPHONE SCREEN Β· Seen Jun 2025
- Return Priority of Order IDsPHONE SCREEN Β· Seen Jun 2025
- Adjust Prices π±Seen Oct 2024
- Discount EventsSeen Oct 2024
- Team FormationSeen Oct 2024
- Get Sizes of Friends Groups π₯Seen Mar 2024
public int findDifferenceValue(String firstString, String secondString) {
// write your code here
}