From 8aaf81bc657ad48495b490cc00d2cb4a5821263e Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Th=C3=A9o=20LUDWIG?= Date: Sat, 16 Sep 2023 15:50:35 +0200 Subject: [PATCH] feat(challenges): add `frequency-deviation` --- challenges/frequency-deviation/README.md | 67 +++++++++++++++++++ .../frequency-deviation/solutions/.gitkeep | 0 .../frequency-deviation/test/1/input.txt | 1 + .../frequency-deviation/test/1/output.txt | 1 + .../frequency-deviation/test/2/input.txt | 1 + .../frequency-deviation/test/2/output.txt | 1 + .../frequency-deviation/test/3/input.txt | 1 + .../frequency-deviation/test/3/output.txt | 1 + .../frequency-deviation/test/4/input.txt | 1 + .../frequency-deviation/test/4/output.txt | 1 + .../frequency-deviation/test/5/input.txt | 1 + .../frequency-deviation/test/5/output.txt | 1 + .../frequency-deviation/test/6/input.txt | 1 + .../frequency-deviation/test/6/output.txt | 1 + 14 files changed, 79 insertions(+) create mode 100644 challenges/frequency-deviation/README.md create mode 100644 challenges/frequency-deviation/solutions/.gitkeep create mode 100644 challenges/frequency-deviation/test/1/input.txt create mode 100644 challenges/frequency-deviation/test/1/output.txt create mode 100644 challenges/frequency-deviation/test/2/input.txt create mode 100644 challenges/frequency-deviation/test/2/output.txt create mode 100644 challenges/frequency-deviation/test/3/input.txt create mode 100644 challenges/frequency-deviation/test/3/output.txt create mode 100644 challenges/frequency-deviation/test/4/input.txt create mode 100644 challenges/frequency-deviation/test/4/output.txt create mode 100644 challenges/frequency-deviation/test/5/input.txt create mode 100644 challenges/frequency-deviation/test/5/output.txt create mode 100644 challenges/frequency-deviation/test/6/input.txt create mode 100644 challenges/frequency-deviation/test/6/output.txt diff --git a/challenges/frequency-deviation/README.md b/challenges/frequency-deviation/README.md new file mode 100644 index 0000000..e027ca0 --- /dev/null +++ b/challenges/frequency-deviation/README.md @@ -0,0 +1,67 @@ +# frequency-deviation + +Created by [@theoludwig](https://github.com/theoludwig) on 16 September 2023. + +## Instructions + +Given a string consisting of lowercase English letters, we define the frequency deviation of a substring as the difference between the maximum and the minimum frequencies of the characters in that substring. + +A substring of a string is formed by any contiguous segment of the string. For example, given "bbacccc", the character appearing most frequently is 'c' with $4$ occurrences. The character that appears the fewest times is 'a' with $1$ occurrence. The frequency deviation of the entire string is $4 - 1 = 3$. + +Given a string, $s$, representing the input string, find the maximum possible frequency deviation of any of its substrings. + +### Constraints + +- $$1 \leq s.length \leq 10^4$$ +- $s$ consists of lowercase English letters. + +## Source + +- [LeetCode - Substring With Largest Variance](https://leetcode.com/problems/substring-with-largest-variance/) +- [Twitter @CoderNolimit](https://twitter.com/CoderNolimit/status/1668147202173050881) + +## Examples + +See the `test` folder for examples of input/output. + +### Example 1 + +#### Input + +```txt +bbacccc +``` + +#### Output + +```txt +3 +``` + +### Example 2 + +#### Input + +```txt +aabb +``` + +#### Output + +```txt +1 +``` + +### Example 3 + +#### Input + +```txt +aaaaa +``` + +#### Output + +```txt +0 +``` diff --git a/challenges/frequency-deviation/solutions/.gitkeep b/challenges/frequency-deviation/solutions/.gitkeep new file mode 100644 index 0000000..e69de29 diff --git a/challenges/frequency-deviation/test/1/input.txt b/challenges/frequency-deviation/test/1/input.txt new file mode 100644 index 0000000..3577a9a --- /dev/null +++ b/challenges/frequency-deviation/test/1/input.txt @@ -0,0 +1 @@ +bbacccc \ No newline at end of file diff --git a/challenges/frequency-deviation/test/1/output.txt b/challenges/frequency-deviation/test/1/output.txt new file mode 100644 index 0000000..e440e5c --- /dev/null +++ b/challenges/frequency-deviation/test/1/output.txt @@ -0,0 +1 @@ +3 \ No newline at end of file diff --git a/challenges/frequency-deviation/test/2/input.txt b/challenges/frequency-deviation/test/2/input.txt new file mode 100644 index 0000000..7702ecf --- /dev/null +++ b/challenges/frequency-deviation/test/2/input.txt @@ -0,0 +1 @@ +aabb \ No newline at end of file diff --git a/challenges/frequency-deviation/test/2/output.txt b/challenges/frequency-deviation/test/2/output.txt new file mode 100644 index 0000000..56a6051 --- /dev/null +++ b/challenges/frequency-deviation/test/2/output.txt @@ -0,0 +1 @@ +1 \ No newline at end of file diff --git a/challenges/frequency-deviation/test/3/input.txt b/challenges/frequency-deviation/test/3/input.txt new file mode 100644 index 0000000..e4a7dd9 --- /dev/null +++ b/challenges/frequency-deviation/test/3/input.txt @@ -0,0 +1 @@ +aaaaa \ No newline at end of file diff --git a/challenges/frequency-deviation/test/3/output.txt b/challenges/frequency-deviation/test/3/output.txt new file mode 100644 index 0000000..c227083 --- /dev/null +++ b/challenges/frequency-deviation/test/3/output.txt @@ -0,0 +1 @@ +0 \ No newline at end of file diff --git a/challenges/frequency-deviation/test/4/input.txt b/challenges/frequency-deviation/test/4/input.txt new file mode 100644 index 0000000..af8fdec --- /dev/null +++ b/challenges/frequency-deviation/test/4/input.txt @@ -0,0 +1 @@ +bbacccabab \ No newline at end of file diff --git a/challenges/frequency-deviation/test/4/output.txt b/challenges/frequency-deviation/test/4/output.txt new file mode 100644 index 0000000..d8263ee --- /dev/null +++ b/challenges/frequency-deviation/test/4/output.txt @@ -0,0 +1 @@ +2 \ No newline at end of file diff --git a/challenges/frequency-deviation/test/5/input.txt b/challenges/frequency-deviation/test/5/input.txt new file mode 100644 index 0000000..d04ca97 --- /dev/null +++ b/challenges/frequency-deviation/test/5/input.txt @@ -0,0 +1 @@ +aababbb \ No newline at end of file diff --git a/challenges/frequency-deviation/test/5/output.txt b/challenges/frequency-deviation/test/5/output.txt new file mode 100644 index 0000000..e440e5c --- /dev/null +++ b/challenges/frequency-deviation/test/5/output.txt @@ -0,0 +1 @@ +3 \ No newline at end of file diff --git a/challenges/frequency-deviation/test/6/input.txt b/challenges/frequency-deviation/test/6/input.txt new file mode 100644 index 0000000..6a81654 --- /dev/null +++ b/challenges/frequency-deviation/test/6/input.txt @@ -0,0 +1 @@ +abcde \ No newline at end of file diff --git a/challenges/frequency-deviation/test/6/output.txt b/challenges/frequency-deviation/test/6/output.txt new file mode 100644 index 0000000..c227083 --- /dev/null +++ b/challenges/frequency-deviation/test/6/output.txt @@ -0,0 +1 @@ +0 \ No newline at end of file