A growing collection of Data Structures & LeetCode-style DSA solutions implemented in Swift ๐
Welcome to my DSA in Swift repository!
This repo is my personal journey (and a helpful reference for others) to master Data Structures and Algorithms โ all implemented in Swift ๐ป
Here, youโll find clean, well-documented solutions to popular problems from LeetCode โ neatly organized by data structure and algorithm type.
This repository documents my journey to master Data Structures & Algorithms using Swift, by solving real interview-standard problems and organizing them by topic.
Perfect for:
- โ iOS Engineers prepping for interviews
- โ Swift learners who want DSA fundamentals
- โ Anyone who wants clean, readable Swift solutions
- ๐ Strengthen understanding of core data structures and algorithms
- ๐งฉ Solve LeetCode problems in Swift
- ๐๏ธ Organize them by category for easy navigation
- ๐ง Write clean, readable, and efficient Swift code
- ๐ฌ Optionally include explanations & time complexities
Each directory represents a Data Structure or Algorithm Category.
Within each folder, youโll find problems with their Swift implementations and clear explanations (where applicable).
| ๐ฆ Folder | ๐งฉ Description |
|---|---|
| ๐งฎ Arrays | Problems involving arrays, searching, sorting, and manipulation |
| ๐ LinkedList | Linked list operations โ reversing, merging, detecting cycles |
| ๐งฑ Stack | Stack-based problems (e.g. parentheses, next greater element) |
| ๐ Queue | FIFO structures, sliding window, and scheduling problems |
| ๐ Hashing | HashMap / Dictionary based problems |
| ๐ณ Trees | Binary Trees, BSTs, traversals, depth/height problems |
| ๐ Graphs | BFS, DFS, pathfinding, connected components |
| ๐ง DynamicProgramming | Classic DP problems like LIS, LCS, Knapsack |
Each folder includes:
- โ Swift solution
- ๐ง Approach / Explanation (when helpful)
- โฑ Time & space complexity
- ๐ Link to original problem
- Swift 5+
- Xcode Playground / Swift files
- LeetCode problem references
Each problem typically includes:
- Problem name
- Link to the original problem
- Approach / Explanation
- Time & Space Complexity
- Swift Solution
// ๐ Problem: https://leetcode.com/problems/two-sum/
// ๐ง Approach: HashMap to store visited numbers and their indices
// โฐ Time: O(n)
// ๐พ Space: O(n)
func twoSum(_ nums: [Int], _ target: Int) -> [Int] {
var map = [Int: Int]()
for (i, num) in nums.enumerated() {
if let j = map[target - num] {
return [j, i]
}
map[num] = i
}
return []
}