# param_1 = obj.gather(k,maxRow)
# param_2 = obj.scatter(k,maxRow)

true, false, null = True, False, None
cases = [
    (["BookMyShow", "gather", "gather", "scatter",
      "scatter"], [[2, 5], [4, 0], [2, 0], [5, 1],
                   [5, 1]], [null, [0, 0], [], true, false]),
    ([
        "BookMyShow", "gather", "gather", "gather", "gather", "gather",
        "gather", "gather", "scatter", "scatter", "gather", "gather", "gather",
        "gather", "gather", "scatter", "gather", "gather", "scatter", "gather",
        "scatter", "scatter", "scatter", "gather", "scatter"
    ], [[25, 941], [34, 1], [296, 21], [927, 18], [695, 15], [830, 22],
        [638, 2], [169, 15], [623, 16], [268, 6], [160, 16], [342, 5], [22, 8],
        [187, 11], [332, 24], [589, 14], [87, 14], [581, 4], [334,
                                                              14], [322, 0],
        [511, 4], [1000, 3], [938, 9], [19, 5], [672, 5]], [
            null, [0, 0], [0, 34], [1, 0], [2, 0], [3, 0], [], [0, 330],
            true, true, [4, 78], [4, 238], [4, 580], [4, 602], [5, 0], true,
            [5, 769], [], true, [], false, false, true, [], false
        ]),
]

import aatest_helper

aatest_helper.run_simulation_cases(BookMyShow, cases)

if __name__ == '__main__':
    pass
Exemple #2
0
        "queryRange", "addRange", "queryRange", "removeRange", "queryRange",
        "removeRange", "addRange", "queryRange"
    ], [[], [55, 62], [1, 29], [18, 49], [6, 98], [59, 71], [40, 45], [4, 58],
        [57, 69], [20, 30], [1, 40], [73, 93], [32, 93], [38, 100], [50, 64],
        [26, 72], [8, 74], [15, 53], [44, 85], [10, 71], [54, 70], [10, 45],
        [30, 66], [47, 98], [1, 7], [44, 78], [31, 49], [62, 63], [49, 88],
        [47, 72], [8, 50], [49, 79], [31, 47], [54, 87], [77, 78], [59, 100],
        [8, 9], [50, 51], [67, 93], [25, 86], [8, 92], [31, 87], [90, 95],
        [28, 56], [10, 42], [27, 34], [75, 81], [17, 63], [78, 90], [9, 18],
        [51, 74], [20, 54], [35, 72], [2, 29], [28, 41], [17, 95], [73, 75],
        [34, 43], [57, 96], [51, 72], [21, 67], [40, 73], [14, 26], [71, 86],
        [34, 41], [10, 25], [27, 68], [18, 32], [30, 31], [45, 61], [64, 66],
        [18, 93], [13, 21], [13, 46], [56, 99], [6, 93], [25, 36], [27, 88],
        [82, 83], [30, 71], [31, 73], [10, 41], [71, 72], [9, 56], [22, 76],
        [38, 74], [2, 77], [33, 61], [74, 75], [11, 43], [27, 75]], [
            null, null, null, null, false, false, null, null, null, null, null,
            false, null, null, null, null, false, false, null, null, true,
            null, false, null, false, null, null, null, null, null, null, null,
            null, null, true, true, false, false, true, null, null, false,
            null, null, null, true, null, null, null, null, false, null, null,
            false, null, null, null, true, null, true, null, null, null, null,
            false, null, false, false, null, false, null, null, false, null,
            null, false, null, null, null, null, null, null, true, true, null,
            true, null, false, null, null, false
        ])
]

import aatest_helper

aatest_helper.run_simulation_cases(RangeModule, cases)
Exemple #3
0
        self.unlock_all(num)
        st = self.state[num]
        x = num
        while x != -1:
            self.state[x].lock -= (cut - 1)
            x = self.state[x].parent
        st.user = user
        return True


