
Given an array of integers nums and an integer target, return the indices of the two numbers that add up to target. You may assume that each input would have exactly one solution, and you may not use the same element twice. Return the answer in any order.
from typing import List# Complete the function belowdef two_sum(nums: List[int], target: int) -> List[int]:# Your solution herepass
DSA Adaptive MCQ — Arrays & Hashing👍 Good Effort
DSA Adaptive MCQ — Arrays & Hashing · 5 Questions
What is the time complexity of accessing an element in an array by its index?
Arrays store elements in contiguous memory locations. Accessing an element by index requires a single memory address calculation: base_address + (index × element_size), which is performed in constant time regardless of the array size.
Which data structure uses the LIFO (Last In, First Out) principle?
A Stack follows the Last In, First Out (LIFO) principle — the last element pushed onto the stack is the first one to be popped off. Common use cases include function call stacks, undo/redo operations, and expression evaluation. A Queue, in contrast, uses FIFO (First In, First Out).
What is the worst-case time complexity of QuickSort?
QuickSort's worst-case time complexity is O(n²), which occurs when the pivot selection consistently results in unbalanced partitions — for example, always picking the smallest or largest element as pivot on an already-sorted array. Average case is O(n log n). Randomized pivot selection or the median-of-three strategy significantly reduces worst-case probability.
In a Hash Map, what happens when two keys produce the same hash value?
When two different keys produce the same hash value, a collision occurs. Hash maps handle this via: (1) Chaining — each bucket holds a linked list of entries; (2) Open Addressing — the algorithm probes for the next available slot using linear probing, quadratic probing, or double hashing. Java's HashMap uses chaining with tree-ification (red-black trees) for buckets exceeding 8 entries.
Which traversal of a Binary Search Tree (BST) produces elements in sorted ascending order?
In-order traversal of a BST visits nodes in the sequence: Left subtree → Root → Right subtree. Since a BST maintains the invariant that all left descendants are smaller and all right descendants are larger than the root, in-order traversal always yields elements in ascending sorted order. This property is often used for BST validation and sorting algorithms.
No comments yet. Be the first!