You are given a shop's customer log as a string customers of 'Y' and 'N': customers[i] is 'Y' if customers come at hour i and 'N' if none come. If the shop closes at hour j (0 <= j <= n), every open hour with no customers costs 1 and every closed hour with customers costs 1. Return the earliest hour at which the shop should close to get the minimum penalty.
You are given a shop's customer log as a string customers of 'Y' and 'N': customers[i] is 'Y' if customers come at hour i and 'N' if none come. If the shop closes at hour j (0 <= j <= n), every open hour with no customers costs 1 and every closed hour with customers costs 1. Return the earliest hour at which the shop should close to get the minimum penalty.
Example 1:
Input: {"customers":"YYNY"}
Output: 2
Constraints:
1≤customers.length≤105
customers consists only of 'Y' and 'N'.
Test Cases
Input (Stdin)
Expected Output (Stdout)
Execution Result
Run code to see results.
Input
arr ={"customers":"YYNY"}
Closing at hour 0 means every 'Y' hour is missed, a penalty of 3. Track the penalty relative to that, starting at 0, and slide the closing time right one hour at a time.