Skip to content

Commit

Permalink
fixed some things, time for a revamp
Browse files Browse the repository at this point in the history
  • Loading branch information
Tamrakar182 committed Nov 20, 2023
1 parent 3ea6b9d commit 58f6616
Show file tree
Hide file tree
Showing 5 changed files with 103 additions and 4 deletions.
9 changes: 5 additions & 4 deletions .gitignore
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
.vscode/settings.json
.obsidian/*
.obsidian/

.vscode/settings.json
.obsidian/*
.obsidian/
template/

43 changes: 43 additions & 0 deletions docs/LeetCode 75/Day 12 Container With Most Water.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,43 @@
# 11. Container With Most Water

Tags: #array #twopointers #greedy #medium

### Problem Statement
You are given an integer array `height` of length `n`. There are `n` vertical lines drawn such that the two endpoints of the `ith` line are `(i, 0)` and `(i, height[i])`.

Find two lines that together with the x-axis form a container, such that the container contains the most water.

Return _the maximum amount of water a container can store_.

**Notice** that you may not slant the container.

![LeetCodeExample](https://s3-lc-upload.s3.amazonaws.com/uploads/2018/07/17/question_11.jpg)


```Example
Input: height = [1,8,6,2,5,4,8,3,7]
Output: 49
Explanation: The above vertical lines are represented by array [1,8,6,2,5,4,8,3,7]. In this case, the max area of water (blue section) the container can contain is 49.
```

### My Approach
```Python
class Solution:
def maxArea(self, height: List[int]) -> int:
i = 0
j = len(height)-1
temp = 0
primary = 0
while(i<j):
temp = min(height[i], height[j])*(j-i)
if temp > primary:
primary = temp
if height[j]>height[i]:
i+=1
else:
j-=1
return primary
```


### Personal Thoughts
Empty file removed docs/LeetCode 75/Day 12.md
Empty file.
43 changes: 43 additions & 0 deletions docs/LeetCode 75/Day 13 Max Number of K-Sum Pairs.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,43 @@
# 1679. Max Number of K-Sum Pairs

Tags: #array #twopointers #sorting #hashtable #medium

### Problem Statement
You are given an integer array `nums` and an integer `k`.

In one operation, you can pick two numbers from the array whose sum equals `k` and remove them from the array.

Return _the maximum number of operations you can perform on the array_.

```Example
Input: nums = [1,2,3,4], k = 5
Output: 2
Explanation: Starting with nums = [1,2,3,4]:
- Remove numbers 1 and 4, then nums = [2,3]
- Remove numbers 2 and 3, then nums = []
There are no more pairs that sum up to 5, hence a total of 2 operations.
```

### My Approach
```Python
class Solution:
def maxOperations(self, nums: List[int], k: int) -> int:
i = 0
j = len(nums)-1
count = 0
nums.sort()

while(i<j):
sum =nums[i]+nums[j]
if sum == k:
count +=1
i+=1
j-=1
elif sum < k:
i+=1
else:
j-=1
return count
```

### Personal Thoughts
12 changes: 12 additions & 0 deletions docs/index.md
Original file line number Diff line number Diff line change
Expand Up @@ -21,3 +21,15 @@ These are my notes for the ["Ace Coding Interview with 75 Qs"](https://leetcode.
- [[Day 6 Reverse Words in a String]]

- [[Day 7 Product of Array Except Self]]

- [[Day 8 Increasing Triplet Subsequence]]

- [[Day 9 String Compression]]

- [[Day 10 Move Zeroes]]

- [[Day 11 Is Subsequence]]

- [[Day 12 Container With Most Water]]

- [[Day 13 Max Number of K-Sum Pairs]]

0 comments on commit 58f6616

Please sign in to comment.