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..92a1f4bd --- /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; + 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 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 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<