Coding Interview Questions
Comprehensive coding interview questions covering algorithms, data structures, and problem-solving techniques with Go implementations. Data Structures Detailed explanations and implementations of core data structures: Binary trees and BSTs Heaps and priority queues Tries and advanced trees Linked lists and arrays Hash …
Read MoreA binary tree is a tree data structure where each node has at most two children, referred to as the left child and right child. Structure 1type TreeNode struct { 2 Val int 3 Left *TreeNode 4 Right *TreeNode 5} 6 7// Helper to create a node 8func NewNode(val int) *TreeNode { 9 return &TreeNode{Val: val} 10} …
Read MoreA tree is a hierarchical data structure consisting of nodes connected by edges, with one node designated as the root. Unlike binary trees, general trees allow nodes to have any number of children. Definitions Basic Terminology Root: The topmost node with no parent Parent: A node that has one or more child nodes Child: …
Read MoreA heap is a specialized tree-based data structure that satisfies the heap property. It's commonly used to implement priority queues and for efficient sorting (heapsort). Heap Property Max-Heap Property For every node $i$ other than the root: $$ A[\text{parent}(i)] \geq A[i] $$ The parent's value is greater than or …
Read MoreOptimal techniques for common linked list operations using pointer manipulation, particularly the two-pointer (slow/fast) and three-pointer techniques. Linked List Structure 1type ListNode struct { 2 Val int 3 Next *ListNode 4} 5 6// Helper to create a list from array 7func CreateList(values []int) *ListNode { 8 if …
Read MoreCache replacement policies determine which items to evict when the cache is full. LRU (Least Recently Used) and LFU (Least Frequently Used) are two popular strategies. LRU Cache (Least Recently Used) Evicts the least recently accessed item when cache is full. Operations get(key): Return value if exists, mark as …
Read MoreA Quadtree is a tree data structure where each internal node has exactly four children. Used for spatial partitioning in 2D space, commonly in graphics for Level of Detail (LOD) and collision detection. Structure 1type Point struct { 2 X, Y float64 3} 4 5type Rectangle struct { 6 X, Y, Width, Height float64 7} 8 9func …
Read MoreA Trie (pronounced "try") is a tree-like data structure used to store and retrieve strings efficiently. Each path from root to a node represents a prefix. Structure 1type TrieNode struct { 2 children map[rune]*TrieNode 3 isEnd bool // Marks end of a word 4} 5 6type Trie struct { 7 root *TrieNode 8} 9 10func …
Read More