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.
defsolve(c):# By sorting the cards, we ensure that we handle the smallest constraints first, which simplifies checking validity and calculating permutationsc.sort()result=1foriinrange(len(c)):# For each card at index i, the value must be at most i. If any card's value exceeds its index, it can't be placed in a valid position, resulting in 0 permutationsifc[i]>i:return0# Permutations Calculation: For each valid card, the number of available positions is determined by (i + 1 - c[i]), where i is the index (0-based). The product of these values for all cards gives the total number of valid permutationsresult=(result*(i+1-c[i]))%1000000007returnresult
Cookie support is required to access HackerRank
Seems like cookies are disabled on this browser, please enable them to open this website
Join us
Create a HackerRank account
Be part of a 26 million-strong community of developers
Please signup or login in order to view this challenge
Picking Cards
You are viewing a single comment's thread. Return to all comments →