We use cookies to ensure you have the best browsing experience on our website. Please read our cookie policy for more information about how we use cookies.
Where Node is subclassed from dict and __slots__ is set manually to have a counter, saves enough memory to allow the code to run without a segmentation fault.
Cookie support is required to access HackerRank
Seems like cookies are disabled on this browser, please enable them to open this website
Contacts
You are viewing a single comment's thread. Return to all comments →
In Python you can save a substantial amount of memory when creating a large number of objects by defining
__slots__
.In the Python code: https://www.hackerrank.com/challenges/contacts/submissions/code/28219710 changing the Node class from:
To:
Where Node is subclassed from dict and
__slots__
is set manually to have a counter, saves enough memory to allow the code to run without a segmentation fault.