HomeInterview QuestionsWhat is the time complexity of the code written?

What is the time complexity of the code written?

🟡 Medium Conceptual Junior level
1Times asked
Apr 2026Last seen
Apr 2026First seen

💡 Model Answer

To determine the time complexity, analyze the loops, recursive calls, and data structure operations in the code. For instance, if the code contains a single for-loop that iterates over n elements, the complexity is O(n). If there are nested loops, multiply the sizes: a double loop over n elements yields O(n²). Recursive functions often follow recurrence relations; for example, a divide‑and‑conquer algorithm that splits the input in half and processes each half recursively has T(n) = 2T(n/2) + O(1), which solves to O(n log n). Also consider the cost of operations on data structures: accessing an array element is O(1), but inserting into a balanced binary search tree is O(log n). Summarize the dominant term to give the overall time complexity.

This answer was generated by AI for study purposes. Use it as a starting point — personalize it with your own experience.

🎤 Get questions like this answered in real-time

Assisting AI listens to your interview, captures questions live, and gives you instant AI-powered answers — invisible to screen sharing.

Get Assisting AI — Starts at ₹500