Join Regular Classroom : Visit ClassroomTech

Hackwithinfy 2021 Solution | Power of 10

Question: Power of 10

Solution: In Python 3

import functools
l=[]
n=int(input())
for _ in range (n):
    for j in range(len(l)+1):
        lists.append(l[j: i])
z=[]
for i in lists:
    result1=functools.reduce((lambda x, y: x*y), i)
    if result1%10==0:
        z.append(result//10)
if len(x)==0:
    print(0)
else:
    print(len(max(z)))
Another Way
def dfs(cur_index, prod):
    global res
    intermediate_res = 0
    dup_prod = prod
    while dup_prod%10 == 0:
        intermediate_res+=1
        dup_prod/=10
    if dup_prod == 1:
        res = max(res, intermediate_res)

    
    if cur_index == n:
        return
    
    dfs(cur_index+1, prod*arr[cur_index])
    dfs(cur_index+1, prod)


if name == "_main_":

    n = int(input())

    arr = [int(input()) for _ in range(n)]

    res = 0

    prod = 1

    dfs(0, 1)

    print(res)

Follow Us

You Missed