Big-O complexity analyzer prompt for code
Paste any function and get its time and space complexity explained clearly, with a faster alternative if one exists.
متى تستخدم هذا البرومبت
- When preparing for coding interviews and checking your own solutions.
- When a function is slow and you need to confirm whether it's algorithmic or environmental.
- When reviewing a pull request that touches a hot loop.
نص البرومبت
Analyze the time and space complexity (Big-O) of this {{language}} code. Explain the reasoning per section and suggest a more efficient approach if one exists.
{{CLIPBOARD}}{{language}}{{CLIPBOARD}}الكتلة {{CLIPBOARD}} تُستبدل تلقائياً بما نسخته قبل الضغط على «نسخ».
كيف تستخدمه
- انسخ البرومبت بالزر أو املأ المتغيرات أولاً.
- الصقه في ChatGPT أو Claude أو Gemini.
- عدّل النتيجة أو أعد الطلب بتغيير المتغيرات.
مثال على النتيجة
Time complexity: O(n^2), the inner indexOf call scans the array on every outer iteration. Space complexity: O(1) extra space, aside from the input array itself. Faster approach: build a Set of seen values first, reducing time to O(n) at the cost of O(n) space.
نصائح للاستخدام
- Paste the full function including any helper calls, since complexity often hides inside them.
- Ask for best-case, average-case, and worst-case separately if they differ meaningfully.
- For interview prep, ask it to also state the complexity in the standard notation you'd say out loud.
أسئلة شائعة
- Does it account for the complexity of built-in functions I call?
- Yes, it factors in the real cost of calls like indexOf, sort, or includes, not just the loops you wrote.
- Can it suggest an optimized rewrite, not just analyze?
- Yes, ask explicitly for the optimized version alongside the complexity analysis.