diff --git a/Challenge-1/README.md b/Challenge-1/README.md new file mode 100644 index 0000000..f7c9fcc --- /dev/null +++ b/Challenge-1/README.md @@ -0,0 +1 @@ +saheed muhammed diff --git a/Challenge-2/solution.py b/Challenge-2/solution.py new file mode 100644 index 0000000..2f72754 --- /dev/null +++ b/Challenge-2/solution.py @@ -0,0 +1,9 @@ +class Solution: + def twoSum(self, nums: List[int], target: int) -> List[int]: + prev_map=dict() + for i, num in enumerate(nums): + if target - num in prev_map: + return[i, prev_map[target-num]] + prev_map[num]=i + + return -1 \ No newline at end of file diff --git a/Challenge-4/Duplicate.py b/Challenge-4/Duplicate.py new file mode 100644 index 0000000..c99aed3 --- /dev/null +++ b/Challenge-4/Duplicate.py @@ -0,0 +1,9 @@ +class Solution: + def containsDuplicate(self, nums: List[int]) -> bool: + hash_set=set() + + for num in nums: + if num in hash_set: + return True + hash_set.add(num) + return False diff --git a/Challenge-5/solution.js b/Challenge-5/solution.js new file mode 100644 index 0000000..b1f843f --- /dev/null +++ b/Challenge-5/solution.js @@ -0,0 +1,16 @@ +/** + * @param {number} a + * @param {number} b + * @return {number} + */ +var getSum = function(a, b) { + + while(b){ + let temp=a + a=temp^b + b=(temp&b)<<1 + } + return a + + +}; \ No newline at end of file diff --git a/Challenge_3/solution.py b/Challenge_3/solution.py new file mode 100644 index 0000000..da69616 --- /dev/null +++ b/Challenge_3/solution.py @@ -0,0 +1,16 @@ +class Solution: + def maxProfit(self, prices: List[int]) -> int: + # tow pointer + left, right = 0, 1 + profit = 0 + + while right < len(prices): + # Check if profitable + if prices[right] > prices[left]: + profit = max(profit, prices[right] - prices[left]) + else: + left = right # Update left pointer to the current right + + right += 1 # Move the right pointer forward + + return profit \ No newline at end of file