DSA in Go (Golang): coding interview problems, solved
How to read judge input fast, then fifteen problems campus hiring tests and online assessments ask most (maps, slices, linked lists, trees, recursion, DP, graphs, sliding windows), each solved idiomatically in Go with the trap that costs marks.
- 01Fast input and output for online judgesHow to read the input HackerRank, CodeChef and company OAs send on stdin, and print the answer fast enough to pass the time limit.Graded challenge
- 02Two sum with a mapThe most-asked warm-up in any coding round, and the cleanest demonstration of why a map beats a nested loop.Graded challenge
- 03Reverse and rotate a slice in placeTwo pointers, the three-reversal trick, and the slice aliasing that makes "in place" mean what it says.Graded challenge
- 04Frequency count and top KCount with a map, rank with a sort or a heap, and never let map order leak into your answer.Graded challenge
- 05Valid parentheses with a slice as a stackGo has no stack type, because a slice already is one. Push with append, pop by re-slicing.Graded challenge
- 06Binary search, by hand and from the stdlibWrite it once without an off-by-one, then know when `slices.BinarySearch` and `sort.Search` do it for you.Graded challenge
- 07LRU cache with container/list and a mapThe design question disguised as a coding question: two structures, each covering what the other cannot.Graded challenge
- 08Reverse a linked listThree pointers and one saved link. The question that checks you can move pointers without losing the rest of the list.Graded challenge
- 09Detect a cycle with two pointersFloyd's tortoise and hare: find a loop in a linked list with no extra memory.Graded challenge
- 10Merge two sorted listsA dummy head node removes every special case, and the leftover tail is attached in one line.Graded challenge
- 11Binary tree depth and level orderRecursion for depth, a slice as a queue for level order. The two shapes every tree question uses.Graded challenge
- 12Subsets and permutations with backtrackingChoose, recurse, undo. And the one-line copy that stops every answer turning into the same slice.Graded challenge
- 13Dynamic programming: stairs, coins, LCSWrite the answer for a small case in terms of smaller ones, then fill a table from the bottom up.Graded challenge
- 14Number of islands: DFS on a gridA grid is a graph in disguise. Find unvisited land, flood it, count one.Graded challenge
- 15Merge overlapping intervalsSort by start, then one pass. The sort does the hard part.Graded challenge
- 16Longest substring without repeating charactersA window with two edges and a map of where each character was last seen. Rune-aware, so it counts characters, not bytes.Graded challenge