From 6c5e17a170f08b642fa802938151b5f39b0346a4 Mon Sep 17 00:00:00 2001 From: pratikb0501 Date: Sat, 2 May 2026 16:46:26 -0700 Subject: [PATCH] Completed Competative Coding 3 --- Problem_1.py | 14 ++++++++++++++ Problem_2.py | 16 ++++++++++++++++ README.md | 9 +++++++++ 3 files changed, 39 insertions(+) create mode 100644 Problem_1.py create mode 100644 Problem_2.py diff --git a/Problem_1.py b/Problem_1.py new file mode 100644 index 00000000..1b96247e --- /dev/null +++ b/Problem_1.py @@ -0,0 +1,14 @@ +# https://leetcode.com/problems/k-diff-pairs-in-an-array/ + +class Solution: + def findPairs(self, nums, k): + count_map = {} + for num in nums: + count_map[num] = count_map.get(num, 0) + 1 + result = 0 + for x in count_map.keys(): + if k > 0 and x + k in count_map: + result += 1 + if k == 0 and count_map[x] > 1: + result += 1 + return result diff --git a/Problem_2.py b/Problem_2.py new file mode 100644 index 00000000..2f218a5b --- /dev/null +++ b/Problem_2.py @@ -0,0 +1,16 @@ +# https://leetcode.com/problems/pascals-triangle/ + +class Solution: + def generate(self, numRows): + result = [[1]] + for row in range(1, numRows): + temp = [] + for i in range(row + 1): + if i == 0: + temp.append(result[row - 1][i]) + elif i == row: + temp.append(result[row - 1][i - 1]) + else: + temp.append(result[row - 1][i] + result[row - 1][i - 1]) + result.append(temp) + return result diff --git a/README.md b/README.md index f7a4d082..5f429809 100644 --- a/README.md +++ b/README.md @@ -1,3 +1,12 @@ # Competitive_Coding-3 Please submit the interview problems posted in slack channel here. The problems and statements are intentionally not shown here so that students are not able to see them in advance + +K-diff Pairs in an Array +https://youtu.be/KTPnDMhWnoE + +Pascal's Triangle +https://youtu.be/LZnp0rpEc1U + +Contest Solutions: +https://www.thes30.com/problem/5db27d9ba368590004f8f324/solutions