Welcome to the Lockboxes project, part of the ALX Interview Preparation curriculum. In this project, you'll use your algorithmic skills to determine if all boxes in a list can be unlocked. You’ll apply concepts such as list manipulation, graph theory, recursion, and set operations to create an efficient solution.
By completing this project, you will:
- 🔑 Understand List Manipulation: Learn how to access, iterate over, and modify lists dynamically in Python.
- 🌐 Apply Graph Theory Concepts: Explore how boxes and keys can be represented as nodes and edges in a graph, making traversal algorithms useful.
- 🧠 Optimize Algorithm Complexity: Understand how to measure and optimize time and space complexity using Big O notation.
- ♻️ Work with Recursion: Implement recursive solutions to traverse through boxes and keys efficiently.
- 📚 Use Queues and Stacks: Understand when to use data structures such as queues and stacks for breadth-first and depth-first search algorithms.
- ⚡ Utilize Set Operations: Efficiently track visited boxes and available keys using sets.
This project includes the following:
- File: 0-lockboxes.py
- Description: Implement the
canUnlockAll
method, which determines if all boxes can be opened based on the keys found in each box.- Prototype:
def canUnlockAll(boxes)
- Input:
boxes
is a list of lists, where each inner list represents a box containing keys to other boxes. - Output: Return
True
if all boxes can be opened,False
otherwise.
- Prototype:
#!/usr/bin/python3
canUnlockAll = __import__('0-lockboxes').canUnlockAll
boxes = [[1], [2], [3], [4], []]
print(canUnlockAll(boxes)) # True
boxes = [[1, 4, 6], [2], [0, 4, 1], [5, 6, 2], [3], [4, 1], [6]]
print(canUnlockAll(boxes)) # True
boxes = [[1, 4], [2], [0, 4, 1], [3], [], [4, 1], [5, 6]]
print(canUnlockAll(boxes)) # False
- 📘 Python Lists (Python Official Documentation)
- 🎥 Graph Theory Basics (Khan Academy)
- 📚 Big O Notation (GeeksforGeeks)
- 🧠 Recursion in Python (Real Python)
- 📦 Python Queue and Stack (GeeksforGeeks)
- 🔗 Python Sets (Python Official Documentation)
To get started with this project, follow these steps:
-
Install Python:
- Make sure you have Python 3.4.3 or later installed on your system. If not, you can install it using the following command:
sudo apt-get update sudo apt-get install python3
- Make sure you have Python 3.4.3 or later installed on your system. If not, you can install it using the following command:
-
Clone the repository:
- Clone this project to your local machine:
git clone https://github.com/Alogyn/alx-interview.git cd alx-interview/0x01-lockboxes
- Clone this project to your local machine:
-
Make the script executable:
- Ensure that all your Python scripts are executable:
chmod u+x *.py
- Ensure that all your Python scripts are executable:
-
Run the code:
- You can test the code by running:
./main_0.py
- You can test the code by running:
- Your code should be documented.
- Your code must follow the PEP 8 style guidelines (version 1.7.x).
- All your files should be executable.
- All scripts will be interpreted/compiled on Ubuntu 20.04 LTS using Python 3.4.3.
This project is licensed under the terms of the MIT License.
© 2024 ALX. All rights reserved.