Java katas
Finger + verbal memory for the basics. Read the prompt, type the idiom from memory while saying what each line does, then check. Do a few every day so the fundamentals stop wobbling.
- Count frequencies into a MapMapCount how many times each word appears in a List<String>, into a Map<String,Integer>.
- Detect duplicates with a SetSetIterate a list and detect duplicates using a Set.
- ArrayDeque as stack and queueDequeUse an ArrayDeque as both a stack (LIFO) and a queue (FIFO).
- Min-heap and max-heapHeapCreate a min-heap and a max-heap of integers.
- Sort by field, then tie-breakComparatorSort a List<Person> by age ascending, then by name.
- Define an enumenumDefine an offer-status enum.
- Define and use a recordrecordDefine an immutable Point record and read a field.
- Avoid null with OptionalOptionalRead a possibly-null user's name, defaulting to "anonymous".
- Validate argument and stateexceptionsReject a bad argument and an illegal state with the right exceptions.
- Stream: filter → map → collectstreamFrom a List<Integer>, keep positives, double them, collect to a List.
- main() with a manual checktestingWrite a main() that verifies add(2,3)==5 without a test framework.
- Two-pointer pair sumtwo-pointerDoes a SORTED array have a pair summing to target? (two pointers)
- Sliding window (longest ≤ k)sliding-windowLongest subarray with sum ≤ k (non-negative values).
- Binary searchbinary-searchFind target's index in a sorted array, or -1.
- BFS with a visited setBFSBFS over an adjacency Map<Integer,List<Integer>> from start.
- Top-K frequent (count + heap)heapReturn the k most frequent elements of an int[] (LC 347).
- Insert/Delete/GetRandom O(1)array+mapA set with insert, remove, and getRandom all O(1) (LC 380).
- Merge overlapping intervalsintervalsMerge overlapping intervals in an int[][].