VivaPrep
← All modules

DSA Refresher

Arrays, strings, linked lists, trees, complexity — the "small code" viva slice.

Start here

Not a full coding-interview grind — making sure that if the panel hands you a pen and asks for ten lines of code, you don't freeze. Two ideas do most of the work.

  • "Efficient" = — shorthand for "how much slower does this get as input grows." O(n) doubles when input doubles; O(n²) quadruples. Recognize the shape: one loop ≈ O(n), nested loop ≈ O(n²), halving each step () ≈ O(log n).
  • The toolbox — arrays/strings (, sliding-window), linked lists (nodes chained to the next), stacks/queues, trees (branching hierarchy), hash maps (instant lookup by key).

Almost every "small code" question is one of these building blocks in disguise — recognizing which one applies is 80% of the battle.

Why this is here

The HR call flagged "small code possible" — not a full LeetCode grind, but enough DSA fluency to write 10-15 lines cleanly on a whiteboard or paper without an IDE.

Core threads

  • Complexity: know for common ops (array access O(1), search O(n), sorted-array O(log n), hash lookup O(1) avg). Always state time *and* space complexity after solving.
  • Arrays/strings: and sliding-window patterns solve most "small code" prompts fast (reverse a string in place, check palindrome, find a pair summing to target).
  • Linked lists: reversing in place (three-pointer walk: prev/curr/next), detecting a cycle (Floyd's fast-slow pointer).
  • Trees: recursive traversal (pre/in/post-order), via queue for level-order — know when to "return up" a value vs "pass down" a value through recursion.
  • Hashing: the go-to for O(1) lookups/dedup/frequency counting — most interview "small code" problems reduce to a trick.

Viva angle

Practice writing these on paper, no IDE, no autocomplete — that's the actual test condition. Speed and clean syntax matter less than correct logic explained while writing.

Visual reference

Big-O growth rates

O(1)log nO(n)O(n²)
How runtime grows as input size n increases. O(1) and O(log n) barely grow; O(n²) explodes — that gap is why complexity matters at scale.

Two-pointer technique

274193L →← R
One pointer starts at each end and they move toward each other, checking a condition each step — most single-pass array problems reduce to this.

Cheatsheet

Big-O growth (best to worst)

NotationNameExample
O(1)ConstantArray index access, hash lookup
O(log n)LogarithmicBinary search
O(n)LinearSingle loop / scan
O(n log n)LinearithmicGood sorting (merge/quick sort)
O(n²)QuadraticNested loop / naive pair check

Which structure for which job

NeedUse
Instant lookup / dedup / countingHash map
Sorted-input searchBinary search
Best contiguous subarray/substringSliding window
Pair/triplet in sorted arrayTwo pointer
Shortest path, unweightedBFS
Explore all paths / backtrackingDFS
  • Always state time AND space complexity after solving.
  • Reverse a linked list: three pointers — prev, curr, next.
  • Cycle detection: Floyd's fast-slow pointer.
  • Merge two sorted arrays: two pointers, always copy the smaller — the heart of merge sort.

Further study

Question bank

17 questions
#1Easycomplexity

What is and what does it measure?

#2Easyarrayscoding

Write (or describe step by step) how you'd check if a string is a palindrome without extra space.

#3Mediumlinked-listcoding

Describe how to reverse a singly linked list in place.

#4Mediumlinked-list

How do you detect a cycle in a linked list without extra memory?

#5Easystackcoding

How would you check if a string of brackets ( { [ is validly matched and nested?

#6Mediumtrees

What is the difference between and traversal of a tree, and when would you use each?

#7Easyhashing

How does a achieve O(1) average lookup, and when does it degrade?

#8Easycoding

Given an array, describe an O(n) approach to find two numbers that sum to a target (Two Sum).

#9Easysortingbinary-search

Why does require a sorted array, and what is its time complexity?

#10Easycomplexity

After solving a coding problem, why is it important to always state both time and space complexity?

#11Mediumsorting

Compare merge sort and quicksort — how each works at a high level, and when would you prefer one over the other?

#12Mediumdynamic-programming

What is dynamic programming, and how does it apply to a problem like climbing stairs or computing Fibonacci numbers?

#13Easygraphs

Compare adjacency list and adjacency matrix as ways to represent a graph — what are the space and lookup tradeoffs?

#14Mediumheap

What operations does a heap (priority queue) support efficiently, and what's a classic use case?

#15Easyrecursion

What are the tradeoffs between solving a problem recursively vs iteratively?

#16Easysortingcomplexity

Quickly compare the time complexity of bubble sort, merge sort, quicksort, and heap sort — best, average, and worst case.

#17Easyarrayscodingtwo-pointer

Describe how to merge two already-sorted arrays into one sorted array in O(n + m).