# Your LockingTree object will be instantiated and called as such:
# obj = LockingTree(parent)
# param_1 = obj.lock(num,user)
# param_2 = obj.unlock(num,user)
# param_3 = obj.upgrade(num,user)

true, false, null = True, False, None
cases = [
    (["LockingTree", "lock", "unlock", "unlock", "lock", "upgrade", "lock"],
     [[[-1, 0, 0, 1, 1, 2, 2]], [2, 2], [2, 3], [2, 2], [4, 5], [0, 1], [0, 1]],
     [null, true, false, true, true, true, false]),
]

import aatest_helper

aatest_helper.run_simulation_cases(LockingTree, cases)

if __name__ == '__main__':
    pass
    def popBack(self) -> int:
        if self.empty():
            return -1
        x = self.b.pop()
        self.adjust()
        return x


# Your FrontMiddleBackQueue object will be instantiated and called as such:
# obj = FrontMiddleBackQueue()
# obj.pushFront(val)
# obj.pushMiddle(val)
# obj.pushBack(val)
# param_4 = obj.popFront()
# param_5 = obj.popMiddle()
# param_6 = obj.popBack()

null = None
cases = [
    ([
        "FrontMiddleBackQueue", "pushFront", "pushBack", "pushMiddle",
        "pushMiddle", "popFront", "popMiddle", "popMiddle", "popBack",
        "popFront"
    ], [[], [1], [2], [3], [4], [], [], [], [],
        []], [null, null, null, null, null, 1, 3, 4, 2, -1]),
]

import aatest_helper

aatest_helper.run_simulation_cases(FrontMiddleBackQueue, cases)
Exemple #5
0
class StockSpanner:
    def __init__(self):
        self.past = []

    def next(self, price: int) -> int:
        nc = 1
        while self.past:
            (v, c) = self.past.pop()
            if price >= v:
                nc += c
            else:
                self.past.append((v, c))
                break
        self.past.append((price, nc))
        return nc


# Your StockSpanner object will be instantiated and called as such:
# obj = StockSpanner()
# param_1 = obj.next(price)

null = None
cases = [
    (["StockSpanner", "next", "next", "next", "next", "next", "next",
      "next"], [[], [100], [80], [60], [70], [60], [75],
                [85]], [null, 1, 1, 1, 2, 1, 4, 6])
]

run_simulation_cases(StockSpanner, cases)
Exemple #6
0
        # ans = val * mul + add

        mul = (mul1 * div2) % MOD
        add = add1 - add2 * mul
        ans = val * mul + add
        while ans < 0:
            ans += MOD
        return ans % MOD


# Your Fancy object will be instantiated and called as such:
# obj = Fancy()
# obj.append(val)
# obj.addAll(inc)
# obj.multAll(m)
# param_4 = obj.getIndex(idx)

null = None
cases = [
    ([
        "Fancy", "append", "addAll", "append", "multAll", "getIndex", "addAll",
        "append", "multAll", "getIndex", "getIndex", "getIndex"
    ], [[], [2], [3], [7], [2], [0], [3], [10], [2], [0], [1],
        [2]], [null, null, null, null, null, 10, null, null, null, 26, 34,
               20]),
]

import aatest_helper

aatest_helper.run_simulation_cases(Fancy, cases)
Exemple #7
0
                if p != -1:
                    dp[i][k] = dp[dp[i][k - 1]][k - 1]
        self.dp = dp

    def getKthAncestor(self, node: int, k: int) -> int:
        dp = self.dp
        while k > 0:
            d = 0
            while (1 << (d + 1)) <= k:
                d += 1
            node = dp[node][d]
            if node == -1:
                break
            k = k - (1 << d)
        return node


# Your TreeAncestor object will be instantiated and called as such:
# obj = TreeAncestor(n, parent)
# param_1 = obj.getKthAncestor(node,k)

