Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
33 changes: 32 additions & 1 deletion readme.md
Original file line number Diff line number Diff line change
@@ -1,7 +1,38 @@
## Algorithms (24/ 167)
## DSA

## 🛠 Prerequisites

Make sure you have the following installed:

Python 3.8+

Node.js 18+ and npm

(Optional) virtualenv for Python

## Running Python solution

```
python3 -m venv venv
source venv/bin/activate
pip install -r requirements.txt

pytest
```

## Running Node solutions

```
npm install

npm test
```

## Algorithms (25/ 168)

| Name | Tags | Solution |
| --------------------------------------------------------- | ----------------------- | ----------------------------------------------------------------------------------------------------------------------------------- |
| Max value | `Arrays` | [Python](./src/algorithms/arrays/max-value/max_value.py) |
| Is-Monotonic | `Arrays` | [TypeScript](./src/algorithms/arrays/is-monotonic/is-monotonic.ts) , [Python](./src/algorithms/arrays/is-monotonic/is_monotonic.py) |
| 2D Array - DS | `Arrays` | [TypeScript](./src/algorithms/arrays/2d-array-ds) |
| Left Rotation | `Arrays` | [TypeScript](./src/algorithms/arrays/left-rotation) |
Expand Down
11 changes: 11 additions & 0 deletions src/algorithms/arrays/max-value/max_value.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,11 @@
def max_value(nums):
if not nums:
raise ValueError("Empty list has no maximum value")

maximum = float('-inf')

for num in nums:
if num > maximum:
maximum = num

return maximum
26 changes: 26 additions & 0 deletions src/algorithms/arrays/max-value/test_max_value.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,26 @@
import pytest
from max_value import max_value


def test_positive_numbers():
assert max_value([3, 1, 7, 2, 5]) == 7

def test_negative_numbers():
assert max_value([-10, -20, -3]) == -3


def test_single_element():
assert max_value([42]) == 42

def test_all_zeros():
assert max_value([0, 0, 0]) == 0

def test_all_same():
assert max_value([5, 5, 5, 5]) == 5

def test_mixed_numbers():
assert max_value([-1, 0, 3, -2]) == 3

def test_empty_list_raises():
with pytest.raises(ValueError, match="Empty list has no maximum value"):
max_value([])