‹ Back to Home

You cannot clear a coding round without Big-O

The code ran. The interviewer still asked time complexity. Here is Big-O the way a senior on OMR would explain it in an hour: Python you can run, loops you can read, and the data-structure costs Indian rounds actually want.

Keerthika 7 min read
Follow on Google
Programming You cannot clear a coding round without Big-O 7 min left Follow on Google

TamilTech AI summary

Big-O notation describes how an algorithm’s running time or extra memory grows as input size n increases, dropping constants and lesser terms to highlight the dominant factor. It is not a stopwatch measurement of milliseconds but a growth story interviewers use to judge whether code will scale. In Indian SDE hiring, from TCS NQT papers to product-company screens at Flipkart, Amazon, Google India, Zoho and others, candidates who cannot name and derive these complexities routinely fail even when their functions are correct. The four labels that cover most beginner rounds are O(1) constant work (index access or average dict/set lookup), O(n) a single cheap pass, O(log n) repeated halving such as binary search on a sorted list, and O(n²) nested loops over n. A loop is read by asking how many times the inner line executes as n grows; a hidden list-membership test inside a loop turns an apparent O(n) into O(n²). Python specifics matter: list append and end-pop are cheap, insert or pop at index 0 and “in” on a list are linear, while dict and set operations are average O(1). Extra space is billed separately—an auxiliary set of size n buys linear time at linear memory cost. Common errors include quoting best-case instead of worst-case, treating constants as significant, sorting inside a loop, or claiming O(n) for recursive work that is actually quadratic. Interviewers treat the topic as table stakes rather than advanced theory. One focused hour spent annotating existing functions and comparing a nested-loop duplicate check against a set-based version is enough to start answering these questions aloud.

  • Big-O measures growth of time and memory as n grows, not laptop milliseconds
  • Nested loops and membership on a list are the usual O(n²) traps
  • Python dict and set are average O(1); list membership is O(n)

AI-assisted summary, checked by the TamilTech editorial team.

0:00
0:00
🔒 Listen is for subscribers. Subscribe
  • Big-O is about how time and extra memory grow as n grows, not the milliseconds on your laptop.
  • O(1), O(n), O(log n) and O(n²) cover most beginner coding rounds in India.
  • One cheap loop is usually O(n). Nested loops, or in on a list, often mean O(n²).
  • Python dict and set lookups are average O(1). List membership is O(n). append is cheap; insert at 0 is not.
  • You cannot pass a typical SDE coding round without this. One honest hour of loop-reading is enough to start.

What is Big-O notation, in one line?

You are outside an OMR office with filter coffee. Your roommate just walked out of a product-company screen looking wrecked. The function ran. The offer did not. The follow-up was not about syntax. It was time complexity. They froze. Big-O is a short label for how time or extra memory grows when the input size n grows. You drop constants and the small terms. You keep the piece that blows up first.

That is Big-O explained simply. Not a stopwatch. A growth story you can say out loud in a round.

Why do we even measure how code grows?

Forty items on a college laptop will never betray you. Four lakh rows in a Flipkart catalogue or an IRCTC-sized list will. Two functions can both be correct and still be different animals at scale.

Interviewers here are not flexing calculus. They want to know you will not drop an O(n²) scan inside a busy path. Growth is the language you share with whoever owns uptime.

If n doubles and your work barely moves, you are safe. If n doubles and your work squares, the hidden test case times out. Correct is not enough. Correct and scalable is the job.

What do O(1), O(n), O(log n) and O(n²) actually mean?

O(1) means constant work. n can be 10 or a crore. Reading nums[0] does not care. An average dict lookup does not care.

O(n) means linear. Double the list, roughly double the work. One pass. Linear search. Sum of an array. If you see a single for and the body is cheap, say O(n).

O(log n) means each step throws away half the problem. Binary search on a sorted list is the one they expect you to name. The log is base 2 in practice.

O(n²) means nested loops over n. Compare every pair. Fine at n=100. Pain at n=10,000. This is the one that fails the hidden test case.

Do not fight over 2n versus n. Both are O(n). O(n² + n) is O(n²). They want the dominant term.

Here is O(1) sitting next to O(n). Same file. Different growth.

def first_user(users):
    return users[0]


def find_user(users, name):
    for user in users:
        if user == name:
            return True
    return False

first_user does not walk the list. find_user may scan every name. That is O(1) versus O(n) in two functions you can actually run.

Here is O(log n). The list must already be sorted. Empty list returns -1, no drama.

def binary_search(nums, target):
    left, right = 0, len(nums) - 1
    while left <= right:
        mid = (left + right) // 2
        if nums[mid] == target:
            return mid
        if nums[mid] < target:
            left = mid + 1
        else:
            right = mid - 1
    return -1

And here is O(n²). Every id against every other id. Works. Does not scale.

def has_duplicate_nested(ids):
    n = len(ids)
    for i in range(n):
        for j in range(i + 1, n):
            if ids[i] == ids[j]:
                return True
    return False

How do you read a loop and guess the complexity?

Ask one thing. As n grows, how many times does the inner line run?

One loop to n is O(n). Two nested loops to n is O(n²). A while that halves n each time is O(log n). Work that never looks at n is O(1).

