From 450193c8c25bfbab016c09f0684f379048c0fe1a Mon Sep 17 00:00:00 2001 From: Rushorgir Date: Sun, 19 Oct 2025 21:32:17 +0530 Subject: [PATCH] CompetitiveProgramming: Added leetcode solutions for Q1614, Q2697, Q2859, and Q3019 in Python. --- .../Programs/Python/Leetcode/Q1614.py | 10 ++++++++++ .../Programs/Python/Leetcode/Q2697.py | 3 +++ .../Programs/Python/Leetcode/Q2859.py | 10 ++++++++++ .../Programs/Python/Leetcode/Q3019.py | 9 +++++++++ 4 files changed, 32 insertions(+) create mode 100644 Domains/CompetitiveProgramming/Programs/Python/Leetcode/Q1614.py create mode 100644 Domains/CompetitiveProgramming/Programs/Python/Leetcode/Q2697.py create mode 100644 Domains/CompetitiveProgramming/Programs/Python/Leetcode/Q2859.py create mode 100644 Domains/CompetitiveProgramming/Programs/Python/Leetcode/Q3019.py diff --git a/Domains/CompetitiveProgramming/Programs/Python/Leetcode/Q1614.py b/Domains/CompetitiveProgramming/Programs/Python/Leetcode/Q1614.py new file mode 100644 index 00000000..1e3db521 --- /dev/null +++ b/Domains/CompetitiveProgramming/Programs/Python/Leetcode/Q1614.py @@ -0,0 +1,10 @@ +class Solution: + def maxDepth(self, s: str) -> int: + max_depth=0 + for i in range(len(s)): + l=s.count("(",0,i) + r=s.count(")",0,i) + depth=l-r + if depth>=max_depth: + max_depth=depth + return max_depth \ No newline at end of file diff --git a/Domains/CompetitiveProgramming/Programs/Python/Leetcode/Q2697.py b/Domains/CompetitiveProgramming/Programs/Python/Leetcode/Q2697.py new file mode 100644 index 00000000..14aff9ba --- /dev/null +++ b/Domains/CompetitiveProgramming/Programs/Python/Leetcode/Q2697.py @@ -0,0 +1,3 @@ +class Solution: + def makeSmallestPalindrome(self, s: str) -> str: + return ''.join(map(min, zip(s, s[::-1]))) \ No newline at end of file diff --git a/Domains/CompetitiveProgramming/Programs/Python/Leetcode/Q2859.py b/Domains/CompetitiveProgramming/Programs/Python/Leetcode/Q2859.py new file mode 100644 index 00000000..6f0623af --- /dev/null +++ b/Domains/CompetitiveProgramming/Programs/Python/Leetcode/Q2859.py @@ -0,0 +1,10 @@ +class Solution: + def sumIndicesWithKSetBits(self, nums: List[int], k: int) -> int: + l=len(nums) + sum=0 + for i in range(l): + b=str(bin(i)) + o=b.count("1") + if o==k: + sum+=nums[i] + return sum \ No newline at end of file diff --git a/Domains/CompetitiveProgramming/Programs/Python/Leetcode/Q3019.py b/Domains/CompetitiveProgramming/Programs/Python/Leetcode/Q3019.py new file mode 100644 index 00000000..d442da2d --- /dev/null +++ b/Domains/CompetitiveProgramming/Programs/Python/Leetcode/Q3019.py @@ -0,0 +1,9 @@ +class Solution: + def countKeyChanges(self, s: str) -> int: + s1=s.lower() + c=0 + for i in range(len(s1)-1): + j=i+1 + if s1[i]!=s1[j]: + c+=1 + return c \ No newline at end of file