InfyTQ Python
Coding Questions & Answers 2022
Amusement park
Problem
Statement –
Aashay loves to go to WONDERLA , an amusement park.
They are offering students who can code well with some discount. Our task is to
reduce the cost of the ticket as low as possible.
The cost of tickets can be removed by removing the
digits from the price given. They will give some k turns to remove the digits
from the price of the ticket. Your task is to help Aashay in coding a program
that can help him to reduce the cost of a ticket by removing the digits from
its price and getting the maximum possible discount.
Note
– You cannot make the cost of a ticket
zero. For eg -: If the cost of a ticket is 100, and you have 2 turns to reduce
the price, the final price will be 1 and not zero.
Constraints:
1 <= number of tickets <= 10^5
1 <= K <= number of tickets
Input Format for Custom Testing:
The first line contains a string,Tickets, denoting
the given cost of each ticket.
The next line contains an integer, K, denoting the
number of tickets that is to be removed.
Sample Cases:
Sample
Input 1
203
3
Sample
Output 1
0
Program :
import sys
n=input("Cost of each Ticket : ")
k=int(input("Number of Tickets that is to be
Removed : "))
n1=len(n)
if len(n)<=k:
print(0)
sys.exit()
a=''
i=0
while i < (n1-1) and k>0:
if
int(n[i])>int(n[i+1]):
i+=1
k-=1
continue
else:
a+=n[i]
i+=1
a+=n[i]
i+=1
if k>0:
a=a[:-k]
if i<=(n1-1):
while
i < n1:
a+=n[i]
i+=1
print(int(a)%((10**9)+7))
Comments
Post a Comment