What is the time complexity of accessing an array index?
Simple meaning
Access by index is O(1) because the address is base plus index times size.
Open the full page for Why, Steps, Example and Key takeaway.
Panel-ready DSA interview set questions for freshers and experienced developers. Practice at Coding Cadre in Faridabad, or Online from Delhi NCR.
Access by index is O(1) because the address is base plus index times size.
Open the full page for Why, Steps, Example and Key takeaway.
I scan once and store seen values in a hash set or map.
Open the full page for Why, Steps, Example and Key takeaway.
I push opening brackets and pop when a matching closer arrives.
Open the full page for Why, Steps, Example and Key takeaway.
BFS uses a queue and explores level by level — good for shortest path in unweighted graphs.
Open the full page for Why, Steps, Example and Key takeaway.
Kadane’s algorithm keeps a running best ending here.
Open the full page for Why, Steps, Example and Key takeaway.
Quicksort is often faster in practice with good pivot choice and better cache behavior, average O(n log n).
Open the full page for Why, Steps, Example and Key takeaway.
Ordering tasks with prerequisites in a DAG.
Open the full page for Why, Steps, Example and Key takeaway.
Big-O upper-bounds how time or space grow as input size grows, ignoring constants.
Open the full page for Why, Steps, Example and Key takeaway.
Overlapping subproblems plus optimal substructure.
Open the full page for Why, Steps, Example and Key takeaway.
DP solves a problem by saving answers to overlapping subproblems so we never recompute them.
Open the full page for Why, Steps, Example and Key takeaway.
O(1) average with a good hash.
Open the full page for Why, Steps, Example and Key takeaway.
Preorder with null markers or level order with queue.
Open the full page for Why, Steps, Example and Key takeaway.
It needs non-negative weights.
Open the full page for Why, Steps, Example and Key takeaway.
Substring is contiguous
Open the full page for Why, Steps, Example and Key takeaway.
Scan tokens, push numbers, pop operands for operators.
Open the full page for Why, Steps, Example and Key takeaway.
Put one array in a hash set and scan the other for hits.
Open the full page for Why, Steps, Example and Key takeaway.
Two pointers from ends moving inward comparing characters.
Open the full page for Why, Steps, Example and Key takeaway.
BFS for shortest path in unweighted graphs and level order.
Open the full page for Why, Steps, Example and Key takeaway.
Overlapping subproblems plus optimal substructure.
Open the full page for Why, Steps, Example and Key takeaway.
Hash map to nodes plus doubly linked list for recency.
Open the full page for Why, Steps, Example and Key takeaway.