Complete preparation materials for coding assessment, implemented in Rust for optimal performance and efficiency.
- Duration: 60 minutes
- Questions: 2 coding problems
- Focus: Algorithm efficiency, clean code, time management
- Language: Rust (chosen for performance and safety)
- Algorithm Efficiency (Most Critical): Time/space complexity heavily weighted
- Time Management: Read both questions first, assess difficulty
- Clean Code: Readable, idiomatic Rust solutions
- Pattern Recognition: Know the common problem types
βββ Cargo.toml # Workspace configuration
βββ tools/ # Development utilities
β βββ performance_check.sh # Complete performance validation
β βββ README.md # Tools documentation
βββ exercises/ # Your implementations (Rust crate)
β βββ Cargo.toml # Package configuration
β βββ src/ # Source code (standard Rust structure)
β β βββ lib.rs # Library exports
β β βββ exercise1.rs # CSV Price Analysis (OHLC)
β β βββ exercise2.rs # Financial Command Processor
β β βββ exercise3.rs # Data Structure Transformations
β β βββ exercise4.rs # Iterator Mastery
β β βββ exercise5.rs # State Machine Simulation
β βββ tests/ # Package-specific tests
β βββ exercise1_tests.rs # CSV analysis tests
β βββ exercise2_tests.rs # Financial command tests
β βββ exercise3_tests.rs # Data transformation tests
β βββ exercise4_tests.rs # Iterator tests
β βββ exercise5_tests.rs # Portfolio simulation tests
βββ solutions/ # Reference solutions (Rust crate)
β βββ Cargo.toml # Package configuration
β βββ src/ # Source code
β β βββ lib.rs # Library exports
β β βββ solution_exercise1.rs # OHLC price analysis
β β βββ solution_exercise2.rs # Financial commands
β β βββ solution_exercise3.rs # Data transformations
β β βββ solution_exercise4.rs # Iterator operations
β β βββ solution_exercise5.rs # Portfolio state machine
β βββ tests/ # Empty (reference implementations)
βββ benches/ # Performance benchmarking
β βββ exercise1_benchmark.rs # Exercise 1 benchmarks
β βββ exercise2_benchmark.rs # Exercise 2 benchmarks
β βββ exercise3_benchmark.rs # Exercise 3 benchmarks
β βββ exercise4_benchmark.rs # Exercise 4 benchmarks
β βββ exercise5_benchmark.rs # Exercise 5 benchmarks
β βββ README.md # Benchmarking guide
βββ tests/ # Workspace-level integration tests
β βββ performance_tests.rs # Performance regression tests
βββ test_prep_guide.md # Detailed preparation guide
βββ test_day_guide.md # Test day strategy and checklist
βββ Cargo.toml # Rust project configuration
βββ README.md # This file
-
Build the entire workspace:
cargo build --workspace
-
Run individual exercise tests:
# From workspace root (recommended) cargo test -p exercises --test exercise1_tests # CSV Price Analysis cargo test -p exercises --test exercise2_tests # Financial Commands cargo test -p exercises --test exercise3_tests # Data Transformations cargo test -p exercises --test exercise4_tests # Iterator Mastery cargo test -p exercises --test exercise5_tests # State Simulation # Or from exercises directory cd exercises && cargo test # For specific tests cargo test --test exercise2_tests
-
Run all package tests:
cargo test --workspace # Tests all packages cargo test -p exercises # Tests just exercises package cargo test -p solutions # Tests just solutions package
-
Performance validation (Recommended):
./tools/performance_check.sh # Complete performance validation -
Individual benchmarks:
# Exercise-specific benchmarks cargo bench --bench exercise1_benchmark # CSV Price Analysis cargo bench --bench exercise2_benchmark # Financial Commands cargo bench --bench exercise3_benchmark # Data Transformations cargo bench --bench exercise4_benchmark # Iterator Mastery cargo bench --bench exercise5_benchmark # State Simulation # Run all benchmarks cargo bench --workspace # View HTML benchmark reports open target/criterion/report/index.html
-
Performance regression testing:
cargo test --test performance_tests # Performance regression tests
-
Practice under time pressure:
- Set a 30-40 minute timer per exercise
- Run tests for each exercise:
cargo test -p exercises exercise{N}_tests - Focus on algorithm efficiency and clean code
- Use
./tools/performance_check.shto validate performance
| Task | Command | Description |
|---|---|---|
| Build | cargo build --workspace |
Build all packages |
| Test All | cargo test --workspace |
Run all tests |
| Test Exercise | cargo test -p exercises exercise1_tests |
Test specific exercise |
| Performance | ./tools/performance_check.sh |
Complete validation |
| Benchmarks | cargo bench --bench exercise1_benchmark |
Benchmark specific exercise |
| All Benchmarks | cargo bench --workspace |
Run all benchmarks |
| View Reports | open target/criterion/report/index.html |
HTML benchmark reports |
- CSV parsing and line-by-line processing
- Calculate aggregates (OHLC prices, statistics)
- Sorting and ordering with business logic
- Formatted output with precision
Practice: cargo test -p exercises exercise1_tests
Variant A: State Simulation (Most Common)
- Process commands from CSV
- State management over time
- Multiple conditional branches
- Financial calculations
Variant B: Complex Data Operations
- Heavy string manipulation
- Extensive conditional logic
- Sorting and filtering collections
- HashMap-intensive operations
Practice:
cargo test -p exercises exercise2_tests # Financial commands
cargo test -p exercises exercise4_tests # Iterator operations
cargo test -p exercises exercise5_tests # State simulationlet lines: Vec<&str> = csv_data.trim().split('\n').collect();
let mut data: BTreeMap<String, Vec<f64>> = BTreeMap::new();
for line in &lines[1..] { // Skip header
let fields: Vec<&str> = line.split(',').collect();
if let (Ok(key), Ok(value)) = (fields[0].parse::<String>(), fields[1].parse::<f64>()) {
data.entry(key).or_insert(Vec::new()).push(value);
}
}#[derive(Debug)]
struct State {
balance: f64,
rate: f64,
// ... other fields
}
impl State {
fn process_command(&mut self, command: &str) -> Result<(), String> {
// Command processing logic
Ok(())
}
}HashMap: O(1) lookups for state trackingBTreeMap: Sorted iteration when neededVec: Dynamic arrays for data collectionVecDeque: When you need queue operations
- Reading Phase (5 min): Read both questions completely
- Planning Phase (5 min): Check test cases, assess difficulty
- Implementation Phase: Q1 (20-25 min) + Q2 (30-35 min)
- Review Phase (5-10 min): Test and submit
Key Decision: Identify which question is harder and consider tackling it first to ensure completion.
- Algorithm Efficiency: Brute force solutions pass tests but score poorly
- Test Cases: Check them FIRST to understand requirements
- Over-engineering: Simple efficient solution > complex incomplete code
- Submission: Click BOTH "Submit test" AND "Finish test"
- Time Pressure: Questions are longer than expected - pace yourself
- Master the Exercises: Complete all 5 exercises with comprehensive tests
- Time Pressure Practice: Set 30-40 minute timers per exercise, run tests to verify
- Algorithm Focus: For each problem, think "What's the optimal approach?"
- Code Quality: Write clean, readable Rust code under pressure
- Edge Cases: All exercises include comprehensive edge case testing
- Performance Validation: Use
./tools/performance_check.shfor complete validation - Benchmark Analysis: Run individual benchmarks to understand performance characteristics
- Compare Implementations: Use benchmarks to compare your code vs solutions
- Review Solutions: Compare with solutions package for different approaches
Exercise 1 (CSV Price Analysis): Your implementation should be competitive (~2-4 Β΅s/iter)
Exercise 3 (Data Transformations): Solutions are typically 10-20x faster due to optimized data structures
# π§ Complete performance validation (Recommended)
./tools/performance_check.sh
# π Individual exercise benchmarks
cargo bench --bench exercise1_benchmark # CSV Price Analysis
cargo bench --bench exercise2_benchmark # Financial Commands
cargo bench --bench exercise3_benchmark # Data Transformations
cargo bench --bench exercise4_benchmark # Iterator Mastery
cargo bench --bench exercise5_benchmark # State Simulation
# π Run all benchmarks in workspace
cargo bench --workspace
# π Run specific benchmark groups
cargo bench --bench exercise1_benchmark -- exercise1_small # Small dataset only
cargo bench --bench exercise1_benchmark -- exercise1_large # Large dataset only
# π List all available benchmarks
cargo bench -- --list
# π View detailed HTML reports
open target/criterion/report/index.html
# π Compare specific implementations
# Results show: your_implementation vs solution columnsUnderstanding the Output:
exercise1_small/your_implementation
time: [2.6494 Β΅s 2.6841 Β΅s 2.7249 Β΅s]
β² β² β²
Lower Mean Upper
- Lower bound: Best case performance (noise floor)
- Mean: Average performance (most useful)
- Upper bound: Worst case (outliers)
RΒ² > 0.9: Reliable measurements (good statistical confidence)
Performance Goals:
- β Exercise 1: Competitive with solutions (~2-4 Β΅s/iter)
- β Exercise 3: Solutions typically 10-20x faster (optimized data structures)
- β Memory Safety: Zero-cost abstractions with Rust's guarantees
- β Scalability: Performance degrades gracefully with larger datasets
Common Optimizations:
- Use integer arithmetic instead of floating point where possible
- Minimize memory allocations
- Choose appropriate data structures (HashMap vs BTreeMap vs Vec)
- Avoid unnecessary string operations
"No benchmarks found":
# Make sure you're using the correct bench name
cargo bench --bench exercise1_benchmark
# List all available benchmarks
cargo bench -- --list"Criterion not found" error:
# Install plotters backend for Criterion
sudo apt-get install libfontconfig-dev # Linux
# or
brew install fontconfig # macOSInconsistent results:
- Benchmarks run in release mode - ensure
cargo build --releaseworks - Close other applications for consistent measurements
- Run benchmarks multiple times for statistical confidence
Comparing with solutions:
- Your Exercise 1 implementation should be competitive or faster
- Exercise 3 solutions are typically much faster due to algorithmic optimizations
- Focus on understanding WHY solutions are faster, not just matching the numbers
This project uses a Cargo workspace with two main packages:
exercises: Your implementations (what you submit for assessments)solutions: Reference implementations for comparison and learning
tools/performance_check.sh: Complete performance validation script- Individual benchmarks: Compare your code vs solutions
- Performance regression tests: Catch slowdowns automatically
- Comprehensive test suites: Edge cases and correctness verification
# Full workspace build
cargo build --workspace
# Test everything
cargo test --workspace
# Performance validation
./tools/performance_check.sh
# Individual package development
cargo test -p exercises # Test your implementations
cargo test -p solutions # Test reference solutionsBoth packages follow standard Rust crate conventions and can be published to crates.io if desired.
- Rust Advantages: Zero-cost abstractions, memory safety, performance
- Efficiency Focus: HashMap lookups, efficient sorting, optimal algorithms
- Pattern Recognition: Q1 is usually CSV processing, Q2 is state simulation or complex data ops
- Performance Mindset: Always think about algorithmic complexity first
- Development Workflow: Use the performance check script regularly during development
- Mental Prep: Stay calm, read carefully, check test cases first
Remember: The problems aren't extremely hard - doing them efficiently with clean code is what wins. You've got the tools and practice - focus on algorithm efficiency and you'll succeed!
Pro Tip: Run ./tools/performance_check.sh before submitting any implementation to ensure optimal performance!
Good luck! π