null = None
cases = [
    (["TreeAncestor", "getKthAncestor", "getKthAncestor", "getKthAncestor", "getKthAncestor", "getKthAncestor"],
     [[5, [-1, 0, 0, 0, 3]], [1, 5], [3, 2], [0, 1], [3, 1], [3, 5]], [null, -1, -1, -1, 0, -1]),
]

import aatest_helper

aatest_helper.run_simulation_cases(TreeAncestor, cases)
                    s = m + 1
                else:
                    e = m - 1
            return s

        # 找到第一个>=left的pos
        a = bs(ps, left)
        # 找到第一个<=right的pos.
        # 等于找到第一个>=(right+1)的pos, 然后-1?
        b = bs(ps, right + 1) - 1
        return b - a + 1

    def query(self, left: int, right: int, threshold: int) -> int:
        t = query_seg_tree(self.st, left, right)
        freq = self.get_freq(t.val, left, right)
        if freq >= threshold:
            return t.val
        return -1


import aatest_helper

null = None
cases = [
    (["MajorityChecker", "query", "query", "query"], [[[1, 1, 2, 2, 1, 1]],
                                                      [0, 5, 4], [0, 3, 3],
                                                      [2, 3,
                                                       2]], [null, 1, -1, 2]),
]
aatest_helper.run_simulation_cases(MajorityChecker, cases)
Exemple #9
0
        if v == 0:
            self.last_zero = len(self.arrays)
            v = 1
        self.arrays.append(v)

    def getProduct(self, k: int) -> int:
        # print(self.arrays, self.last_zero, k)
        p = len(self.arrays) - 1 - k
        if (p + 1) <= self.last_zero:
            return 0
        v = self.arrays[p]
        v2 = self.arrays[-1]
        return v2 // v


# Your ProductOfNumbers object will be instantiated and called as such:
# obj = ProductOfNumbers()
# obj.add(num)
# param_2 = obj.getProduct(k)

import aatest_helper

null = None
cases = [([
    "ProductOfNumbers", "add", "add", "add", "add", "add", "getProduct",
    "getProduct", "getProduct", "add", "getProduct"
], [[], [3], [0], [2], [5], [4], [2], [3], [4], [8],
    [2]], [null, null, null, null, null, null, 20, 40, 0, null, 32])]

aatest_helper.run_simulation_cases(ProductOfNumbers, cases)
Exemple #10
0
    def q(self, t: int) -> int:
        times = self.times

        def bs(t):
            s, e = 0, len(times) - 1
            while s <= e:
                m = (s + e) // 2
                if times[m] > t:
                    e = m - 1
                else:
                    s = m + 1
            return e

        idx = bs(t)
        return self.tmp[idx]


# Your TopVotedCandidate object will be instantiated and called as such:
# obj = TopVotedCandidate(persons, times)
# param_1 = obj.q(t)

null = None
cases = [(["TopVotedCandidate", "q", "q",
           "q", "q", "q", "q"], [[[0, 1, 1, 0, 0, 1, 0],
                                  [0, 5, 10, 15, 20, 25, 30]], [3], [12], [25],
                                 [15], [24], [8]], [null, 0, 1, 1, 0, 0, 1])]

import aatest_helper

aatest_helper.run_simulation_cases(TopVotedCandidate, cases)
        node = self.node
        while k and node and node.next is not None:
            k -= 1
            node = node.next
        self.node = node
        return self.leftContent()


# Your TextEditor object will be instantiated and called as such:
# obj = TextEditor()
# obj.addText(text)
# param_2 = obj.deleteText(k)
# param_3 = obj.cursorLeft(k)
# param_4 = obj.cursorRight(k)

true, false, null = True, False, None
cases = [
    ([
        "TextEditor", "addText", "deleteText", "addText", "cursorRight",
        "cursorLeft", "deleteText", "cursorLeft", "cursorRight"
    ], [[], ["leetcode"], [4], ["practice"], [3], [8], [10], [2],
        [6]], [null, null, 4, null, "etpractice", "leet", 4, "", "practi"]),
]

