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

Done Competetive-Coding-3 #930

Open
wants to merge 1 commit 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
27 changes: 27 additions & 0 deletions Problem-1.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,27 @@
# Approach
# since every index isdepend on the previous row i, i-1
# recuurelation = curr[i] = prev[i]+prev[i-1]


#Complexities
# Time Complexity: O(N*N)
# Space Complexity: O(N)

def pascalTriangle(num):
num = num+1
if num ==1:
return[1]

prev = [1]
for i in range(2,num+1):
curr = [1]
for j in range(1,i-1):

curr.append(prev[j-1]+prev[j])
curr.append(1)
prev = curr

return prev


print(pascalTriangle(5))
33 changes: 33 additions & 0 deletions Problem-2.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,33 @@
#Approach
# Since We need to find the absolute difference is k . if num+ target or num-target is present in the hashSet then add thenum, num-target in the resukt


#Complexities
# Time Complexity: 0(N)
# Space Complexity: O(N)




from typing import List


class Solution:
def findPairs(self, nums: List[int], k: int) -> int:
hashSet = set()
result = set()
for i in nums:
if i - k in hashSet:
if i > i - k:

result.add((i, i - k))
else:
result.add((i - k, i))
if i + k in hashSet:
if i > i + k:
result.add((i, i + k))
else:
result.add((i + k, i))
hashSet.add(i)

return len(set(result))