Vowel and Consonant Substrings | InterviewBit | Solution

Problem Link.

class Solution:
    def solve(self, A):
        vowels = ['a', 'e', 'i', 'o', 'u']
        data = {'c': 0, 'v': 0}

        ans = 0
        for c in A:
            if c in vowels:
                ans += data['c']
                data['v'] += 1
            else:
                ans += data['v']
                data['c'] += 1
            ans = ans % (10**9 + 7)

        return (ans % (10**9 + 7))

    Leave a Reply

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