Skip to content

Repository files navigation

Grind75-Swift

Swift Tests Grind 75 Swift 5.9+ License: MIT

The complete Grind 75 interview study guide in Swift: every problem includes its pattern, selected data structure, complexity analysis, XCTest coverage, and a LeetCode-ready submission.

Original problem list:

https://leetcode.com/problem-list/rab78cw1/

Each problem includes:

  • A simple, optimal Swift solution
  • Explanation of the algorithm and selected data structure
  • Time and space complexity
  • Edge cases and common mistakes
  • XCTest coverage for every problem (571 passing tests)
  • A LeetCode-ready submission file

How to Use This Repository

Choose the workflow that matches your goal:

  1. Following Grind 75: Work through the progress table in day order. Open the problem guide, solve it without looking at the implementation, and then compare approaches.
  2. Strengthening a weak pattern: Start with the Swift pattern guides, then use the pattern index to select related problems.
  3. Practicing LeetCode submissions: Copy the matching standalone file from LeetCodeSubmissions/; these files are ready for the LeetCode editor.
  4. Studying production Swift: Read the reusable implementation under Sources/, inspect its XCTest coverage under Tests/, and run swift test.

For a paced curriculum, choose the 4-week intensive plan or the 8-week balanced plan.

Study by Pattern

Use this index to drill a weak area instead of working only in day order. Each problem appears once under its primary interview pattern.

Pattern Problems
Hashing and frequency counting 1 Two Sum, 169 Majority Element, 217 Contains Duplicate, 242 Valid Anagram, 383 Ransom Note, 409 Longest Palindrome
Two pointers and array scanning 11 Container With Most Water, 15 3Sum, 42 Trapping Rain Water, 75 Sort Colors, 121 Best Time to Buy and Sell Stock, 125 Valid Palindrome
Linked lists and cache design 21 Merge Two Sorted Lists, 141 Linked List Cycle, 146 LRU Cache, 206 Reverse Linked List, 876 Middle of the Linked List
Sliding window 3 Longest Substring Without Repeating Characters, 76 Minimum Window Substring, 438 Find All Anagrams in a String
Binary search 33 Search in Rotated Sorted Array, 278 First Bad Version, 704 Binary Search, 981 Time Based Key-Value Store
Intervals 56 Merge Intervals, 57 Insert Interval
Stacks and queues 20 Valid Parentheses, 84 Largest Rectangle in Histogram, 150 Evaluate Reverse Polish Notation, 155 Min Stack, 224 Basic Calculator, 232 Implement Queue using Stacks
Trees and binary search trees 98 Validate Binary Search Tree, 102 Binary Tree Level Order Traversal, 104 Maximum Depth of Binary Tree, 105 Construct Binary Tree, 110 Balanced Binary Tree, 199 Binary Tree Right Side View, 226 Invert Binary Tree, 230 Kth Smallest Element in a BST, 235 LCA of a BST, 236 LCA of a Binary Tree, 297 Serialize and Deserialize Binary Tree, 543 Diameter of Binary Tree
Graphs and grid traversal 127 Word Ladder, 133 Clone Graph, 200 Number of Islands, 207 Course Schedule, 310 Minimum Height Trees, 542 01 Matrix, 721 Accounts Merge, 733 Flood Fill, 994 Rotting Oranges
Dynamic programming 53 Maximum Subarray, 62 Unique Paths, 70 Climbing Stairs, 139 Word Break, 322 Coin Change, 416 Partition Equal Subset Sum, 1235 Maximum Profit in Job Scheduling
Backtracking 17 Letter Combinations of a Phone Number, 39 Combination Sum, 46 Permutations, 78 Subsets, 79 Word Search
Heaps and greedy scheduling 23 Merge k Sorted Lists, 295 Find Median from Data Stream, 621 Task Scheduler, 973 K Closest Points to Origin
String parsing and expansion 5 Longest Palindromic Substring, 8 String to Integer, 67 Add Binary
Trie 208 Implement Trie
Matrix traversal 54 Spiral Matrix
Prefix and suffix products 238 Product of Array Except Self

Progress

