Codu is fond of vehicle numbers. Codu wants to compute the number of vehicles can be registered in his state. A vehicle normally has a registration number like ST 01 AB 1234. Each
registration number has four parts, separated by spaces. The first part has two letters common for all cars in the state. The next two-digit number is the number of the district where the
car is registered within the state. It is always two digits, and may have a leading zero. After that, the next part consists of two letters (AB), with each letter selected from a range, denoting
the series and the last part is a 4-digit number (this will always be four digits, even if it has leading zeroes). The entire registration number is unique to each vehicle. You have been given
the number of districts in state and a range of letters (to be used in the series) and a set of digits that can be used for forming a vehicle registration number. You need to find the
maximum number of vehicles that can be registered in the state subject to the rules.
Constraints
1 <= Number of districts < 100
A<= Range of alphabets <= Z
0 <= Range of digits <= 9
Width of district column will always be equal to 2.
Ex-District 1 will be represented as 01.
- Input
The first line contains an integer denoting the number of districts in the state.
The second line contains two space separated characters denoting the range of alphabeticalseries python
Answers
Answered by
0
The algorithm is as below -
- The 1st part of the registration number for a particular state is fixed, so we need not do anything with that.
- Now, we will count the total number of possibilities for the 2nd part of the registration number (number of districts, say, ‘D’).
- Then the number of possible values for the 3rd part can be calculated with the help of the principle of counting since we have 2 characters and let the range of the first character be 'A'(i.e. a total of ‘A’ number of characters are allowed in this place) and that of the second character be 'B', so the total number of possible values for the 3rd part 'S' is equal to 'A'*'B'.
- Similarly, we can calculate for the 4th part, with the help of the principle of counting and it comes out to be 'R' equal to 'A'*'B'*'C'*'D', where 'A' is the range of the first digit, 'B' is the range of the second digit, 'C' is the range of the third digit and 'D' is the range of the fourth digit.
- So, the total number of vehicles that can be registered in the state can be calculated as 'D'*'S'*'R'. Since we have 'R' registration numbers in each series so in the 'S' series we have 'S'*'R' possible registration numbers, then we have 'S' series in a district so in 'D' districts we have 'D'*'S' series, so the total possible registration numbers are 'D'*'S'*'R'.
The code is as below -
'''
Time Complexity : O(1)
Space Complexity : O(1)
'''
def numberOfVehicles(districtCount, alpha1, alpha2, alpha3, alpha4, dig1, dig2, dig3, dig4):
possibilties = 1
# Find total number.
possibilties *= districtCount*(ord(alpha2) - ord(alpha1) + 1) * (ord(alpha4) - ord(alpha3) + 1) * (dig1 + 1) * (dig2 + 1) * (dig3 + 1) * (dig4 + 1)
return possibilties
#SPJ3
Similar questions