Minimum Penalty for a Shop 🔥 | LeetCode 2483 | Prefix Sum + Greedy | Optimal Solution
Автор: Study Placement
Загружено: 2025-12-25
Просмотров: 525
In this video, we solve LeetCode 2483 – Minimum Penalty for a Shop, a prefix + greedy optimization problem.
Telegram Community Channel link: https://t.me/studyplacementcommunity
Telegram Discussion Group link:
https://t.me/+iCezc5Ds9GkwZjdl
Code:
https://leetcode.com/problems/minimum...
Upsolve Leetcode Contest:
• Leetcode Contests
Greedy & Heaps:
• Greedy & Heaps
Two pointers:
• Two pointers
Sliding Window:
• Sliding Window
Maths & Geometry:
• Maths & Geometry
Stack:
• Stack
Set & Map:
• Set & Map
Bit manipulation:
• Bit Manipulation
Backtracking:
• Backtracking
Linked List:
• Linked List
Binary Search:
• Binary Search
Graph:
• Graph
Dynamic Progamming:
• Dynamic Programming
You are given a string customers consisting of 'Y' and 'N' where:
'Y' means customers come at that hour.
'N' means no customers come.
If the shop is:
Open and no customers come → penalty +1
Closed and customers come → penalty +1
Your task is to choose the best closing hour to minimize the total penalty.
🔗 Problem Link:
https://leetcode.com/problems/minimum...
Approach
Count the penalty if the shop is always closed initially.
Traverse the string and adjust penalty:
If 'Y', opening earlier reduces penalty.
If 'N', staying open increases penalty.
Track the hour where penalty becomes minimum.
Time Complexity: O(n)
Space Complexity: O(1)
#leetcode #leetcode2483 #prefixsum #greedy #strings #javacode #dsa #interviewprep #dailycodingchallenge #leetcodechallenge #codingdaily #problemSolving #competitiveprogramming #codinglife #codingjourney #placementprep #softwareengineering #codinginterview #techyoutube #learncoding #algorithms #datastructures #codingmotivation #studyplacement #javadeveloper #codingtips #codingpractice
Доступные форматы для скачивания:
Скачать видео mp4
-
Информация по загрузке: