Answer to Question #226878 in Python for Santosh

Question #226878
In a wedding that you are attending, there are some chairs that have digits inscribed at their
backs. The chairs are lined in a row such that they form a string of the digits. Find the
minimum number of sets M that can be formed from these digits such that:
1. The number of digits in each set is one gf more than one.
2. Each set is formed using consecutive digits and no digit can be used more than once.
3. In each set, the number formed using the digits is less than or equal to Y.
1
Expert's answer
2021-08-17T12:58:17-0400
s=input()
x=int(input())
count = 0
n = 0
l=len(s)
f= False 
for i in range(l):
    n=n*10+int(s[i])
    if n<=x:
        print(n)
        f=True 
    else:
        if f:
            count +=1
            n=int(s[i])
            f= False 
        if n<=x:
            f=True
        else:
            n=0
if f==True:
    count +=1


print(count)

Need a fast expert's response?

Submit order

and get a quick answer at the best price

for any assignment or question with DETAILED EXPLANATIONS!

Comments

No comments. Be the first!

Leave a comment

LATEST TUTORIALS
New on Blog
APPROVED BY CLIENTS