Automate Python Virtual Environment Setup on Linux Terminal
Company: Capital One
Role: Data Scientist
Category: Coding & Algorithms
Difficulty: medium
Interview Round: Onsite
Overview: This question evaluates proficiency in shell scripting and Linux terminal automation for Python virtual-environment setup, focusing on environment management, automation, and reproducibility skills relevant to data science workflows.
Constraints
- 1 <= len(commands) <= 100000
- Each command is one of: 'set -e', 'mkdir PATH', 'touch PATH', 'rm PATH', 'chmod +x PATH', 'virtualenv PATH', 'source PATH'
- PATH is relative (no leading '/'), uses '/' as separator, has no '.' or '..', and contains no spaces
- Each PATH length <= 200
- Initial file system contains only the root directory
Hints
- Model the file system with hash maps: path -> type (file/dir) and executable bit for files.
- Implement mkdir with recursive creation; error if a file blocks any directory component.
- Implement rm as recursive deletion; maintain parent->children sets for efficient subtree removal.
- virtualenv PATH should ensure PATH, PATH/bin, and PATH/bin/activate exist; treat conflicts as errors.
- Apply set -e: stop the run on the first error. Idempotent means both runs succeed and final states match (including ACTIVE_VENV).