Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Completed Competitive-Coding-3 #960

Open
wants to merge 2 commits into
base: master
Choose a base branch
from
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
28 changes: 28 additions & 0 deletions K-diffPairs.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,28 @@
class Solution:
def findPairs(self, nums: List[int], k: int) -> int:
# TC : O(n)
# SC : O(n)
seen = set() # Initialize a set to keep track of seen numbers
pairs = set() # Initialize a set to store unique pairs


for n in nums:
pair1 = n + k
pair2 = n - k

# Check if | val| has been seen and
# if the pair (n, pair1) is not already counted
if pair1 in seen and (pair1, n) not in seen:
pairs.add((n, pair1))

# Check if |-val| has been seen and
# if the pair (n, pair2) is not already counted
if pair2 in seen and (pair2, n) not in seen:
pairs.add((pair2, n))

# Add the current number to the seen set for future pair checks
seen.add(n)

# Return the number of unique pairs found
return len(pairs)

19 changes: 19 additions & 0 deletions PascalTriangle.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,19 @@
class Solution:
def generate(self, numRows: int) -> List[List[int]]:
# TC: O(n**2)
# SC: O(n**2)
if numRows == 0:
return []
res = [[1]]
if numRows == 1:
return res

for _ in range(numRows - 1):
dummy_row = [0] + res[-1] + [0]
row = []

for i in range(len(res[-1]) + 1):
row.append(dummy_row[i] + dummy_row[i+1])
res.append(row)

return res