# Logic for Single Lane Highway Codevita 9

Page Contents

## Single Lane Highway Code Solution

We are trying our best to upload the code back as nearly 12k people has copied the same code due to which it has let to massive plagiarism issue to avoid this and to keep you guys safe we are working to bring the solution in python in different format. Before that please understand the logic and try to come up with the idea.

Also See: Codevita Season 9 Solutions

## Single Lane Highway Logic

This is a gathering hypothesis issue. We discover number of all potential cycles in all potential changes in S_n. So number of changes is consistently n!. Presently let say our cycle type in a specific change is 1(C1), 2(C2),…n(Cn). Where Ci is the quantity of patterns of length I. We locate the quantity of changes of this cycle type that is frac{n!}{C1! C2! … Cn! 1^(C1) 2^(C2)…n^(Cn) }. Presently we need to consider all conceivable cycle types. Likewise we have a limitation that sum_{i=1}^{n} i(Ci) = n (condition *).

So given n we fix n factors C1, C2, … Cn    For 1 leq I leq n    For 0 leq Ci leq n/I and condition *    Process k = frac{n!}{C1! C2! … Cn! 1^(C1) 2^(C2)…n^(Cn) }    Presently total = 0    total = aggregate + k    Result = total/n!

The above logic was given by one of our Teammates which has received from unknown source.

Python 3 Code :

``````def factorial(n): f = 1 if (n == 0 or n == 1):
return 1 for i in range(2, n + 1):
f = f * i return f def getSum(arr, n):
fact = factorial(n)
digitsum = 0
for i in range(n):
digitsum += arr[i]
digitsum *= (fact // n)
res = 0
i = 1
k = 1
while i <= n :
res += (k * digitsum)
k = k * 10
i += 1
return res

if __name__ == "__main__":
arr = [1, 2, 3]
n = len(arr)
print(getSum(arr, n))``````