The trap is a single for with if x in some_list inside. Membership on a list is O(n), so the function is O(n²). Put those values in a set. You drop to O(n). That swap is a callback moment.

A slice like nums[:] copies n items. Sorting inside a loop is O(n log n) per call. Sort once outside if you can.

Recursion: n calls of cheap work is O(n). n calls of O(n) work is O(n²). Do not say O(n) just because you see one def.

Does memory also have a Big-O?

Yes. Time is one bill. RAM is the other. Extra lists, extra dicts, recursion depth.

A new list the size of the input is O(n) extra space. Two index swaps in place are O(1) extra. They usually ignore the input itself unless they say total space.

Python recursion adds a stack frame per call. A naive walk of n nodes is O(n) space even with no list. Product-company interviewers ask this right after time.

A set of every id you have seen is O(n) extra space. You bought speed with memory. Say the trade out loud.

def has_duplicate_set(ids):
    seen = set()
    for user_id in ids:
        if user_id in seen:
            return True
        seen.add(user_id)
    return False

Same problem as the nested version. Time drops to O(n) average. Extra space becomes O(n). That sentence is the interview.

What do lists, dicts and sets actually cost in Python?

This is CPython, the interpreter you run in interviews. Not a textbook machine.

List: get and set by index are O(1). append is amortized O(1). pop from the end is O(1). Insert or pop at index 0 is O(n), because the rest shifts. x in my_list is O(n). A full copy slice is O(n) time and O(n) space.

Dict and set: add, get, delete, and in are average O(1). Worst case can degrade. In a round, say average O(1) unless they push. Keys must be hashable. A list cannot be a key. A tuple of ids can.

A tuple is a frozen list. Index reads are O(1). No append.

heapq push and pop are O(log n). Use that when they want kth largest without a full sort.

collections.deque: append and pop on both ends are O(1). Need a queue? Do not list.pop(0). That O(n) shift is a favourite trap.

Which mistakes get people into trouble?

They see one for and say O(n), while the body scans a list. Nested work hides in helpers.

They write O(3n) and argue about the 3. Drop the constant.

They call a dict O(1) as a worst-case guarantee. Average is the honest word.

They sort inside a loop and forget sort is O(n log n).

They fix time and allocate a huge extra matrix. Space still counts.

They quote best case. Linear search is O(1) if the item sits first. Rounds want worst case unless they say average.

They mix log n with n. Halving is log. Visiting every element is n. A loop 0, 1, 2, ... n is not log.

Where do Indian interviews actually grill you on this?

TCS NQT-style papers often stay at naming the Big-O of a loop. Zoho, Freshworks, Chargebee, and most Bengaluru product companies will make you derive it on a whiteboard.

Flipkart, Amazon, and Google India SDE screens treat this as table stakes. You cannot pass a coding round without it. A focused hour of loop-reading covers most beginner questions.

Service-company interviews in Chennai, Pune, and Hyderabad still use it as a filter. They will not ask for the master theorem. They will paste a nested loop and wait. Mumble, and they move on.

What should you do now?

Open a notebook. Skip another playlist. Pick three functions you already wrote — a lookup like a UPI app finding a user, a report that nested-loops orders, a binary search you copied. Write the Big-O on top in a comment.

Practice task: you get a list of n user ids, duplicates allowed. Return True if any id appears twice. Write two Python versions, nested loop and a set. State time and extra space for both. Run them in your head for n=10 and n=1,00,000. That hour is the round.

Frequently asked questions

5

Is O(n log n) always better than O(n²)?

For large n, yes. Sorting at O(n log n) beats a nested O(n²) scan once the list leaves toy size. For tiny n, both can feel instant, which is why interviews talk growth, not your laptop clock.

Why does x in list ruin an O(n) answer?

Checking whether a value sits in a Python list walks the list, so that check is O(n). Put it inside a loop over n items and the whole function is O(n²). A set makes the check average O(1).

Do interviewers want best, average, or worst case?

Worst case, unless they say otherwise. Linear search can be O(1) if the item is first, but a round still wants O(n). For dict and set, say average O(1) and mention worst case only if they push.

Should I memorise every data structure cost?

No. Memorise list, dict, set, deque, and heapq. That set covers almost every beginner DSA round in India. If you use something rarer, derive it from loops and hashing the same way.

How do I say Big-O out loud without sounding lost?

Name the dominant term, then one reason. Example: nested loop over n, so O(n²) time and O(1) extra space. Then mention the set trade if they ask how to make it faster.

Get tomorrow’s tech news on WhatsApp

One short update a day, free. Follow the TamilTech channel.

What do you think?

people reacted

Keerthika

TamilTech editorial team · 3,913 articles

Keerthika is an editor at TamilTech, the Tamil and English technology publication founded by Praveen Kumar S. She covers AI, smartphones, gadgets, EVs, startups and cybersecurity i...

More from Keerthika

Ask TamilTech on WhatsApp

Tech doubt? Ask in Tamil or English — our WhatsApp assistant answers from TamilTech articles in seconds.

Related stories

Comments (0)

| Supports **bold**, *italic*, `code`

Be the first to comment!

Next story Five Bash Scripts That Replace Manual Folder Copying — Backups, Renames and Deploys
TamilTech

TamilTech

Install app for faster access

Earn XP 🏆
WhatsApp
Notifications