Skip to content

Navigation Menu

Sign in
Appearance settings

Search code, repositories, users, issues, pull requests...

Provide feedback

We read every piece of feedback, and take your input very seriously.

Saved searches

Use saved searches to filter your results more quickly

Sign up
Appearance settings

Commit 5a93c09

Browse files
Merge pull request #105 from thecoderebel/addcode-new
Added Grumpy Bookstore Problem
2 parents af683e5 + 5de0964 commit 5a93c09

File tree

1 file changed

+40
-0
lines changed

1 file changed

+40
-0
lines changed
Lines changed: 40 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,40 @@
1+
//Problem Name: Grumpy Bookstore owner
2+
//Problem Link: https://leetcode.com/problems/grumpy-bookstore-owner/
3+
4+
5+
//Code:
6+
7+
class Solution {
8+
public:
9+
int maxSatisfied(vector<int>& customers, vector<int>& grumpy, int minutes) {
10+
int satisfied=0;
11+
int n= customers.size();
12+
for(int i=0;i<n;i++){
13+
if(grumpy[i]==0)
14+
satisfied+= customers[i];
15+
}
16+
int additionalsatisfied= 0;
17+
int left=0;
18+
int right= minutes;
19+
for(int i=0;i<minutes;i++){
20+
if(grumpy[i]==1)
21+
{
22+
additionalsatisfied+= customers[i];
23+
}
24+
}
25+
int maxx= additionalsatisfied;
26+
while(right<n){
27+
if(grumpy[right]==1){
28+
additionalsatisfied+= customers[right]; /* If the satisfied customer found, then include in the given window or minute.*/
29+
}
30+
if(grumpy[left]==1){
31+
additionalsatisfied-= customers[left]; /*If the unsatisfied customers found, then exclude from the window*/
32+
}
33+
maxx= max(maxx, additionalsatisfied);
34+
left++;
35+
right++;
36+
}
37+
38+
return satisfied+maxx;
39+
}
40+
};

0 commit comments

Comments
(0)

AltStyle によって変換されたページ (->オリジナル) /