Question: Do you know how i can solve the problem use a python code? Implement a class TrackRepeat with the following methods: add ( x ,

Do you know how i can solve the problem use a python code?
Implement a class TrackRepeat with the following methods:
add(x, k): add the number x to the list k times.
check(): return True if all numbers in the list repeat a different number of times, otherwise return False.
Both methods should operate in O(1) time complexity.
For example, in the list [1,3,1,1,2,3,1], there are three numbers: 1,2, and 3. Number 1 repeats 4 times, number 2 repeats once, and number 3 repeats twice. Therefore, all numbers in the list repeat a different number of times (4,1, and 2 times).
Implement the class TrackRepeat according to the following template.
class TrackRepeat:
def __init__(self):
# TODO
def add(self, x, k):
# TODO
def check(self):
# TODO
if __name__=="__main__":
t = TrackRepeat()
print(t.check()) # True
t.add(1,3)
print(t.check()) # True
t.add(2,3)
print(t.check()) # False
t.add(2,2)
print(t.check()) # True
t.add(3,1)
print(t.check()) # True
t.add(3,4)
print(t.check()) # False

Step by Step Solution

There are 3 Steps involved in it

1 Expert Approved Answer
Step: 1 Unlock blur-text-image
Question Has Been Solved by an Expert!

Get step-by-step solutions from verified subject matter experts

Step: 2 Unlock
Step: 3 Unlock

Students Have Also Explored These Related Databases Questions!