subject
Computers and Technology, 01.12.2021 02:20 AshNo

Given two strings s and t, both consisting of lowercase English letters and digits, your task is to calculate how many ways exactly one digit could be removed from one of the strings so that s is lexicographically smaller than t after the removal. Note that we are removing only a single instance of a single digit, rather than all instances (eg: removing 1 from the string a11b1c could result in a1b1c or a11bc, but not abc). Also note that digits are considered lexicographically smaller than letters. Example
For s = "ab12c" and t = "1zz456", the output should be removeOneDigit(s, t) = 1.
Here are all the possible removals:
We can remove the first digit from s, obtaining "ab2c". "ab2c" > "1zz456", so we don't count this removal
We can remove the second digit from s, obtaining "ab1c". "ab1c" > "1zz456", so we don't count this removal
We can remove the first digit from t, obtaining "zz456". "ab12c" < "zz456", so we count this removal
We can remove the second digit from t, obtaining "1zz56". "ab12c" > "1zz56", so we don't count this removal
We can remove the third digit from t, obtaining "1zz46". "ab12c" > "1zz46", so we don't count this removal
We can remove the fourth digit from t, obtaining "1zz45". "ab12c" > "1zz45", so we don't count this removal
The only valid case where s < t after removing a digit is "ab12c" < "zz456". Therefore, the answer is 1.
For s = "ab12c" and t = "ab24z", the output should be removeOneDigit(s, t) = 3.
There are 4 possible ways of removing the digit:
"ab1c" < "ab24z"
"ab2c" > "ab24z"
"ab12c" < "ab4z"
"ab12c" < "ab2z"
Three of these cases match the requirement that s < t, so the answer is 3.
Input/Output
[execution time limit] 4 seconds (py3)
[input] string s
A string consisting of lowercase English letters and digits 0..9.
Guaranteed constraints:
1 ≤ s. length ≤ 103.
[input] string t
A string consisting of lowercase English letters and digits 0..9.
Guaranteed constraints:
1 ≤ t. length ≤ 103.
[output] integer
The number of ways to remove exactly one digit from one of the strings so that s is lexicographically smaller than t after the removal.
Please use Python
def removeOneDigit(s, t):
Sample test case
Input:
s: "ab12c"
t: "1zz456"
Output:
Expected Output:1
Test case 2
Input:
s: "ab12c"
t: "ab24z"
Expected Output:
3

ansver
Answers: 2

Another question on Computers and Technology

question
Computers and Technology, 22.06.2019 04:30
There is a simple pattern for determining if a binary number is odd. what is it and why does this pattern occur? how many bits would you need if you wanted to have the ability to count up to 1000? how high could you count in binary if you used all 10 of your fingers as bits? (finger up means 1, finger down means 0)
Answers: 3
question
Computers and Technology, 22.06.2019 22:30
I'll mark brainliest if answered right! with which feature or menu option of a word processing program can you make an image like this? you can get this image using the option of a word processing program.
Answers: 1
question
Computers and Technology, 23.06.2019 08:00
The managing director of a company sends a christmas greeting to all his employees through the company email. which type of network does he use? he uses an .
Answers: 3
question
Computers and Technology, 23.06.2019 18:00
Which finger presses the h key on the keyboard? index finger on the left hand pinky finger on the right hand index finger on the right hand thumb on the left hand
Answers: 1
You know the right answer?
Given two strings s and t, both consisting of lowercase English letters and digits, your task is to...
Questions
question
Mathematics, 11.07.2019 03:50
question
Mathematics, 11.07.2019 03:50