OA. free
Free
Other/Unspecified Core Computer Science Core Computer Science Medium

Problem Statement: Analyze the provided code snippet and determine what this function computes.

Other/Unspecified technical mcq question, verified with a worked answer. Free to practise - no sign-up.

int solve(int n, vector<int> &arr, string P){
    string s = P;
    vector<int> cnt(26, 0);
    ll sum=0;
    for(int i=0 ; i<n ; i++){
        if(s[i] == 'a' ||s[i] == 'e' ||s[i] == 'i' ||s[i] == 'o' ||s[i] == 'u'){
            cnt[s[i]-'a'] = arr[i];
        }
        else sum += arr[i];
    }

    if(cnt[0] == 0 || cnt['e'-'a'] == 0 || cnt['i'-'a'] == 0 || cnt['o'-'a'] == 0 || cnt['u'-'a'] == 0){
        return 0;
    }

    ll ans = 0;
    ans = ((ll)ans+power(2, cnt[0], mod)-1)%mod;
    ans = ((ll)ans*power(2, cnt[4], mod)-1)%mod;
    ans = ((ll)ans*power(2, cnt['i'-'a'], mod)-1)%mod;
    ans = ((ll)ans*power(2, cnt['o'-'a'], mod)-1)%mod;
    ans = ((ll)ans*power(2, cnt['u'-'a'], mod)-1)%mod;
    ans = ((ll)ans*power(2, sum, mod))%mod;

    return ans;
}

Problem Statement:

Analyze the provided code snippet and determine what this function computes. Based on the logic:

  1. It counts occurrences of vowels ('a', 'e', 'i', 'o', 'u') from a string and stores their counts
  2. It sums values from arr for non-vowel positions
  3. It checks if all five vowels are present (returns 0 if any is missing)
  4. It computes a result using powers of 2 and modular arithmetic

What does this algorithm likely solve?

Choose one option.
Show answer & explanation
Answer: A. A) Count the number of subsets of vowels with all 5 vowels present

Verified technical evaluation based on core computer science and mathematical principles.

Step-by-step Derivation:
Step 1: Parse problem constraints.
Step 2: Compute verified solution.
Step 3: Select matching option.