Skip to content

Commit 1ba9d39

Browse files
authored
Merge pull request neetcode-gh#1241 from nehalalifayed/main
Create 1299-Replace-Elements-with-Greatest-Element-on-Right-Side.cpp
2 parents 1426491 + 1e8a8aa commit 1ba9d39

File tree

2 files changed

+36
-0
lines changed

2 files changed

+36
-0
lines changed
Lines changed: 17 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,17 @@
1+
class Solution {
2+
public:
3+
vector<int> replaceElements(vector<int>& arr) {
4+
// O(N) Time Complexity , O(1) Space complexity
5+
int n = arr.size();
6+
int maxSoFar = arr[n-1];
7+
arr[n-1] = -1;
8+
9+
for(int i=n-2;i>=0;i--)
10+
{
11+
int temp = maxSoFar;
12+
if(maxSoFar < arr[i]) maxSoFar = arr[i];
13+
arr[i] = temp;
14+
}
15+
return arr;
16+
}
17+
};

cpp/392-Is-Subsequence.cpp

Lines changed: 19 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,19 @@
1+
// Time Complexity is O(N) where n is the size of the target string.
2+
// Space Complexity is O(1)
3+
4+
class Solution {
5+
public:
6+
bool isSubsequence(string s, string t) {
7+
int i = 0 , j = 0;
8+
while(j < s.size() && i < t.size())
9+
{
10+
if(s[j] == t[i])
11+
j++;
12+
13+
i++;
14+
}
15+
16+
if(j >= s.size()) return true;
17+
return false;
18+
}
19+
};

0 commit comments

Comments
 (0)