Skip to content

Commit

Permalink
Merge pull request #137 from sir-gon/develop
Browse files Browse the repository at this point in the history
Develop
  • Loading branch information
sir-gon authored Jul 27, 2023
2 parents 6c0c8c6 + a39fb4b commit 717c164
Show file tree
Hide file tree
Showing 121 changed files with 2,442 additions and 2,925 deletions.
68 changes: 68 additions & 0 deletions src/hackerrank/implementation/betweenTwoSets.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,68 @@
# [Between Two Sets](https://www.hackerrank.com/challenges/between-two-sets)

- Difficulty: #easy
- Category: #implementation

There will be two arrays of integers. Determine all integers that satisfy
the following two conditions:

1. The elements of the first array are all factors of the integer being
considered
2. The integer being considered is a factor of all elements of the second
array

These numbers are referred to as being between the two arrays. Determine
how many such numbers exist.

# Example
$ a = [2, 6] $

$ b = [24, 36] $

There are two numbers between the arrays: $ 6 $ and $ 12 $.
$ 6 \bmod 2 = 0 $, $ 6 \bmod 6 = 0 $, $ 24 \bmod 6 = 0 $ and $ 36 \bmod 6 = 0 $ for the first value.
$ 12 \bmod 2 = 0 $, $ 12 \bmod 6 = 0 $, and $ 24 \bmod 12 = 0 $, $ 36 \bmod 12 = 0 $ for the second value. Return $ 2 $.

# Function Description
Complete the getTotalX function in the editor below. It should return the
number of integers that are betwen the sets.

getTotalX has the following parameter(s):

- int a[n]: an array of integers
- int b[m]: an array of integers

# Returns
- int: the number of integers that are between the sets

# Input Format
The first line contains two space-separated integers, n and m, the number
of elements in arrays a and b.
The second line contains n distinct space-separated integers $ a[i] $ where
$ 0 \leq i < n $.
The third line contains m distinct space-separated integers $ b[j] $ where
$ 0 \leq j < m $.

# Constraints
- $ 1 \leq n, m < 10 $
- $ 1 \leq a[i] \leq 100 $
- $ 1 \leq b[j] \leq 100 $

# Sample Input
```
2 3
2 4
12 32 96
```

# Sample Output
```
3
```

# Explanation
2 and 4 divide evenly into 4, 8, 12 and 16.

4, 8 and 16 divide evenly into 16, 32, 96.

4, 8 and 16 are the only three numbers for which each element of a is a factor and each is a factor of all elements of b.
70 changes: 0 additions & 70 deletions src/hackerrank/implementation/betweenTwoSets.ts
Original file line number Diff line number Diff line change
@@ -1,73 +1,3 @@
/**
* Between Two Sets
*
* https://www.hackerrank.com/challenges/between-two-sets
*
* Difficulty: #easy
* Category: #implementation
*
* There will be two arrays of integers. Determine all integers that satisfy
* the following two conditions:
*
* 1. The elements of the first array are all factors of the integer being
* considered
* 2. The integer being considered is a factor of all elements of the second
* array
* These numbers are referred to as being between the two arrays. Determine
* how many such numbers exist.
*
* # Example
* a = [2, 6]
* b = [24, 36]
*
* There are two numbers between the arrays: 6 and 12.
* 6%2 = 0, 6%6 = 0, 24%6 = 0 and 36%6 = 0 for the first value.
* 12%2 = 0, 12%6 = 0, and 24%12 = 0, 36%12 = 0 for the second value. Return 2.
*
* # Function Description
* Complete the getTotalX function in the editor below. It should return the
* number of integers that are betwen the sets.
*
* getTotalX has the following parameter(s):
*
* * int a[n]: an array of integers
* * int b[m]: an array of integers
*
* # Returns
* * int: the number of integers that are between the sets
*
* # Input Format
* The first line contains two space-separated integers, n and m, the number
* of elements in arrays a and b.
* The second line contains n distinct space-separated integers a[i] where
* 0 <= i < n.
* The third line contains m distinct space-separated integers b[j] where
* 0 <= j < m.
*
* # Constraionts
* * 1 <= n, m < 10
* * 1 <= a[i] <= 100
* * 1 <= b[j] <= 100
*
* # Sample Input
* ```
* 2 3
* 2 4
* 12 32 96
* ```
*
* # Sample Output
* ```
* 3
* ```
* # Explanation
* 2 and 4 divide evenly into 4, 8, 12 and 16.
* 4, 8 and 16 divide evenly into 16, 32, 96.
* 4, 8 and 16 are the only three numbers for which each element of a is a factor and each is a factor of all elements of b.
*/

// import { logger as console } from '../../logger';