import aatest_helper

aatest_helper.run_simulation_cases(TextEditor, cases)

if __name__ == '__main__':
    pass
Exemple #12
0
        while True:
            root.count += 1
            if root.left is None:
                root.left = node
                break
            elif root.right is None:
                root.right = node
                break

            lc = root.left.count
            rc = root.right.count
            if (lc & (lc + 1)) != 0:
                root = root.left
            elif (rc & (rc + 1)) != 0:
                root = root.right
            else:
                root = root.left if rc == lc else root.right

        return root.val

    def get_root(self) -> TreeNode:
        return self.root


import aatest_helper
null = None
cases = [(["CBTInserter", "insert", "insert",
           "get_root"], [[aatest_helper.list_to_tree([1, 2, 3, 4, 5, 6])], [7],
                         [8], []], [null, 3, 4, [1, 2, 3, 4, 5, 6, 7, 8]])]
aatest_helper.run_simulation_cases(CBTInserter, cases)
Exemple #13
0
        Initialize your data structure here.
        """
        self.lookup = set()

    def add(self, key: int) -> None:
        self.lookup.add(key)

    def remove(self, key: int) -> None:
        if key in self.lookup:
            self.lookup.remove(key)

    def contains(self, key: int) -> bool:
        """
        Returns true if this set contains the specified element
        """
        return key in self.lookup


# Your MyHashSet object will be instantiated and called as such:
# obj = MyHashSet()
# obj.add(key)
# obj.remove(key)
# param_3 = obj.contains(key)

cases = [([
    "MyHashSet", "add", "remove", "add", "remove", "remove", "add", "add",
    "add", "add", "remove"
], [[], [9], [19], [14], [19], [9], [0], [3], [4], [0],
    [9]], [None, None, None, None, None, None, None, None, None, None, None])]
aatest_helper.run_simulation_cases(MyHashSet, cases)
Exemple #14
0
            v = xs[e]
            assert (v[0] <= snap_id)
            return v[1]
        return 0


# Your SnapshotArray object will be instantiated and called as such:
# obj = SnapshotArray(length)
# obj.set(index,val)
# param_2 = obj.snap()
# param_3 = obj.get(index,snap_id)

# Your SnapshotArray object will be instantiated and called as such:
# obj = SnapshotArray(length)
# obj.set(index,val)
# param_2 = obj.snap()
# param_3 = obj.get(index,snap_id)

null = None

cases = [
    (["SnapshotArray", "set", "snap", "set",
      "get"], [[3], [0, 5], [], [0, 6], [0, 0]], [null, null, 0, null, 5]),
    (["SnapshotArray", "set", "snap", "set",
      "get"], [[3], [0, 5], [], [0, 6], [0, 0]], [null, null, 0, null, 5]),
]

import aatest_helper

aatest_helper.run_simulation_cases(SnapshotArray, cases)
    def back(self, steps: int) -> str:
        self.pos -= steps
        self.pos = max(self.pos, 0)
        return self.st[self.pos]

    def forward(self, steps: int) -> str:
        self.pos += steps
        self.pos = min(self.pos, len(self.st) - 1)
        return self.st[self.pos]


# Your BrowserHistory object will be instantiated and called as such:
# obj = BrowserHistory(homepage)
# obj.visit(url)
# param_2 = obj.back(steps)
# param_3 = obj.forward(steps)

null = None
cases = [
    (["BrowserHistory", "visit", "visit", "visit", "back", "back", "forward", "visit", "forward", "back", "back"],
     [["leetcode.com"], ["google.com"], ["facebook.com"], ["youtube.com"], [1], [1], [1], ["linkedin.com"], [2], [2], [
         7]],
     [null, null, null, null, "facebook.com", "google.com", "facebook.com", null, "linkedin.com", "google.com",
      "leetcode.com"]),
]

import aatest_helper

aatest_helper.run_simulation_cases(BrowserHistory, cases)