Skip to content

Commit d7fe666

Browse files
authored
Teemo Attacking (#58)
* teemo-attacking.cpp added * Comments added * Comments added and README.md updated
1 parent f4c3806 commit d7fe666

File tree

2 files changed

+31
-0
lines changed

2 files changed

+31
-0
lines changed

Diff for: C++/teemo-attacking.cpp

+29
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,29 @@
1+
//https://leetcode.com/problems/teemo-attacking/
2+
//Difficulty Level: Medium
3+
//Tags: Arrays
4+
//Time complexity: O(n)
5+
//Space complexity: O(1)
6+
//similar to overlapping subintervals problems
7+
8+
class Solution {
9+
public:
10+
int findPoisonedDuration(vector<int>& timeSeries, int duration) {
11+
12+
int n = timeSeries.size();
13+
if(n==0)
14+
return 0;
15+
16+
int ans = duration;
17+
18+
for(int i=0; i<n-1; i++)
19+
{
20+
ans += duration;
21+
if(timeSeries[i+1] < timeSeries[i] + duration) //overlapping condition
22+
{
23+
ans -= (timeSeries[i] + duration - timeSeries[i+1]); //the overlapped time subtracted
24+
}
25+
}
26+
27+
return ans;
28+
}
29+
};

Diff for: README.md

+2
Original file line numberDiff line numberDiff line change
@@ -100,6 +100,7 @@ Check out ---> [Sample PR](https://github.com/codedecks-in/LeetCode-Solutions/pu
100100
| 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 | | |
101101
| 53 | [Maximum Subarray](https://leetcode.com/problems/maximum-subarray/) | [C++](./C++/maximum-subarray.cpp) | _O(N)_ | _O(1)_ |Easy | Array | |
102102
| 1 | [Two Sum](https://leetcode.com/problems/two-sum/) | [C++](./C++/two-sum.cpp) | _O(N^2)_ | _O(1)_ |Easy | Array | |
103+
| 495 | [Teemo Attacking](https://leetcode.com/problems/teemo-attacking) | [C++](./C++/teemo-attacking.cpp) | _O(n)_ | _O(1)_ | Medium| Array | |
103104

104105
<br/>
105106
<div align="right">
@@ -359,6 +360,7 @@ DISCLAIMER: This above mentioned resources have affiliate links, which means if
359360
|[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/) |
360361
|[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/) |
361362
|[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/) |
363+
|[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/) |
362364

363365
<br/>
364366
<div align="right">

0 commit comments

Comments
 (0)