Version 1.0

This commit is contained in:
Alexander R.
2026-07-21 22:24:25 +00:00
parent f3645fbfbc
commit 9edbfd3f77
4134 changed files with 1448752 additions and 1 deletions
+19
View File
@@ -0,0 +1,19 @@
# Challenge: Hello World
**Difficulty:** Easy
**Language:** Python
**Subject:** Basic I/O
## Description
Write a Python script that prints the phrase "Hello, World!" to the console.
## Requirements
- The script must output exactly "Hello, World!".
- The script should be named `hello.py`.
## Hints
- Use the `print()` function in Python.
- Ensure there are no extra spaces or characters in the string.
## Validation
- **Check:** `python3 -c "import hello; print(hello.main())"`
- **Expected Output:** Hello, World!
+20
View File
@@ -0,0 +1,20 @@
# Challenge: Variables and Assignment
**Difficulty:** Easy
**Language:** Python
**Subject:** Variables & Types
## Description
Create a variable named `score` and assign it the value 100. Then, print the message "The score is 100" to the console.
## Requirements
- Create a variable named `score`.
- Assign the integer value 100 to it.
- Print "The score is 100".
## Hints
- Use `score = 100` to create the variable.
- Use `print("The score is 100")` to output the text.
## Validation
- **Check:** `python3 -c "import main; print(main.score)"`
- **Expected Output:** 100
+24
View File
@@ -0,0 +1,24 @@
# Challenge: For Loops
**Difficulty:** Easy
**Language:** Python
**Subject:** Control Flow (Loops)
## Description
Write a loop that prints the numbers from 1 to 5 (inclusive).
## Requirements
- Use a `for` loop.
- Print each number on a new line.
## Hints
- The `range(1, 6)` function generates numbers from 1 to 5.
- Use `print()` inside the loop body.
## Validation
- **Check:** `python3 -c "import main; [print(i) for i in range(1, 6)]"`
- **Expected Output:**
1
2
3
4
5
+20
View File
@@ -0,0 +1,20 @@
# Challenge: Conditionals
**Difficulty:** Easy
**Language:** Python
**Subject:** Control Flow (Conditionals)
## Description
Write a program that checks if a number is positive, negative, or zero.
## Requirements
- Create a variable `num` and assign it a value (e.g., -5).
- Use `if`, `elif`, and `else` to check the value.
- Print "Positive", "Negative", or "Zero" based on the value.
## Hints
- Use `num > 0`, `num < 0`, and `num == 0` for the conditions.
- Remember to use indentation for the code inside the blocks.
## Validation
- **Check:** `python3 -c "import main; print(main.check_num(-5))"`
- **Expected Output:** Negative
+20
View File
@@ -0,0 +1,20 @@
# Challenge: Functions
**Difficulty:** Easy
**Language:** Python
**Subject:** Modular Programming (Functions)
## Description
Write a function named `add_numbers` that takes two parameters, `a` and `b`, and returns their sum.
## Requirements
- Define the function `add_numbers(a, b)`.
- Use the `return` keyword.
- Call the function and print the result of adding 5 and 10.
## Hints
- `def add_numbers(a, b):` is the standard way to define a function.
- Use `print(add_numbers(5, 10))` to see the result.
## Validation
- **Check:** `python3 -c "import main; print(main.add_numbers(5, 10))"`
- **Expected Output:** 15
+20
View File
@@ -0,0 +1,20 @@
# Challenge: List Basics
**Difficulty:** Easy
**Language:** Python
**Subject:** Data Structures (Lists)
## Description
Create a list of 3 fruits. Add a 4th fruit to the list and then print the final list.
## Requirements
- Create a list named `fruits`.
- Use `.append()` to add another item.
- Print the final list.
## Hints
- `fruits = ["apple", "banana", "cherry"]`
- `fruits.append("date")`
## Validation
- **Check:** `python3 -c "import main; print(main.fruits)"`
- **Expected Output:** ['apple', 'banana', 'cherry', 'date']
@@ -0,0 +1,44 @@
# Challenge: LRU Cache Implementation
**Difficulty:** Medium
**Language:** Java
**Subject:** Data Structures
## Description
In high-performance software engineering, caching is a critical technique used to reduce data retrieval time by storing frequently accessed information in fast-access memory. One of the most common eviction policies is **LRU (Least Recently Used)**. This policy discards the least recently accessed items first when the cache reaches its capacity.
Your task is to design and implement a data structure for an LRU Cache. The cache must support two primary operations: `get` and `put`.
- `get(key)`: Retrieve the value associated with the key. If the key exists, it should be marked as "recently used." If it doesn't exist, return -1.
- `put(key, value)`: Insert or update the value for a given key. If the key already exists, update its value and mark it as "recently used." If the key is new and the cache is at full capacity, you must remove the least recently used item before inserting the new one.
The primary constraint is that both `get` and `put` operations must run in **O(1)** average time complexity.
## Requirements
- Implement a class `LRUCache` that takes an integer `capacity` as a constructor argument.
- Implement the `get(int key)` method:
- Return the value if the key exists; otherwise, return -1.
- Moving a key to the "most recently used" position must happen automatically upon access.
- Implement the `put(int key, int value)` method:
- If the key exists, update the value and move it to the "most recently used" position.
- If the key is new, add it to the cache.
- If the cache exceeds `capacity`, remove the entry that was accessed least recently.
- **Performance Constraint:** You must achieve $O(1)$ time complexity for both operations. (Hint: Using only a HashMap or only a Linked List will not satisfy the time complexity requirements for both operations simultaneously).
## Hints
- To achieve $O(1)$ lookup, a `HashMap` is essential. However, a standard `HashMap` does not maintain the order of access.
- To achieve $O(1)$ removal and insertion at specific positions, a **Doubly Linked List** is the ideal companion to the HashMap.
- The HashMap should store the key as the map key and the corresponding Node object (from your Doubly Linked List) as the map value. This allows you to jump directly to the node in the list to re-link it in constant time.
## Validation
- **Check:** Initialize `LRUCache cache = new LRUCache(2)`.
- **Sequence:**
1. `cache.put(1, 1)`
2. `cache.put(2, 2)`
3. `cache.get(1)` (Should return 1, and 1 becomes most recent)
4. `cache.put(3, 3)` (Capacity is 2, so the least recently used key '2' should be evicted)
5. `cache.get(2)` (Should return -1)
6. `cache.get(3)` (Should return 3)
7. `cache.put(4, 4)` (Capacity is 2, so the least recently used key '1' should be evicted)
8. `cache.get(1)` (Should return -1)
9. `cache.get(3)` (Should return 3)
10. `cache.get(4)` (Should return 4)
- **Expected Output:** `[1, -1, 3, -1, 3, 4]`