Minimum Penalty for a Shop
You are given the customer visit log of a shop represented by a 0-indexed string customers consisting only of characters 'N' and 'Y':
- If the
i^thcharacter is'Y', it means that customers come at thei^thhour. - If the
i^thcharacter is'N', it indicates that no customers come at thei^thhour.
If the shop closes at the j^th hour (0 <= j <= n), the penalty is calculated as follows:
- For every hour when the shop is open and no customers come, the penalty increases by
1. - For every hour when the shop is closed and customers come, the penalty increases by
1.
Return the earliest hour at which the shop must be closed to incur a minimum penalty.
Note that if a shop closes at the j^th hour, it means the shop is closed at the hour j.
Example 1
Input
customers = "YYNY"Output
2Closing the shop at the 2^nd or 4^th hour gives a minimum penalty of 1, and 2 is earlier.
Example 2
Input
customers = "NNNNN"Output
0It is best to close the shop at the 0^th hour as no customers arrive.
Constraints
- 1 <= customers.length <= 10^5
- customers consists only of characters 'Y' and 'N'.