Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
29 changes: 29 additions & 0 deletions C++/teemo-attacking.cpp
Original file line number Diff line number Diff line change
@@ -0,0 +1,29 @@
//https://leetcode.com/problems/teemo-attacking/
//Difficulty Level: Medium
//Tags: Arrays
//Time complexity: O(n)
//Space complexity: O(1)
//similar to overlapping subintervals problems

class Solution {
public:
int findPoisonedDuration(vector<int>& timeSeries, int duration) {

int n = timeSeries.size();
if(n==0)
return 0;

int ans = duration;

for(int i=0; i<n-1; i++)
{
ans += duration;
if(timeSeries[i+1] < timeSeries[i] + duration) //overlapping condition
{
ans -= (timeSeries[i] + duration - timeSeries[i+1]); //the overlapped time subtracted
}
}

return ans;
}
};
2 changes: 2 additions & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -100,6 +100,7 @@ Check out ---> [Sample PR](https://github.com/codedecks-in/LeetCode-Solutions/pu
| 811 | [Subdomain Visit Count](https://leetcode.com/problems/subdomain-visit-count/) | [Javascript](./JavaScript/Subdomain-Visit-Count.js) | _O(N*M)_ | _O(N*M + N)_ | Easy | | |
| 53 | [Maximum Subarray](https://leetcode.com/problems/maximum-subarray/) | [C++](./C++/maximum-subarray.cpp) | _O(N)_ | _O(1)_ |Easy | Array | |
| 1 | [Two Sum](https://leetcode.com/problems/two-sum/) | [C++](./C++/two-sum.cpp) | _O(N^2)_ | _O(1)_ |Easy | Array | |
| 495 | [Teemo Attacking](https://leetcode.com/problems/teemo-attacking) | [C++](./C++/teemo-attacking.cpp) | _O(n)_ | _O(1)_ | Medium| Array | |

<br/>
<div align="right">
Expand Down Expand Up @@ -359,6 +360,7 @@ DISCLAIMER: This above mentioned resources have affiliate links, which means if
|[Avinash Trivedi](https://github.com/trivediavinash) <br> <img src="https://github.com/trivediavinash.png" width="100" height="100"> |India | C++ | [Leetcode](https://leetcode.com/avi_002/) |
|[Ishika Goel](https://github.com/ishikagoel5628) <br> <img src="https://github.com/Nour-Grati.png" width="100" height="100"> | India | C++ | [Leetcode](https://leetcode.com/ishikagoel5628/) |
|[Prashansa Tanwar](https://github.com/prashansatanwar) <br> <img src="https://github.com/prashansatanwar.png" width="100" height="100"> | India | C++ | [Leetcode](https://leetcode.com/prashansaaa/) |
|[Ishu Raj](https://github.com/ir2010) <br> <img src="https://github.com/ir2010.png" width="100" height="100"> | India | C++ | [Leetcode](https://leetcode.com/ishuraj2010/) |

<br/>
<div align="right">
Expand Down