Day # Problem Difficulty Pattern Data Structure Time Space Status
1 1 Two Sum Easy Hash Map Dictionary O(n) O(n) ✅ Completed
2 20 Valid Parentheses Easy Matching Delimiters Stack O(n) O(n) ✅ Completed
3 21 Merge Two Sorted Lists Easy Two Pointers Singly Linked List O(m + n) O(1) ✅ Completed
4 121 Best Time to Buy and Sell Stock Easy Sliding Minimum Integer State O(n) O(1) ✅ Completed
5 125 Valid Palindrome Easy Two Pointers Filtered Character Array O(n) O(n) ✅ Completed
6 226 Invert Binary Tree Easy Depth-First Search Binary Tree O(n) O(h) ✅ Completed
7 242 Valid Anagram Easy Frequency Counting Dictionary O(n) O(k) ✅ Completed
8 704 Binary Search Easy Binary Search Integer Bounds O(log n) O(1) ✅ Completed
9 733 Flood Fill Easy Breadth-First Search Array-Backed Queue O(m * n) O(m * n) ✅ Completed
10 235 Lowest Common Ancestor of a Binary Search Tree Easy BST Search Binary Search Tree O(h) O(1) ✅ Completed
11 110 Balanced Binary Tree Easy Postorder DFS Binary Tree O(n) O(h) ✅ Completed
12 141 Linked List Cycle Easy Fast and Slow Pointers Singly Linked List O(n) O(1) ✅ Completed
13 232 Implement Queue using Stacks Easy Lazy Stack Transfer Two Array-Backed Stacks Amortized O(1) O(n) ✅ Completed
14 278 First Bad Version Easy Binary Search Integer Bounds O(log n) O(1) ✅ Completed
15 383 Ransom Note Easy Frequency Counting Fixed-Size Integer Array O(m + n) O(1) ✅ Completed
16 70 Climbing Stairs Easy Dynamic Programming Two Integer States O(n) O(1) ✅ Completed
17 409 Longest Palindrome Easy Pair Counting Set O(n) O(k) ✅ Completed
18 206 Reverse Linked List Easy Iterative Pointer Reversal Singly Linked List O(n) O(1) ✅ Completed
19 169 Majority Element Easy Boyer–Moore Majority Vote Two Integer States O(n) O(1) ✅ Completed
20 67 Add Binary Easy Right-to-Left Addition Byte Arrays O(max(m, n)) O(max(m, n)) ✅ Completed
21 543 Diameter of Binary Tree Easy Postorder DFS Binary Tree O(n) O(h) ✅ Completed
22 876 Middle of the Linked List Easy Fast and Slow Pointers Singly Linked List O(n) O(1) ✅ Completed
23 104 Maximum Depth of Binary Tree Easy Depth-First Search Binary Tree O(n) O(h) ✅ Completed
24 217 Contains Duplicate Easy Membership Tracking Set O(n) O(n) ✅ Completed
25 53 Maximum Subarray Medium Kadane's Algorithm Two Integer States O(n) O(1) ✅ Completed
26 57 Insert Interval Medium Three-Phase Linear Scan Interval Array O(n) O(n) ✅ Completed
27 542 01 Matrix Medium Multi-Source Breadth-First Search Array-Backed Queue O(m * n) O(m * n) ✅ Completed
28 973 K Closest Points to Origin Medium Bounded Max-Heap Array-Backed Binary Heap O(n log k) O(k) ✅ Completed
29 3 Longest Substring Without Repeating Characters Medium Sliding Window Character-to-Index Dictionary O(n) O(k) ✅ Completed
30 15 3Sum Medium Sorting and Two Pointers Sorted Integer Array O(n²) O(n) ✅ Completed
31 102 Binary Tree Level Order Traversal Medium Breadth-First Search Array-Backed Queue O(n) O(n) ✅ Completed
32 133 Clone Graph Medium Breadth-First Search Identity-to-Clone Dictionary O(V + E) O(V) ✅ Completed
33 150 Evaluate Reverse Polish Notation Medium Postfix Evaluation Array-Backed Stack O(n) O(n) ✅ Completed
34 207 Course Schedule Medium Topological Sort Adjacency Lists and Indegree Array O(V + E) O(V + E) ✅ Completed
35 208 Implement Trie (Prefix Tree) Medium Prefix Tree Traversal Character-to-Node Dictionaries O(n) per operation O(n) insertion, O(1) search ✅ Completed
36 322 Coin Change Medium Bottom-Up Dynamic Programming Minimum-Count Array O(amount * c) O(amount) ✅ Completed
37 238 Product of Array Except Self Medium Prefix and Suffix Products Output Array and Two Integer States O(n) O(1) auxiliary ✅ Completed
38 155 Min Stack Medium Stack with Running Minimum Array of Value-Minimum Pairs O(1) per operation O(n) ✅ Completed
39 98 Validate Binary Search Tree Medium DFS with Bounds Binary Tree and Recursion Stack O(n) O(h) ✅ Completed
40 200 Number of Islands Medium Iterative Depth-First Search Mutable Grid Copy and Stack O(m * n) O(m * n) ✅ Completed
41 994 Rotting Oranges Medium Multi-Source Breadth-First Search Mutable Grid Copy and Array-Backed Queue O(m * n) O(m * n) ✅ Completed
42 33 Search in Rotated Sorted Array Medium Modified Binary Search Integer Bounds O(log n) O(1) ✅ Completed
43 39 Combination Sum Medium Backtracking Sorted Candidate Array and Recursion Path O(n^(t/m)) O(t/m) auxiliary ✅ Completed
44 46 Permutations Medium Backtracking Used-Index Array and Recursion Path O(n * n!) O(n) auxiliary ✅ Completed
45 56 Merge Intervals Medium Sorting and Linear Merge Sorted Interval Array O(n log n) O(n) ✅ Completed
46 236 Lowest Common Ancestor of a Binary Tree Medium Postorder DFS Binary Tree and Recursion Stack O(n) O(h) ✅ Completed
47 981 Time Based Key-Value Store Medium Binary Search by Timestamp Dictionary of Sorted Entry Arrays O(1) set, O(log n) get O(n) ✅ Completed
48 721 Accounts Merge Medium Union-Find Email Owner Dictionary and Disjoint Set O(e log e) O(n + e) ✅ Completed
49 75 Sort Colors Medium Dutch National Flag Three Array Indices O(n) O(1) ✅ Completed
50 139 Word Break Medium Dynamic Programming with Trie Traversal Trie and Reachability Array O(d + n * l) O(d + n) ✅ Completed
51 416 Partition Equal Subset Sum Medium 0/1 Knapsack Dynamic Programming Boolean Reachability Array O(n * t) O(t) ✅ Completed
52 8 String to Integer (atoi) Medium Bounded Linear Parsing UTF-8 View and Integer State O(n) O(1) ✅ Completed
53 54 Spiral Matrix Medium Shrinking Boundaries Four Integer Bounds O(m * n) O(1) auxiliary ✅ Completed
54 78 Subsets Medium Iterative Subset Expansion Result Array O(n * 2^n) O(n * 2^n) ✅ Completed
55 199 Binary Tree Right Side View Medium Level-Order Traversal Array-Backed Queue O(n) O(n) ✅ Completed
56 5 Longest Palindromic Substring Medium Expand Around Center Character Array O(n²) O(n) ✅ Completed
57 62 Unique Paths Medium Grid Dynamic Programming One-Dimensional Integer Array O(m * n) O(min(m, n)) ✅ Completed
58 105 Construct Binary Tree from Preorder and Inorder Traversal Medium Recursive Traversal Partitioning Index Dictionary and Binary Tree O(n) O(n) ✅ Completed
59 11 Container With Most Water Medium Two Pointers Two Integer Indices O(n) O(1) ✅ Completed
60 17 Letter Combinations of a Phone Number Medium Backtracking Digit Mapping and Character Path O(n * 4^n) O(n) auxiliary ✅ Completed
61 79 Word Search Medium Grid DFS with Backtracking Mutable Board and Recursion Stack O(m * n * 3^l) O(m * n + l) ✅ Completed
62 438 Find All Anagrams in a String Medium Fixed-Size Sliding Window Character-Frequency Dictionary O(n + m) O(n + k) ✅ Completed
63 310 Minimum Height Trees Medium Topological Leaf Trimming Adjacency List and Degree Array O(n) O(n) ✅ Completed
64 621 Task Scheduler Medium Greedy Frequency Counting Task-Frequency Dictionary O(t) O(k) ✅ Completed
65 146 LRU Cache Medium Hash Map and Recency Ordering Dictionary and Doubly Linked List O(1) per operation O(capacity) ✅ Completed
66 230 Kth Smallest Element in a BST Medium Iterative Inorder Traversal Binary Tree and Array-Backed Stack O(h + k) O(h) ✅ Completed
67 76 Minimum Window Substring Hard Variable-Size Sliding Window Character-Frequency Dictionary and Array O(n + m) O(n + k) ✅ Completed
68 297 Serialize and Deserialize Binary Tree Hard Preorder DFS with Null Markers Token Array and Binary Tree O(n) O(n) ✅ Completed
69 42 Trapping Rain Water Hard Two Pointers with Running Maxima Two Integer Indices O(n) O(1) ✅ Completed
70 295 Find Median from Data Stream Hard Two-Heap Balancing Max-Heap and Min-Heap O(log n) add, O(1) median O(n) ✅ Completed
71 127 Word Ladder Hard Breadth-First Search Hash Set and Array-Backed Queue O(n * l * 26) O(n * l) ✅ Completed
72 224 Basic Calculator Hard Expression Parsing Array-Backed Stack O(n) O(d) ✅ Completed
73 1235 Maximum Profit in Job Scheduling Hard Weighted Interval Scheduling Sorted Jobs and DP Array O(n log n) O(n) ✅ Completed
74 23 Merge k Sorted Lists Hard K-Way Merge Min-Heap and Linked Lists O(n log k) O(k) ✅ Completed
75 84 Largest Rectangle in Histogram Hard Monotonic Stack Array-Backed Stack of Indices O(n) O(n) ✅ Completed

Repository Structure

Grind75-Swift/
├── .github/workflows/swift-tests.yml
├── docs/problems/
├── docs/study-plans/
├── docs/swift-patterns/
├── Scripts/audit_documentation.rb
├── Sources/Grind75Swift/Problems/
├── Tests/Grind75SwiftTests/
├── LeetCodeSubmissions/
├── Package.swift
├── README.md
├── CONTRIBUTING.md
├── CHANGELOG.md
└── LICENSE

Contributing

Corrections, clearer explanations, additional edge cases, and Swift improvements are welcome. Read CONTRIBUTING.md before opening an issue or pull request.

Run Tests

ruby Scripts/audit_documentation.rb
swift test

License

This project is available under the MIT License.

About

Grind 75 in Swift — every problem with pattern, data structure, complexity, XCTest coverage, and a LeetCode-ready file.

Topics

Resources

Contributing

Stars

6 stars

Watchers

0 watching

Forks

Releases

Packages

Contributors

Languages