diff --git a/Problem-1.py b/Problem-1.py new file mode 100644 index 00000000..b577bd97 --- /dev/null +++ b/Problem-1.py @@ -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)) \ No newline at end of file diff --git a/Problem-2.py b/Problem-2.py new file mode 100644 index 00000000..1a6edfc1 --- /dev/null +++ b/Problem-2.py @@ -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)) \ No newline at end of file