Answered step by step
Verified Expert Solution
Link Copied!

Question

1 Approved Answer

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

Step: 1

blur-text-image

Get Instant Access to Expert-Tailored Solutions

See step-by-step solutions with expert insights and AI powered tools for academic success

Step: 2

blur-text-image

Step: 3

blur-text-image

Ace Your Homework with AI

Get the answers you need in no time with our AI-driven, step-by-step assistance

Get Started

Recommended Textbook for

More Books

Students also viewed these Databases questions