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.
The issue in the problem arises because Python 3.3 and above introduced hash randomization for security, which means the hash() of the same tuple can vary between runs and machines, whereas in Python 2 the hash() output for the same tuple is fixed and predictable. The HackerRank problem expects a specific deterministic hash value (3713081631934410656) for the tuple (1, 2), which aligns with Python 2 behavior. Therefore, running the code in Python 3 on your machine gives a different result because of the randomization, but switching to Python 2, where hash() is consistent, produces the expected output and passes the judge. This is why using Python 2 helps solve the problem correctly.
This is my code and if you are using it too change the python 3 to python2 first from the menu above the shell
Tuples
You are viewing a single comment's thread. Return to all comments →
The issue in the problem arises because Python 3.3 and above introduced hash randomization for security, which means the hash() of the same tuple can vary between runs and machines, whereas in Python 2 the hash() output for the same tuple is fixed and predictable. The HackerRank problem expects a specific deterministic hash value (3713081631934410656) for the tuple (1, 2), which aligns with Python 2 behavior. Therefore, running the code in Python 3 on your machine gives a different result because of the randomization, but switching to Python 2, where hash() is consistent, produces the expected output and passes the judge. This is why using Python 2 helps solve the problem correctly.
This is my code and if you are using it too change the python 3 to python2 first from the menu above the shell