You are on page 1of 3

You are provided with a number D containing only digits 0's and 1's.

Your aim is to
convert this number to have all the digits same.
For that, you will change exactly one digit i.e. from 0 to 1 or from 1 to 0. If it
is possible to make all digits equal (either all 0's or all 1's) by flipping
exactly 1 digit then output "YES", else print "NO" (quotes for clarity).

Input Format:
The first line of the input contains the number D made of only digits 1's and 0's.

Output:
Print 'YES' or 'NO' depending on whether its possible to make it all 0s or 1s or
not.

Example-1:

Input:
101

Output:
YES

D = [int(x) for x in input()]


D.sort()
c=0
x=D.count(1)
y=D.count(0)
n=len(D)
if(x!=0 and y!=0):
if(D[0]==0 and D[1]==1):
D[0]=1
else:
D[n-1]=0
x=D[0]

for i in range(n):
if(D[i]==x):
c=c+1
if(c==n):
print("YES",end='')
else:
print("NO",end='')

else:
print("NO")

Given a list of n-1 numbers ranging from 1 to n, your task is to find the missing
number. There are no duplicates.
Input Format:
The first line contains n-1 numbers with each number separated by a space.

Output Format:
Print the missing number

Example:

Input:
1 2 4 6 3 7 8

Output:
5

n = [int(x) for x in input().split()]


my_set = set(n)
n = list(my_set)
n.sort()
x=len(n)
y=1
for i in range(0,x):
if(n[i]==y):
y=y+1
continue
else:
print(y,end='')
break

You might also like