✅ Python Beats 100% || Beginner Friendly ||  Easy Solution || With Comments || Winner's Solution ✅
The below solution is not mine, it is of @hxu10  who ranked 5th in this contest\n\n\nfrom sortedcontainers import SortedList\n\nclass fenwick(object):\n    def 
**The below solution is not mine, it is of @hxu10  who ranked 5th in this contest**\n\n```\nfrom sortedcontainers import SortedList\n\nclass fenwick(object):\n    def __init__(self, n):\n        self.n = n\n        self.cul = [0] * n\n        self.maxd = len(bin(n)) - 3  # Depth for BIT operations\n\n    # Update BIT: add diff to index\n    def update(self, index, diff):\n        i = index\n        while i < self.n:\n            self.cul[i] += diff\n            i += (i + 1) & (-i - 1)\n\n    # Get cumulative sum up to index\n    def getaccu(self, index):\n        output = 0\n        i = index\n        while i >= 0:\n            output += self.cul[i]\n            i -= (i + 1) & (-i - 1)\n        return output\n\nclass Solution(object):\n    def numberOfAlternatingGroups(self, colors, queries):\n        """\n        :type colors: List[int]\n        :type queries: List[List[int]]\n        :rtype: List[int]\n        """\n        n = len(colors)\n        blocks = SortedList()  # To keep track of boundaries of alternating groups\n\n        # Fenwick Trees for maintaining group sizes and counts\n        fencount = fenwick(n + 1)\n        fentot = fenwick(n + 1)\n\n        ans = []\n\n        def update(index, flag):\n            if flag:  # Removing a boundary\n                if len(blocks) == 1:\n                    blocks.clear()\n                    return\n\n                loc = blocks.bisect_left(index)\n                # Determine the left and right boundaries of the group to be updated\n                if loc == 0:\n                    left = blocks[-1] - n\n                else:\n                    left = blocks[loc - 1]\n                \n                if loc == len(blocks) - 1:\n                    right = blocks[0] + n\n                else:\n                    right = blocks[loc + 1]\n\n                # Update Fenwick Trees\n                fentot.update(right - left, (right - left))\n                fencount.update(right - left, 1)\n                \n                fentot.update(index - left, -(index - left))\n                fencount.update(index - left, -1)\n                \n                fentot.update(right - index, -(right - index))\n                fencount.update(right - index, -1)\n\n                blocks.pop(loc)\n                \n            else:  # Adding a boundary\n                if len(blocks) == 0:\n                    blocks.add(index)\n                    return\n\n                loc = blocks.bisect_left(index)\n                if loc == 0:\n                    left = blocks[-1] - n\n                else:\n                    left = blocks[loc - 1]\n                    \n                if loc == len(blocks):\n                    right = blocks[0] + n\n                else:\n                    right = blocks[loc]\n                    \n                # Update Fenwick Trees\n                fentot.update(right - left, -(right - left))\n                fencount.update(right - left, -1)\n                \n                fentot.update(index - left, (index - left))\n                fencount.update(index - left, 1)\n                \n                fentot.update(right - index, (right - index))\n                fencount.update(right - index, 1)\n                \n                blocks.add(index)\n\n        # Initialize the Fenwick Trees with the full circle size\n        fentot.update(n, n)\n        fencount.update(n, 1)\n\n        # Process initial color blocks\n        for i in range(n):\n            if colors[i] == colors[i - 1]:\n                update(i, False)\n\n        # Process each query\n        for ele in queries:\n            if len(ele) == 2:\n                l = ele[1]\n                if len(blocks) == 0:\n                    ans.append(n)\n                    continue\n\n                # Calculate count and total for groups of size l\n                count = fencount.getaccu(n) - fencount.getaccu(l - 1)\n                tot = fentot.getaccu(n) - fentot.getaccu(l - 1)\n                ans.append(tot - count * (l - 1))\n                \n            else:\n                index = ele[1]\n                c = ele[2]\n                \n                if colors[index] == c:\n                    continue\n                \n                # Update boundaries affected by the color change\n                if colors[index] == colors[index - 1]:\n                    update(index, True)\n                else:\n                    update(index, False)\n                    \n                if colors[index] == colors[(index + 1) % n]:\n                    update((index + 1) % n, True)\n                else:\n                    update((index + 1) % n, False)\n                    \n                colors[index] = c\n                \n        return ans\n\n```\n\n**Approach in Steps**\n\n1. Initialization:\n\n* Create a Fenwick Tree class (fenwick) for efficiently managing cumulative sums and updates.\n* Initialize two Fenwick Trees (fencount and fentot) to handle the count and total size of alternating groups, respectively.\n* Use a SortedList (blocks) to keep track of the boundaries of alternating color groups.\n\n2. Update Function:\n\n* Removing a Boundary: If an index changes from alternating to non-alternating, update the Fenwick Trees to reflect the removal of a group boundary.\n* Adding a Boundary: If an index changes from non-alternating to alternating, update the Fenwick Trees to reflect the addition of a new group boundary.\n\n3. Processing Initial Colors:\n\n* Traverse through the color array and initialize the group boundaries and Fenwick Trees based on the initial colors.\n\n4. Processing Queries:\n\n* Type 1 Query: Calculate the number of alternating groups of a given size by querying the Fenwick Trees.\n* Type 2 Query: Update the color at a specified index, adjust the boundaries, and update the Fenwick Trees accordingly.\n\n5. Return Results:\n\n* After processing all queries, return the results of type 1 queries as a list.
['Tree', 'Python', 'Python3']