arr of the same length as nums.nums with -1, 0, or 1 in arr based on the comparison with k.book_pre to store the frequency of prefix sums.agg to keep track of the current prefix sum and ans to store the count of valid subarrays.arr and update agg with the current element.k), set check to True.check is True, increment ans by the count of agg and agg-1 in book_pre.check is False, increment the count of agg in book_pre.ans.