export function isFactor(n: number, group: number[]): boolean {
let result = true;
let i = 0;
Expand Down
124 changes: 124 additions & 0 deletions src/hackerrank/implementation/birthday.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,124 @@
# [Subarray Division](https://www.hackerrank.com/challenges/the-birthday-bar)

- Difficulty: #easy
- Category: #implementation

Two children, Lily and Ron, want to share a chocolate bar. Each of the squares has an integer on it.

Lily decides to share a contiguous segment of the bar selected such that:

The length of the segment matches Ron's birth month, and,
The sum of the integers on the squares is equal to his birth day.
Determine how many ways she can divide the chocolate.

## Example

$ s = [2, 2, 1, 3, 2] $ \
$ d = 4 $ \
$ m = 2 $

Lily wants to find segments summing to Ron's birth day, $ d = 4 $ with a length
equalling his birth month, $ m = 2 $. In this case, there are two segments
meeting her criteria: $ [2, 2] $ and $ [1, 3] $.

## Function Description

Complete the birthday function in the editor below.

birthday has the following parameter(s):

- int s[n]: the numbers on each of the squares of chocolate
- int d: Ron's birth day
- int m: Ron's birth month

## Returns

- int: the number of ways the bar can be divided

## Input Format

The first line contains an integer , the number of squares in the chocolate
bar.
The second line contains n space-separated integers $ s[i] $, the numbers on the
chocolate squares where $ 0 \leq i < n $.
The third line contains two space-separated integers, d and m, Ron's
birth day and his birth month.

## Constraints

$ 1 \leq n \leq 100 $ \
$ 1 \leq s[i] \leq 5, where (0 \leq i < n) $ \
$ 1 \leq d \leq 31 $ \
$ 1 \leq m \leq 12 $

## Sample Input 0

```text
5
1 2 1 3 2
3 2
```

## Sample Output 0

```text
2
```

## Explanation 0

Lily wants to give Ron $ m = 2 $ squares summing to $ d = 3 $. The following two
segments meet the criteria:

```mermaid
graph LR
A[1] --- |1 + 2 = 3|B[2] --- |2 + 1 = 3|C[1] --- D[3] --- E[2]
```

## Sample Input 1

```text
6
1 1 1 1 1 1
3 2
```

## Sample Output 1

```text
0
```

## Explanation 1

Lily only wants to give Ron $ m = 2 $ consecutive squares of chocolate whose
integers sum to $ d = 3 $. There are no possible pieces satisfying these
constraints:

```mermaid
graph LR
A[1] --- B[1] --- C[1] --- D[1] --- E[1] --- F[1]
```

Thus, we print 0 as our answer.

## Sample Input 2

```text
1
4
4 1
```

## Sample Output 2

```text
1
```

## Explanation 2

Lily only wants to give Ron m = 1 square of chocolate with an integer value
of d = 4. Because the only square of chocolate in the bar satisfies this
constraint, we print 1 as our answer.
113 changes: 0 additions & 113 deletions src/hackerrank/implementation/birthday.ts
Original file line number Diff line number Diff line change
@@ -1,116 +1,3 @@
/**
* Subarray Division
*
* https://www.hackerrank.com/challenges/the-birthday-bar
*
* Difficulty: #easy
* Category: #implementation
*
* Two children, Lily and Ron, want to share a chocolate bar. Each of the squares has an integer on it.
*
* Lily decides to share a contiguous segment of the bar selected such that:
*
* The length of the segment matches Ron's birth month, and,
* The sum of the integers on the squares is equal to his birth day.
* Determine how many ways she can divide the chocolate.
*
* Example
* s = [2, 2, 1, 3, 2]
* d = 4
* m = 2
*
* Lily wants to find segments summing to Ron's birth day, d = 4 with a length
* equalling his birth month, m = 2. In this case, there are two segments
* meeting her criteria: [2, 2] and [1, 3].
*
* # Function Description
* Complete the birthday function in the editor below.
*
* birthday has the following parameter(s):
*
* * int s[n]: the numbers on each of the squares of chocolate
* * int d: Ron's birth day
* * int m: Ron's birth month
*
* # Returns
* * int: the number of ways the bar can be divided
*
* # Input Format
* The first line contains an integer , the number of squares in the chocolate
* bar.
* The second line contains n space-separated integers s[i], the numbers on the
* chocolate squares where 0 <= i < n.
* The third line contains two space-separated integers, d and m, Ron's
* birth day and his birth month.
*
* # Constraints
* 1 <= n <= 100
* 1 <= s[i] <= 5, where (0 <= i < n)
* 1 <= d <= 31
* 1 <= m <= 12
*
* # Sample Input 0
* ```
* 5
* 1 2 1 3 2
* 3 2
* ```
*
* # Sample Output 0
* ```
* 2
* ```
*
* # Explanation 0
* Lily wants to give Ron m = 2 squares summing to d = 3. The following two
* segments meet the criteria:
*
* ```mermaid
* graph LR
* A[1] --- |1 + 2 = 3|B[2] --- |2 + 1 = 3|C[1] --- D[3] --- E[2]
* ```
*
* # Sample Input 1
* ```
* 6
* 1 1 1 1 1 1
* 3 2
* ```
*
* # Sample Output 1
* ```
* 0
* ```
*
* # Explanation 1
* Lily only wants to give Ron m = 2 consecutive squares of chocolate whose
* integers sum to d = 3. There are no possible pieces satisfying these
* constraints:
*
* ```mermaid
* graph LR
* A[1] --- B[2] --- C[1] --- D[3] --- E[2]
* ```
* Thus, we print as our answer.
*
* #Sample Input 2
* ```
* 1
* 4
* 4 1
* ```
*
* Sample Output 2
* ```
* 1
* ```
*
* Explanation 2
* Lily only wants to give Ron m = 1 square of chocolate with an integer value
* of d = 4. Because the only square of chocolate in the bar satisfies this
* constraint, we print 1 as our answer.
*/

import { logger as console } from '../../logger';

export function birthday(s: number[], d: number, m: number): number {
Expand Down
Loading

0 comments on commit 717c164

Please sign in to comment.