From 9b9aec8f836920e340f0708b435b085795da1da1 Mon Sep 17 00:00:00 2001 From: kalpana <154818080+Kalpana8055@users.noreply.github.com> Date: Wed, 24 Jan 2024 03:21:42 +0000 Subject: [PATCH 1/4] Day 17 Q1: Determine if Two Strings Are Close #399 solved by c++ --- .../kalpana--cpp.md | 40 +++++++++++++++++++ 1 file changed, 40 insertions(+) create mode 100644 Day-17/Q1:Determine if two strings are close/kalpana--cpp.md diff --git a/Day-17/Q1:Determine if two strings are close/kalpana--cpp.md b/Day-17/Q1:Determine if two strings are close/kalpana--cpp.md new file mode 100644 index 00000000..d4323844 --- /dev/null +++ b/Day-17/Q1:Determine if two strings are close/kalpana--cpp.md @@ -0,0 +1,40 @@ +class Solution { + public: + bool closeStrings(string word1, string word2) { + if (word1.length() != word2.length()) + return false; + + unordered_map count1; + unordered_map count2; + string s1; // Unique chars in word1 + string s2; + vector freqs1; + vector freqs2; + + for (const char c : word1) + ++count1[c]; + + for (const char c : word2) + ++count2[c]; + + for (const auto& [c, freq] : count1) { + s1 += c; + freqs1.push_back(freq); + } + + for (const auto& [c, freq] : count2) { + s2 += c; + freqs2.push_back(freq); + } + + ranges::sort(s1); + ranges::sort(s2); + + if (s1 != s2) + return false; + + ranges::sort(freqs1); + ranges::sort(freqs2); + return freqs1 == freqs2; + } +}; \ No newline at end of file From 9a6b9d8635d2d52871da1a0a6b5ff96b9d715469 Mon Sep 17 00:00:00 2001 From: kalpana <154818080+Kalpana8055@users.noreply.github.com> Date: Wed, 24 Jan 2024 03:23:15 +0000 Subject: [PATCH 2/4] Day 17 Q1: Determine if Two Strings Are Close #399 solved by cpp --- Day-17/Q1:Determine if two strings are close/kalpana--cpp.md | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/Day-17/Q1:Determine if two strings are close/kalpana--cpp.md b/Day-17/Q1:Determine if two strings are close/kalpana--cpp.md index d4323844..92a1f4bd 100644 --- a/Day-17/Q1:Determine if two strings are close/kalpana--cpp.md +++ b/Day-17/Q1:Determine if two strings are close/kalpana--cpp.md @@ -6,7 +6,7 @@ class Solution { unordered_map count1; unordered_map count2; - string s1; // Unique chars in word1 + string s1; string s2; vector freqs1; vector freqs2; From 6b7ee76586526246cdacaa548361d5601b4deead Mon Sep 17 00:00:00 2001 From: kalpana <154818080+Kalpana8055@users.noreply.github.com> Date: Wed, 24 Jan 2024 15:03:10 +0000 Subject: [PATCH 3/4] Day 21: Q2 - Container With Most Water #421by python solved --- .../kalpana--python.md | 18 ++++++++++++++++++ 1 file changed, 18 insertions(+) create mode 100644 Day-21/q2 : Container With Most Water/kalpana--python.md diff --git a/Day-21/q2 : Container With Most Water/kalpana--python.md b/Day-21/q2 : Container With Most Water/kalpana--python.md new file mode 100644 index 00000000..d9218ce9 --- /dev/null +++ b/Day-21/q2 : Container With Most Water/kalpana--python.md @@ -0,0 +1,18 @@ +class Solution(object): + def maxArea(self, height): + """ + :type height: List[int] + :rtype: int + """ + left = 0 + right = len(height) - 1 + distance = right - left + max_area = 0 + while left < right: + max_area = max(min(height[left],height[right]) * distance, max_area) + if height[left] < height[right]: + left += 1 + else: + right -= 1 + distance -= 1 + return max_area \ No newline at end of file From 6f621b08b93f8ea97657eacabbe8efd6cad4c42e Mon Sep 17 00:00:00 2001 From: kalpana <154818080+Kalpana8055@users.noreply.github.com> Date: Sat, 27 Jan 2024 14:21:32 +0000 Subject: [PATCH 4/4] Day-26 q3: Find first and last position of element in sorted array #560 --- .../kalpana--cpp.md | 16 ++++++++++++++++ 1 file changed, 16 insertions(+) create mode 100644 Day-26/q3: Find first and last position of element in sorted array/kalpana--cpp.md diff --git a/Day-26/q3: Find first and last position of element in sorted array/kalpana--cpp.md b/Day-26/q3: Find first and last position of element in sorted array/kalpana--cpp.md new file mode 100644 index 00000000..b1a8f1aa --- /dev/null +++ b/Day-26/q3: Find first and last position of element in sorted array/kalpana--cpp.md @@ -0,0 +1,16 @@ +class Solution { +public: + vector searchRange(vector& nums, int target) { + vector ans(2,-1); + if(nums.size()==0)return ans; + int t1=lower_bound(nums.begin(),nums.end(),target)-nums.begin(); + int t2=upper_bound(nums.begin(),nums.end(),target)-nums.begin(); + if(t1==t2)return ans; + cout<