2483. Minimum Penalty for a Shop
Problem Statement
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
ith
character is'Y'
, it means that customers come at theith
hourwhereas
'N'
indicates that no customers come at theith
hour.
If the shop closes at the jth
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 jth
hour, it means the shop is closed at the hour j
.
Example 1:
Example 2:
Example 3:
Constraints:
1 <= customers.length <= 105
customers
consists only of characters'Y'
and'N'
.
Intuition
Links
https://leetcode.com/problems/minimum-penalty-for-a-shop/description/
Video Links
https://www.youtube.com/watch?v=iB0IGr-Huu0&ab_channel=AryanMittal
Approach 1:
Approach 2:
Approach 3:
Approach 4:
Similar Problems
Last updated