For the best experience, increase the window size or view on a laptop or desktop device
Title | ||
|---|---|---|
Loading... | ||
For the best experience, increase the window size or view on a laptop or desktop device
Title | ||
|---|---|---|
Loading... | ||
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 (e.g., 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.
For s = "ab12c" and t = "1zz456", the output should be removeOneDigit(s, t) = 1.
Here are all the possible removals:
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:
Three of these cases match the requirement that s < t, so the answer is 3.
def removeOneDigit(s: str, t: str) -> int:
# Your code here
Input:
s = "ab12c"
t = "1zz456"
Expected Output: 1
Input:
s = "ab12c"
t = "ab24z"
Expected Output: 3
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 (e.g., 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.
For s = "ab12c" and t = "1zz456", the output should be removeOneDigit(s, t) = 1.
Here are all the possible removals:
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:
Three of these cases match the requirement that s < t, so the answer is 3.
def removeOneDigit(s: str, t: str) -> int:
# Your code here
Input:
s = "ab12c"
t = "1zz456"
Expected Output: 1
Input:
s = "ab12c"
t = "ab24z"
Expected Output: 3
Output