From c501bf3dcba1ffe03e0b71deaab767ef3d656f4f Mon Sep 17 00:00:00 2001 From: wazedkhan Date: Wed, 4 Jun 2025 08:58:01 +0600 Subject: [PATCH 1/2] Day 05: Maximum sum sub array (GFG) --- Goal/code/jun_04_2025.py | 22 ++++++++++++++++++++++ 1 file changed, 22 insertions(+) create mode 100644 Goal/code/jun_04_2025.py diff --git a/Goal/code/jun_04_2025.py b/Goal/code/jun_04_2025.py new file mode 100644 index 0000000..2978b0e --- /dev/null +++ b/Goal/code/jun_04_2025.py @@ -0,0 +1,22 @@ +#User function Template for python3 +class Solution: + # Function to find the maximum sum of a subarray of size k + def maximumSumSubarrayBruteForce(self,arr,k): + max_sum = 0 + for i in range(0, len(arr)-k+1): + max_sum = max(max_sum, sum(arr[i: i+k])) + return max_sum + + def maximumSumSubarray(self,arr,k): + current_sum = sum(arr[:k]) + max_sum = current_sum + for i in range(k, len(arr)): + current_sum += arr[i] - arr[i - k] + max_sum = max(max_sum, current_sum) + + return max_sum + +arr = [100, 200, 300, 400] +k = 2 +solution = Solution().maximumSumSubarray(arr, k) +print("Maximum sum of subarray of size", k, "is:", solution) \ No newline at end of file From 5d655fa68aed149837e57d6da8430087c724a1f9 Mon Sep 17 00:00:00 2001 From: wazedkhan Date: Wed, 4 Jun 2025 09:26:23 +0600 Subject: [PATCH 2/2] Day 05: Frequncey sort with frequecy count(LE) --- Goal/code/jun_04_2025.py | 25 ++++++++++++++++++++----- 1 file changed, 20 insertions(+), 5 deletions(-) diff --git a/Goal/code/jun_04_2025.py b/Goal/code/jun_04_2025.py index 2978b0e..0f61b18 100644 --- a/Goal/code/jun_04_2025.py +++ b/Goal/code/jun_04_2025.py @@ -1,4 +1,4 @@ -#User function Template for python3 +# User function Template for python3 class Solution: # Function to find the maximum sum of a subarray of size k def maximumSumSubarrayBruteForce(self,arr,k): @@ -16,7 +16,22 @@ def maximumSumSubarray(self,arr,k): return max_sum -arr = [100, 200, 300, 400] -k = 2 -solution = Solution().maximumSumSubarray(arr, k) -print("Maximum sum of subarray of size", k, "is:", solution) \ No newline at end of file + def frequencySort(self, s: str) -> str: + hash_map = {} + + for char in s: + if char in hash_map: + hash_map[char] += 1 + else: + hash_map[char] = 1 + sorted_chars = sorted(hash_map.items(), key=lambda item: item[1], reverse=True) + res = "" + for item in sorted_chars: + res += item[0] * item[1] + + return res + + +char = "tree" +solution = Solution().frequencySort(s=char) +print("Res: ", solution)