Skip to content

Commit 10eaa00

Browse files
author
Jakub Jirous
committed
add index.md to each challenge, ts types refactoring
1 parent a2b94e3 commit 10eaa00

25 files changed

+345
-46
lines changed

.github/labeler.yml

+2
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,2 @@
1+
code-challenge:
2+
- any: ["src/**/*.ts"]

.github/pull_request_template.md

+27
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,27 @@
1+
## NAME
2+
3+
- [Problem Description @ Code Signal](URL)
4+
5+
---
6+
7+
### PR Checklist:
8+
9+
- [ ] Understand the problem
10+
- You know what is known
11+
- You know what is unknown
12+
- You thought throw some edge cases that could potentially happen
13+
- [ ] Devise a plan
14+
- Writing a comment to code challenge what you want to do
15+
- Showing the ability to take that problem and break it down to the parts
16+
- Take the larger problem and take it down into smaller problems
17+
- [ ] Execute the plan
18+
- Turning into an actual code
19+
- [ ] Review your solution
20+
- Time to consider if there were a better approach
21+
- Backwards realizing room for improvements
22+
- [ ] Unit test
23+
- Cover your result with appropriate assertions
24+
25+
---
26+
27+
@octocat :+1: This PR looks great - it's ready to merge! :shipit:

.github/workflows/labeler.yml

+18
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,18 @@
1+
name: "Pull Request Labeler"
2+
3+
on:
4+
- pull_request_target
5+
6+
jobs:
7+
triage:
8+
name: "Labeler"
9+
permissions:
10+
contents: read
11+
pull-requests: write
12+
13+
runs-on: ubuntu-latest
14+
15+
steps:
16+
- uses: actions/labeler@v4
17+
with:
18+
repo-token: "${{ secrets.GITHUB_TOKEN }}"

README.md

+8-7
Original file line numberDiff line numberDiff line change
@@ -12,6 +12,7 @@ In preparation for technical interviews, I discovered this platform that provide
1212

1313
<p align="center">
1414
<img src="https://sonarcloud.io/api/project_badges/measure?project=jakubjirous_code-signal&metric=coverage" alt="Coverage">
15+
<img src="https://sonarcloud.io/api/project_badges/measure?project=jakubjirous_code-signal&metric=code_smells" alt="Code Smells">
1516
<img src="https://sonarcloud.io/api/project_badges/measure?project=jakubjirous_code-signal&metric=ncloc" alt="Lines of Code">
1617
</p>
1718

@@ -23,16 +24,16 @@ In preparation for technical interviews, I discovered this platform that provide
2324

2425
#### The Journey Begins
2526

26-
1) [Add](/src/arcade/intro/01-add/)
27-
2) [Century From Year](/src/arcade/intro/02-century-from-year/)
28-
3) [Check Palindrome](/src/arcade/intro/03-check-palindrome/)
27+
1) [Add](/src/arcade/intro/01-add/INDEX.md)
28+
2) [Century From Year](/src/arcade/intro/02-century-from-year/INDEX.md)
29+
3) [Check Palindrome](/src/arcade/intro/03-check-palindrome/INDEX.md)
2930

3031
#### Edge Of The Ocean
3132

32-
4) [Adjacent Elements Product](/src/arcade/intro/04-adjacent-elements-product/)
33-
5) [Shape Area](/src/arcade/intro/05-shape-area/)
34-
6) [Make Array Consecutive](/src/arcade/intro/06-make-array-consecutive/)
35-
7) [Almost Increasing Sequence](/src/arcade/07-almost-increasing-sequence/)
33+
4) [Adjacent Elements Product](/src/arcade/intro/04-adjacent-elements-product/INDEX.md)
34+
5) [Shape Area](/src/arcade/intro/05-shape-area/INDEX.md)
35+
6) [Make Array Consecutive](/src/arcade/intro/06-make-array-consecutive/INDEX.md)
36+
7) [Almost Increasing Sequence](/src/arcade/intro/07-almost-increasing-sequence/INDEX.md)
3637

3738
---
3839

src/arcade/intro/01-add/INDEX.md

+34
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,34 @@
1+
# Add
2+
3+
Write a function that returns the sum of two numbers.
4+
5+
---
6+
7+
### Example:
8+
9+
- For `param1 = 1` and `param2 = 2`, the output should be `solution(param1, param2) = 3`.
10+
11+
### Input/Output:
12+
13+
- **[execution time limit]** 5 seconds (ts)
14+
15+
16+
- **[input]** integer `param1`
17+
- Guaranteed constraints:
18+
- $-1000 \le param1 \le 1000$
19+
20+
21+
- **[input]** integer `param2`
22+
- Guaranteed constraints:
23+
- $-1000 \le param2 \le 1000$
24+
25+
26+
- **[output]** integer
27+
- The sum of the two inputs.
28+
29+
---
30+
31+
### Solution:
32+
33+
- [Code](/src/arcade/intro/01-add/add.ts)
34+
- [Tests](/src/arcade/intro/01-add/test/add.test.ts)

src/arcade/intro/01-add/add.ts

