Skip to content
Open
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
22 changes: 22 additions & 0 deletions containerwithmostwater.cpp
Original file line number Diff line number Diff line change
@@ -0,0 +1,22 @@
class Solution {
public:
int maxArea(vector<int>& height) {
int n = height.size();
int maximum = 0;
//declare a left pointer and a right pointer
int lpointer = 0;
int rpointer = n - 1;

while(lpointer < rpointer){//making sure left doesnt cross right
int currArea = min(height[lpointer], height[rpointer]) * (rpointer - lpointer);//min of height at left anf right multiplied by width gives us the area
maximum = max(maximum , currArea);//compare previous maximum and curr area and update
if(height[lpointer] < height[rpointer]){
lpointer ++;
}else{
rpointer--;
}
}

return maximum;
}
};
28 changes: 28 additions & 0 deletions sortcolours.cpp
Original file line number Diff line number Diff line change
@@ -0,0 +1,28 @@
class Solution {
public:
void sortColors(vector<int>& nums) {
int n = nums.size();
int left = 0;
int mid = 0;
int right = n-1;
while(mid <= right){
if(nums[mid] == 2){
swap(nums,mid,right);
right--;
}else if(nums[mid] == 0){
swap(nums,mid,left);
left++;
mid++;
}else{
mid++;
}
}
}

private:
void swap(vector<int>& nums, int mid, int idx) {
int temp = nums[idx];
nums[idx] = nums[mid];
nums[mid] = temp;
}
};
Empty file added threesum.cpp
Empty file.