[Microsoft] OA 2025 start – 30 Apr (generic)

Recipe Count Based on Available Ingredients

Problem Description

Given a String[] recipes and a String ingredients (containing only lowercase characters representing available ingredients), return the number of recipes that can be made using only the available ingredients.

Input Example

String[] recipes = {"abc", "de", "ac", "bd"};
String ingredients = "abcd";

Output Example

3

Explanation

Only recipes "abc", "ac", and "bd" can be made using the available ingredients "abcd".


Optimized Distance Between Unequal Elements

Problem Description

Given an integer array A of length up to 75,000, return the maximum distance j - i such that A[i] != A[j].

The brute-force implementation below needs to be optimized to run under 2 seconds.

Original Code

int optimize(int[] A) {
    int N = A.length;
    int result = 0;
    for (int i = 0; i < N; i++)
        for (int j = i; j < N; j++)
            if (A[i] != A[j])
                result = Math.max(result, j - i);
    return result;
}

我们长期稳定承接各大科技公司如TikTok、Google、Amazon等的OA笔试代写服务,确保满分通过。如有需求,请随时联系我们。

We consistently provide professional online assessment services for major tech companies like TikTok, Google, and Amazon, guaranteeing perfect scores. Feel free to contact us if you're interested.

Leave a Reply

Your email address will not be published. Required fields are marked *