A comprehensive collection of coding interview problems implemented in Zig, covering essential algorithms and data structures commonly encountered in technical interviews.
This repository contains 18 coding challenges organized by problem category, each implemented with clean, well-documented Zig code. The solutions demonstrate various algorithmic approaches, optimization techniques, and Zig-specific features like comptime evaluation.
Each challenge is organized in its own directory with the following structure:
challenge-name/
├── src/
│ └── main.zig # Main implementation
├── build.zig # Build configuration
└── build.zig.zon # Package configuration
- 2 - Container Most Water - Two-pointer technique for maximum area calculation
- 3 - Valid Mountain Array - Array validation with specific patterns
- 4 - Boats to Save People - Greedy algorithm with two pointers
- 5 - Move Zeros - In-place array manipulation
- 6 - Longest Substring - Sliding window technique
- 7 - First and Last Position - Binary search implementation
- 8 - First Bad Version - Binary search optimization
- 9 - Missing Number (Gauss Formula) - Mathematical approach using sum formula
- 10 - Sieve of Eratosthenes - Prime number generation with
comptime - 11 - XOR Single Numbers - Bitwise operations for finding unique elements
- 12 - Robot Return to Origin - Coordinate tracking and validation
- 13 - Binary Sum - Binary arithmetic operations
- 14 - Two Sum - Classic hash map problem with O(n) solution
- 15 - Contains Duplicates - Duplicate detection using hash sets
- 17 - 4Sum II - Advanced hash map usage for multi-array problems
- 18 - Minimum Window Substring (Hard) - Complex sliding window with hash maps
- 16 - Boyer-Moore Majority Element - Voting algorithm implementation
- Zig (version 0.11.0 or later)
Navigate to any challenge directory and run:
# Build and run
zig build run
# Run tests
zig build test
# Build only
zig buildcd "14 - Hash: two sum"
zig build runExpected output:
Positions 1 and 2
- Memory Management: Arena allocators, manual memory management
- Comptime Evaluation: Compile-time computations for performance
- Error Handling: Zig's explicit error handling with
tryand! - Type System: Strong typing with type inference
- Performance: Zero-cost abstractions and manual optimizations
- Hash Maps:
std.hash_map.AutoHashMapusage patterns - Slices vs Arrays: Different approaches to data handling
Each solution includes:
- Time Complexity: Big O notation for runtime performance
- Space Complexity: Memory usage analysis
- Alternative Approaches: Multiple solution strategies where applicable
This collection helps you master:
-
Algorithm Design Patterns
- Two pointers technique
- Sliding window
- Binary search
- Hash table optimization
-
Zig Programming Concepts
- Memory allocators
- Comptime evaluation
- Error handling
- Performance optimization
-
Interview Preparation
- Common problem patterns
- Optimization techniques
- Code organization
- Testing strategies
Feel free to:
- Add new challenges
- Improve existing solutions
- Add alternative implementations
- Enhance documentation
- Report issues or bugs
This project is open source and available under the MIT License.
- Zig Language Reference
- Zig Standard Library
- LeetCode - Source of many challenge problems
- Zig Learning Resources
Happy Coding! 🎉
Each challenge is self-contained and can be studied independently. Start with the category that interests you most or follow the numerical order for a structured learning path.