+5-1
Original file line numberDiff line numberDiff line change
@@ -1,9 +1,13 @@
1+
export type Param1 = number;
2+
export type Param2 = number;
3+
export type Output = number;
4+
15
/**
26
* Write a function that returns the sum of two numbers.
37
*
48
* Example:
59
* - for param1 = 1 and param2 = 2, the output should be solution(param1, param2) = 3
610
*/
7-
export const add = (param1: number, param2: number): number => {
11+
export const add = (param1: Param1, param2: Param2): Output => {
812
return param1 + param2;
913
};

src/arcade/intro/01-add/test/add.test.ts

+2-5
Original file line numberDiff line numberDiff line change
@@ -1,9 +1,6 @@
1-
import { add } from "../add";
1+
import { add, Output, Param1, Param2 } from '../add';
22

3-
type FirstArg = number;
4-
type SecondArg = number;
5-
type ExpectedResult = number;
6-
type Cases = [FirstArg, SecondArg, ExpectedResult][];
3+
type Cases = [Param1, Param2, Output][];
74

85
/**
96
* Testing a function that returns the sum of two numbers.
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,33 @@
1+
# Century From Year
2+
3+
Given a year, return the century it is in.
4+
5+
The first century spans from the year 1 up to and including the year 100, the second - from the year 101 up to and including the year 200, etc.
6+
7+
---
8+
9+
### Example:
10+
11+
- For `year = 1905`, the output should be `centuryFromYear(year) = 20`
12+
- For `year = 1700`, the output should be `centuryFromYear(year) = 17`
13+
14+
### Input/Output:
15+
16+
- **[execution time limit]** 5 seconds (ts)
17+
18+
19+
- **[input]** integer `year`
20+
- A positive integer, designating the year.
21+
- Guaranteed constraints:
22+
- $1 \le year \le 2005$
23+
24+
25+
- **[output]** integer
26+
- The number of the century the year is in.
27+
28+
---
29+
30+
### Solution:
31+
32+
- [Code](/src/arcade/intro/02-century-from-year/century-from-year.ts)
33+
- [Tests](/src/arcade/intro/02-century-from-year/test/century-from-year.test.ts)
Original file line numberDiff line numberDiff line change
@@ -1,9 +1,12 @@
1+
export type Input = number;
2+
export type Output = number;
3+
14
/**
25
* Given a year, return the century it is in.
36
* The first century spans from the year 1 up to and including the year 100,
47
* the second - from the year 101 up to and including the year 200, etc.
58
* @param year
69
*/
7-
export const centuryFromYear = (year: number): number => {
10+
export const centuryFromYear = (year: Input): Output => {
811
return Math.ceil(year / 100);
912
};

src/arcade/intro/02-century-from-year/test/century-from-year.test.ts

+2-4
Original file line numberDiff line numberDiff line change
@@ -1,8 +1,6 @@
1-
import { centuryFromYear } from "../century-from-year";
1+
import { centuryFromYear, Input, Output } from '../century-from-year';
22

3-
type FirstArg = number;
4-
type ExpectedResult = number;
5-
type Cases = [FirstArg, ExpectedResult][];
3+
type Cases = [Input, Output][];
64

75
/**
86
* Given a year, return the century it is in.
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,33 @@
1+
# Check Palindrome
2+
3+
Given the string, check if it is a palindrome.
4+
5+
---
6+
7+
### Example:
8+
9+
- For `inputString = "aabaa"`, the output should be `checkPalindrome(inputString) = true`
10+
- For `inputString = "abac"`, the output should be `checkPalindrome(inputString) = false`
11+
- For `inputString = "a"`, the output should be `checkPalindrome(inputString) = true`
12+
13+
### Input/Output:
14+
15+
- **[execution time limit]** 5 seconds (ts)
16+
17+
18+
- **[input]** string `inputString`
19+
- A non-empty string consisting of lowercase characters.
20+
- Guaranteed constraints:
21+
- $1 \le inputString.length \le 10^{5}$
22+
23+
24+
- **[output]** boolean
25+
- `true` if `inputString` is a palindrome
26+
- `false` otherwise
27+
28+
---
29+
30+
### Solution:
31+
32+
- [Code](/src/arcade/intro/03-check-palindrome/check-palindrome.ts)
33+
- [Tests](/src/arcade/intro/03-check-palindrome/test/check-palindrome.test.ts)
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,10 @@
1+
export type Input = string;
2+
export type Output = boolean;
3+
14
/**
25
* Given the string, check if it is a palindrome.
36
* @param inputString
47
*/
5-
export const checkPalindrome = (inputString: string): boolean => {
8+
export const checkPalindrome = (inputString: Input): Output => {
69
return inputString === [...inputString].reverse().join("");
710
};

src/arcade/intro/03-check-palindrome/test/check-palindrome.test.ts

+2-4
Original file line numberDiff line numberDiff line change
@@ -1,8 +1,6 @@
1-
import { checkPalindrome } from "../check-palindrome";
1+
import { checkPalindrome, Input, Output } from '../check-palindrome';
22

3-
type FirstArg = string;
4-
type ExpectedResult = boolean;
5-
type Cases = [FirstArg, ExpectedResult][];
3+
type Cases = [Input, Output][];
64

75
/**
86
* Test if it is a palindrome.
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,32 @@
1+
# Adjacent Elements Product
2+
3+
Given an array of integers, find the pair of adjacent elements that has the largest product and return that product.
4+
5+
---
6+
7+
### Example:
8+
9+
- For `inputArray = [3, 6, -2, -5, 7, 3]`, the output should be `adjacentElementsProduct(inputArray) = 21`.
10+
- `7` and `3` produce the largest product.
11+
12+
### Input/Output:
13+
14+
- **[execution time limit]** 5 seconds (ts)
15+
16+
17+
- **[input]** array.integer `inputArray`
18+
- An array of integers containing at least two elements.
19+
- Guaranteed constraints:
20+
- $2 \le inputArray.length \le 10$
21+
- $-100 \le inputArray[i] \le 1000$
22+
23+
24+
- **[output]** integer
25+
- The largest product of adjacent elements.
26+
27+
---
28+
29+
### Solution:
30+
31+
- [Code](/src/arcade/intro/04-adjacent-elements-product/adjacent-elements-product.ts)
32+
- [Tests](/src/arcade/intro/04-adjacent-elements-product/test/adjacent-elements-product.test.ts)
Original file line numberDiff line numberDiff line change
@@ -1,10 +1,13 @@
1+
export type Input = number[];
2+
export type Output = number;
3+
14
/**
25
* Given an array of integers, find the pair of adjacent elements that has the largest product and return that product.
3-
* @param input
6+
* @param inputArray
47
*/
5-
export const adjacentElementsProduct = (input: number[]): number => {
6-
return input.reduce((acc, value, index, arr) => {
7-
const nextCase = value * arr[index - 1];
8+
export const adjacentElementsProduct = (inputArray: Input): Output => {
9+
return inputArray.reduce((acc, value, index, array) => {
10+
const nextCase = value * array[index - 1];
811
return nextCase > acc ? (acc = nextCase) : acc;
912
}, Number.NEGATIVE_INFINITY);
1013
};

src/arcade/intro/04-adjacent-elements-product/test/adjacent-elements-product.test.ts

+2-4
Original file line numberDiff line numberDiff line change
@@ -1,8 +1,6 @@
1-
import { adjacentElementsProduct } from "../adjacent-elements-product";
1+
import { adjacentElementsProduct, Input, Output } from '../adjacent-elements-product';
22

3-
type FirstArg = number[];
4-
type ExpectedResult = number;
5-
type Cases = [FirstArg, ExpectedResult][];
3+
type Cases = [Input, Output][];
64

75
/**
86
* Given an array of integers, test the pair of adjacent elements that has the largest product and return that product.
+35
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,35 @@
1+
# Shape Area
2+
3+
We will define an `n`-interesting polygon.
4+
5+
Your task is to find the area of a polygon for a given `n`.
6+
7+
A `1`-interesting polygon is just a square with a side of length `1`.
8+
An `n`-interesting polygon is obtained by taking the `n - 1`-interesting polygon and appending `1`-interesting polygons to its rim, side by side.
9+
10+
---
11+
12+
### Example:
13+
14+
- For `n = 2`, the output should be `shapeArea(n) = 5`
15+
- For `n = 3`, the output should be `shapeArea(n) = 13`
16+
17+
### Input/Output:
18+
19+
- **[execution time limit]** 5 seconds (ts)
20+
21+
22+
- **[input]** integer `n`
23+
- Guaranteed constraints:
24+
- $1 \le n \le 10^{4}$
25+
26+
27+
- **[output]** integer
28+
- The area of the `n`-interesting polygon.
29+
30+
---
31+
32+
### Solution:
33+
34+
- [Code](/src/arcade/intro/05-shape-area/shape-area.ts)
35+
- [Tests](/src/arcade/intro/05-shape-area/test/shape-area.test.ts)

src/arcade/intro/05-shape-area/shape-area.ts

+4-1
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,6 @@
1+
export type Input = number;
2+
export type Output = number;
3+
14
/**
25
* Below we will define an n-interesting polygon.
36
* Your task is to find the area of a polygon for a given n.
@@ -8,4 +11,4 @@
811
*
912
* @param n
1013
*/
11-
export const shapeArea = (n: number): number => n * n + (n - 1) * (n - 1);
14+
export const shapeArea = (n: Input): Output => n * n + (n - 1) * (n - 1);

src/arcade/intro/05-shape-area/test/shape-area.test.ts

+2-4
Original file line numberDiff line numberDiff line change
@@ -1,8 +1,6 @@
1-
import { shapeArea } from "../shape-area";
1+
import { Input, Output, shapeArea } from '../shape-area';
22

3-
type FirstArg = number;
4-
type ExpectedResult = number;
5-
type Cases = [FirstArg, ExpectedResult][];
3+
type Cases = [Input, Output][];
64

75
/**
86
* Test the area of a polygon for a given n.

0 commit comments

Comments
 (0)