Dataford
Interview QuestionsInterview GuidesExperiencesMock InterviewsPricing
Get started

Estimating Algorithm Complexity

EasyPython00:00
Practice interviewer
In session
5 left
00:00

Your question is Estimating Algorithm Complexity. Start with the requirements on the right.

Run and submit as often as you like. When you're ready, talk me through your approach or go straight to the code.

You need to log in / sign up to run or submit.

Problem

Estimate the complexity of an algorithm.

Analyze an algorithm containing two independent loops, each iterating over an input of size n, and return its time and auxiliary space complexity. Implement estimate_complexity(n) to return [time_complexity, space_complexity] for this fixed algorithm pattern.

Use n >= 1; the output must be ["O(n^2)", "O(1)"].

Constraints

  • 1 <= n <= 10^9
  • The algorithm pattern is fixed: two loops, each ranging from 0 through n - 1
  • Return time complexity before space complexity

Function Signature

def estimate_complexity(n):
Your solutionPython 3
You need to log in / sign up to run or submit.
Run your code to see test output