Yooshiii commited on
Commit
772d13a
·
verified ·
1 Parent(s): e49a003

Update merge_server.py

Browse files
Files changed (1) hide show
  1. merge_server.py +8 -1
merge_server.py CHANGED
@@ -219,7 +219,14 @@ def predict():
219
  "recommended_name": "Binary Search (O(log n))",
220
  "recommended_code": "import bisect\ndef [FUNC_NAME]_binary([ARGS]):\n idx = bisect.bisect_left([FIRST_ARG], target)\n if idx < len([FIRST_ARG]) and [FIRST_ARG][idx] == target:\n return idx\n return -1"
221
  },
222
-
 
 
 
 
 
 
 
223
  # --- RECURSION, DP, & MATH ---
224
  "Fibonacci Sequence": {
225
  "space": "O(n)",
 
219
  "recommended_name": "Binary Search (O(log n))",
220
  "recommended_code": "import bisect\ndef [FUNC_NAME]_binary([ARGS]):\n idx = bisect.bisect_left([FIRST_ARG], target)\n if idx < len([FIRST_ARG]) and [FIRST_ARG][idx] == target:\n return idx\n return -1"
221
  },
222
+ "Nested Iterative": {
223
+ "space": "O(1)",
224
+ "explanation": "⚠️ WARNING: Nested loops usually indicate a 'brute force' O(n^2) time complexity. This scales poorly for large datasets and can often be optimized.",
225
+ "improvements": ["Check if the inner loop can be replaced with a Hash Map (dictionary) for O(1) lookups.", "If analyzing contiguous subarrays, switch to the Sliding Window technique (O(n))."],
226
+ "optimized_code": "def [FUNC_NAME]([ARGS]):\n n = len([FIRST_ARG])\n # If you MUST use nested loops, ensure the inner loop shrinks each pass (j = i + 1)\n for i in range(n):\n for j in range(i + 1, n):\n pass # Your logic here\n return [FIRST_ARG]",
227
+ "recommended_name": "Hash Map Lookup OR Sliding Window (O(n))",
228
+ "recommended_code": "# --- OPTION 1: HASH MAP (For finding pairs/duplicates) ---\ndef [FUNC_NAME]_hashmap([ARGS]):\n seen = set()\n for item in [FIRST_ARG]:\n if item in seen: return item\n seen.add(item)\n return [FIRST_ARG]\n\n# --- OPTION 2: SLIDING WINDOW (For subarrays) ---\ndef [FUNC_NAME]_window([ARGS], k=2):\n # Assumes [FIRST_ARG] is a list of numbers\n window_sum = sum([FIRST_ARG][:k])\n for i in range(len([FIRST_ARG]) - k):\n window_sum = window_sum - [FIRST_ARG][i] + [FIRST_ARG][i+k]\n return window_sum"
229
+ },
230
  # --- RECURSION, DP, & MATH ---
231
  "Fibonacci Sequence": {
232
  "space": "O(n)",