FastPrepFastPrep
Problem Brief

Looking for a Matching Score

NEW GRADOA

FastPrep has an extensive customer database, which contains a vast number of users. To maintain uniqueness and prevent customers from having very similar usernames, FastPrep's DB Management experts have come up with a solution. They have decided to define what is known as a "F-match" score between two usernames.

Now let's consider two users, each with their respective User IDs: user1ID, which has a length of x, and user2ID, which has a length of y. Each User ID is represented as a string consisting solely of lowercase English letters.

To determine how closely related these usernames are, the F-match score is introduced. The F-match score of user1ID with respect to user2ID is defined as the maximum number of distinct indices i such that the string formed by concatenating characters user1ID[i], user2ID[i + z], ... , user1ID[i + (y - 1) × z] can be rearranged to exactly match user2ID.

This condition holds true under the following constraints:

  • 0 ≤ i, ensuring that the starting index is valid.
  • i + (y - 1) × z < n
  • 1 ≤ z
  • Given two strings that represent user IDs, the goal is to determine the f-match score between them. This involves analyzing how closely related the two user IDs are by applying the matching criteria and finding the best possible match based on the given conditions.

    Function Description

    Complete the function lookingForAMatchingScore in the editor.

    findScore has the following parameters:

    1. String user1ID: the username of 1st user
    2. String user2ID: the username of 2nd user
    3. int z: the interval at which the characters from userID1 are concatenated

    Returns

    int: the score of user1ID with respect to user2ID.

    Forever thankful for spike! - on 02-03-25

    1Example 1

    Input
    user1ID = "acaccaa", user2ID = "aac", z = 2
    Output
    2
    Explanation
    Starting at index i = 0, we increment i by p = 2, meaning we pick every second character. The string formed by concatenating user1id[0], user1id[2], and user1id[4] results in newString = "aca". Since this matches exactly with user2id, the index i = 0 is considered a valid starting index. Starting at index i = 1, we take every second character again, forming newString = "cca" by concatenating user1id[1], user1id[3], and user1id[5]. However, no possible rearrangement of this string can make it identical to user2id. As a result, i = 1 is not a valid starting index. Starting at index i = 2, we once again extract characters at every second position, forming newString = "aca" from user1id[2], user1id[4], and user1id[6]. Even though it’s not an exact match to user2id, it can be rearranged into "aac", which does match. Therefore, i = 2 is also considered a valid starting index. After evaluating all possibilities, we find that there are two valid starting indices (i = 0 and i = 2). Hence, the p-matching score in this case is 2.

    Constraints

    Limits and guarantees your solution can rely on.

    • 1 ≤ |user2ID| ≤ |user2ID| ≤ 10^6
    • 1 ≤ z ≤ 10^6
    • User strings user1ID and user2ID only contain lowercase Latin letters.
    public int lookingForAMatchingScore(String user1ID, String user2ID, int z) {
      // write your code here
    }  
    
    Input

    user1ID

    "acaccaa"

    user2ID

    "aac"

    z

    2

    Output

    2

    Sign in to submit your solution.