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.
def_FACT_TABLE():facts=[0,1,2]def_fact(n):ifn<len(facts)-1:returnfacts[n]foriinrange(len(facts),n+1):facts.append(facts[i-1]*i)returnfacts[n]return_fact_fact=_FACT_TABLE()def_sort(symbs):p_s=[x//2 for x in symbs.values() if x//2 > 0 ]m_s=[x%2forxinsymbs.values()ifx%2>0]returnp_s,m_sdef_to_symbs(l,r):symbs={}foriinrange(l-1,r):symbs[S[i]]=symbs.get(S[i],0)+1returnsymbsdef_calculate(p_s,m_s):res=_fact(max(sum(p_s),1))forxinp_s:res=int(res/_fact(x))res=res*max(len(m_s),1)returnresdefanswerQuery(l,r):# Return the answer for this query modulo 1000000007.symbs=_to_symbs(l,r)iflen(symbs)==1:return1p_s,m_s=_sort(symbs)return_calculate(p_s,m_s)
Cookie support is required to access HackerRank
Seems like cookies are disabled on this browser, please enable them to open this website
Maximum Palindromes
You are viewing a single comment's thread. Return to all comments →
My solution