Module 0
Java for DSA
Just enough Java to write any algorithm in this course: types, arrays, strings, objects, collections and sorting.
This course uses Java for every solution. You don't need to be a Java expert: you need the small part of the language that algorithms use, and you need to know its traps (integer overflow, == on strings, boxed Integer comparisons).
If you already write Java at work, skim the lessons and try the two problems. If you're new, go slowly and run every snippet yourself with java Main.java (Java 11+ runs a single file without compiling first).
Part 1
Learn the ideas
- 0.1Java Basics for Problem SolvingThe shape of a solution class, the number types you'll use, and the overflow and division traps that break correct-looking code.15 min
- 0.2Arrays and Strings in JavaCreating and walking arrays, the helper methods in `Arrays`, 2D arrays, and why strings are compared with `equals` and built with `StringBuilder`.18 min
- 0.3Objects, References and NodesClasses and objects, what a reference really is, `null`, and the `ListNode` and `TreeNode` classes used in linked list and tree problems.15 min
- 0.4The Collections ToolkitArrayList, HashMap, HashSet, ArrayDeque and PriorityQueue: what each is for, the methods you'll use, how fast they are, and the boxing traps.20 min
- 0.5Sorting and ComparatorsHow to sort arrays and lists, sort by your own rules with comparators, and avoid the subtraction-overflow trap.12 min
Part 2
Solve the problems
In order of difficulty. Each one shows the pattern it teaches.
Your first two-pointer algorithm: swap from both ends towards the middle, using O(1) extra space.
Keeping a small running state (the largest and second largest so far) in one pass, and handling duplicates and tiny inputs carefully.