You are viewing a single comment's thread. Return to all comments →
I don't understand why my code doesn't work?!
from collections import defaultdict d=defaultdict(lambda:[]) n,k=map(int,input().split(' ')) l=[] for i in range(1,n): temp=i*i*i s="".join(sorted(str(temp))) d[s].append(i) if len(d[s])==k: #d[s].sort() l.append(pow(min(d[s]),3)) #print(d) new=sorted(l) for v in new: print(v)
The problem says, 'exactly' k, but in your code you add every number that reachs k.
from collections import defaultdict d=defaultdict(lambda:[]) n,k=map(int,input().split(' ')) l=[] for i in range(1,n): temp=i*i*i s="".join(sorted(str(temp))) d[s].append(i) for item in d.items(): if len(item[1]) == k: l.append(pow(min(item[1]), 3)) new=sorted(l) for v in new: print(v)
Omg it worked! I realized the mistake. Thank you so much!!!
Seems like cookies are disabled on this browser, please enable them to open this website
I agree to HackerRank's Terms of Service and Privacy Policy.
Project Euler #62: Cubic permutations
You are viewing a single comment's thread. Return to all comments →
I don't understand why my code doesn't work?!
The problem says, 'exactly' k, but in your code you add every number that reachs k.
Omg it worked! I realized the mistake. Thank you so much!!!