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
17 changes: 17 additions & 0 deletions cpp/1299-Replace-Elements-with-Greatest-Element-on-Right-Side.cpp
Original file line number Diff line number Diff line change
@@ -0,0 +1,17 @@
class Solution {
public:
vector<int> replaceElements(vector<int>& arr) {
// O(N) Time Complexity , O(1) Space complexity
int n = arr.size();
int maxSoFar = arr[n-1];
arr[n-1] = -1;

for(int i=n-2;i>=0;i--)
{
int temp = maxSoFar;
if(maxSoFar < arr[i]) maxSoFar = arr[i];
arr[i] = temp;
}
return arr;
}
};
19 changes: 19 additions & 0 deletions cpp/392-Is-Subsequence.cpp
Original file line number Diff line number Diff line change
@@ -0,0 +1,19 @@
// Time Complexity is O(N) where n is the size of the target string.
// Space Complexity is O(1)

class Solution {
public:
bool isSubsequence(string s, string t) {
int i = 0 , j = 0;
while(j < s.size() && i < t.size())
{
if(s[j] == t[i])
j++;

i++;
}

if(j >= s.size()) return true;
return false;
}
};