Skip to content

Commit

Permalink
final update before daily commit
Browse files Browse the repository at this point in the history
  • Loading branch information
Tamrakar182 committed Jul 7, 2023
1 parent 562a26b commit 07fe9c0
Show file tree
Hide file tree
Showing 9 changed files with 50 additions and 14 deletions.
4 changes: 3 additions & 1 deletion docs/LeetCode 75/Day 1 Merge Strings Alternately.md
Original file line number Diff line number Diff line change
@@ -1,4 +1,6 @@
#twopointers #string
# 1768. Merge Strings Alternately

Topics: #twopointers #string #easy

### Problem Statement
You are given two strings `word1` and `word2`. Merge the strings by adding letters in alternating order, starting with `word1`. If a string is longer than the other, append the additional letters onto the end of the merged string.
Expand Down
4 changes: 3 additions & 1 deletion docs/LeetCode 75/Day 2 Greatest Common Divisor of Strings.md
Original file line number Diff line number Diff line change
@@ -1,4 +1,6 @@
#Math #string
# 1071. Greatest Common Divisor of Strings

Tags: #Math #string #easy

### Problem Statement
For two strings `s` and `t`, we say "`t` divides `s`" if and only if `s = t + ... + t` (i.e., `t` is concatenated with itself one or more times).
Expand Down
Original file line number Diff line number Diff line change
@@ -1,4 +1,6 @@
#array
# 1431. Kids With the Greatest Number of Candies

Tags: #array #easy

### Problem Statement
There are `n` kids with candies. You are given an integer array `candies`, where each `candies[i]` represents the number of candies the `ith` kid has, and an integer `extraCandies`, denoting the number of extra candies that you have.
Expand Down
7 changes: 5 additions & 2 deletions docs/LeetCode 75/Day 4 Can Place Flowers.md
Original file line number Diff line number Diff line change
@@ -1,4 +1,6 @@
#array #greedy
# 605. Can Place Flowers

Tags: #array #greedy #easy

### Problem Statement
You have a long flowerbed in which some of the plots are planted, and some are not. However, flowers cannot be planted in **adjacent** plots.
Expand All @@ -25,7 +27,8 @@ def func(array, n):
return True
return False
```

In my approach, I just made a loop so that it checked whether the current element, the next element and the next-next element is ``one`` upon which we iterate over to the next element otherwise, we increment the ``count`` and iterate over to the next-next element since, the next element has already been checked. After the loop, if the counter variable is equals to the given number then, we return ``True`` otherwise ``False``

### Personal Thoughts
Another Trivial question. The initial concept was quite interesting to figure out and luckily the implementation worked once we (Me and My Friend) thought about the problem properly.

9 changes: 5 additions & 4 deletions docs/LeetCode 75/Day 5 Reverse Vowels of a String.md
Original file line number Diff line number Diff line change
@@ -1,4 +1,6 @@
#twopointers #string
# 345. Reverse Vowels of a String

Tags: #twopointers #string #easy

### Problem Statement
Given a string `s`, reverse only all the vowels in the string and return it.
Expand All @@ -19,8 +21,6 @@ class Solution:
j = len(s)-1
vowel = "aeiouAEIOU"
s = list(s)


while i<j:
if s[i] in vowel and s[j] in vowel:
s[i], s[j] = s[j], s[i]
Expand All @@ -36,6 +36,7 @@ class Solution:
s ="".join(map(str,s))
return s
```

In my approach, first I took a ``vowel`` string to check against every list item. In a while loop, I checked whether the current element and the last element was in the vowels list, upon which if the condition was True, I swapped them and incremented ``i`` and decremented ``j``. For the other condition, if we only found vowel match in the current element then, we increment ``i`` otherwise if we only found in the last element then, we decrement ``j``. Finally, if none of those conditions match, then we increment both ``i`` and ``j`` to reach over to the next element. Finally, we join the array of character and return it as a string.

### Personal Thoughts
This was another wonderful solution presented by one of my friends which was implemented. Collaborative problem solving is very effective and can help to solve problem effectively by brainstroming.
10 changes: 7 additions & 3 deletions docs/LeetCode 75/Day 6 Reverse Words in a String.md
Original file line number Diff line number Diff line change
@@ -1,4 +1,6 @@
#twopointers #string
# 151. Reverse Words in a String

Tags: #twopointers #string #medium

### Problem Statement
Given an input string `s`, reverse the order of the **words**.
Expand All @@ -19,13 +21,13 @@ Explanation: Your reversed string should not contain leading or trailing spaces.
```Python
class Solution:
def reverseWords(self, s: str) -> str:
a = " ".join(s.split()).split(" ")
a = s.split()
if ( len(a) == 1):
return s
return " ".join(a[::-1])

```

In my approach, I kinda cheated for this problem since I used python's built in methods to first split the given string into an array of words using ``s.split()`` and then checked if the length of the array was 1, if it was returned the original string otherwise I first reversed the array through ``a[::-1]`` and then used ``" ".join()`` to add the spaces in between words and return a string.
```Python
class Solution:
def reverseWords(self, s: str) -> str:
Expand All @@ -52,5 +54,7 @@ class Solution:
ans.append("".join(temp[::-1]))
return " ".join(ans)
```
Although my approach isn't the modal solution for the problem, I have found this solution which matches the LeetCode Description and solves the problem statement using the two pointer approach. The code comments pretty much explain the code.

### Personal Thoughts
Well even though I took the more hacky approach, I do think it is a valid solution to the problem since there were no restrictions in the problem statement *(Foreshadowing)*. I learned a lot too by going through the other solution that's why I included it here.
6 changes: 4 additions & 2 deletions docs/LeetCode 75/Day 7 Product of Array Except Self.md
Original file line number Diff line number Diff line change
@@ -1,11 +1,13 @@
#array #prefixsum
# 238. Product of Array Except Self

Tags: #array #prefixsum #medium

### Problem Statement
Given an integer array `nums`, return _an array_ `answer` _such that_ `answer[i]` _is equal to the product of all the elements of_ `nums` _except_ `nums[i]`.

The product of any prefix or suffix of `nums` is **guaranteed** to fit in a **32-bit** integer.

You must write an algorithm that runs in `O(n)` time and without using the division operation.
***You must write an algorithm that runs in `O(n)` time and without using the division operation.***

```Example
Input: nums = [-1,1,0,-3,3]
Expand Down
20 changes: 20 additions & 0 deletions docs/LeetCode 75/Day 8 Increasing Triplet Subsequence.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,20 @@
# 334. Increasing Triplet Subsequence

Tags: #array #greedy #medium

### Problem Statement
Given an integer array `nums`, return `true` _if there exists a triple of indices_ `(i, j, k)` _such that_ `i < j < k` _and_ `nums[i] < nums[j] < nums[k]`. If no such indices exists, return `false`.

**Follow up:** Could you implement a solution that runs in `O(n)` time complexity and `O(1)` space complexity?

```Example
Input: nums = [2,1,5,0,4,6]
Output: true
Explanation: The triplet (3, 4, 5) is valid because nums[3] == 0 < nums[4] == 4 < nums[5] == 6.
```

### My approach
```Python
```

### Personal Thoughts
Empty file removed docs/LeetCode 75/Day 8.md
Empty file.

0 comments on commit 07fe9c0

Please sign in to comment.