Skip to content

Commit 717c164

Browse files
authored
Merge pull request #137 from sir-gon/develop
Develop
2 parents 6c0c8c6 + a39fb4b commit 717c164

File tree

121 files changed

+2442
-2925
lines changed

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

121 files changed

+2442
-2925
lines changed
Lines changed: 68 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,68 @@
1+
# [Between Two Sets](https://www.hackerrank.com/challenges/between-two-sets)
2+
3+
- Difficulty: #easy
4+
- Category: #implementation
5+
6+
There will be two arrays of integers. Determine all integers that satisfy
7+
the following two conditions:
8+
9+
1. The elements of the first array are all factors of the integer being
10+
considered
11+
2. The integer being considered is a factor of all elements of the second
12+
array
13+
14+
These numbers are referred to as being between the two arrays. Determine
15+
how many such numbers exist.
16+
17+
# Example
18+
$ a = [2, 6] $
19+
20+
$ b = [24, 36] $
21+
22+
There are two numbers between the arrays: $ 6 $ and $ 12 $.
23+
$ 6 \bmod 2 = 0 $, $ 6 \bmod 6 = 0 $, $ 24 \bmod 6 = 0 $ and $ 36 \bmod 6 = 0 $ for the first value.
24+
$ 12 \bmod 2 = 0 $, $ 12 \bmod 6 = 0 $, and $ 24 \bmod 12 = 0 $, $ 36 \bmod 12 = 0 $ for the second value. Return $ 2 $.
25+
26+
# Function Description
27+
Complete the getTotalX function in the editor below. It should return the
28+
number of integers that are betwen the sets.
29+
30+
getTotalX has the following parameter(s):
31+
32+
- int a[n]: an array of integers
33+
- int b[m]: an array of integers
34+
35+
# Returns
36+
- int: the number of integers that are between the sets
37+
38+
# Input Format
39+
The first line contains two space-separated integers, n and m, the number
40+
of elements in arrays a and b.
41+
The second line contains n distinct space-separated integers $ a[i] $ where
42+
$ 0 \leq i < n $.
43+
The third line contains m distinct space-separated integers $ b[j] $ where
44+
$ 0 \leq j < m $.
45+
46+
# Constraints
47+
- $ 1 \leq n, m < 10 $
48+
- $ 1 \leq a[i] \leq 100 $
49+
- $ 1 \leq b[j] \leq 100 $
50+
51+
# Sample Input
52+
```
53+
2 3
54+
2 4
55+
12 32 96
56+
```
57+
58+
# Sample Output
59+
```
60+
3
61+
```
62+
63+
# Explanation
64+
2 and 4 divide evenly into 4, 8, 12 and 16.
65+
66+
4, 8 and 16 divide evenly into 16, 32, 96.
67+
68+
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.

src/hackerrank/implementation/betweenTwoSets.ts

Lines changed: 0 additions & 70 deletions
Original file line numberDiff line numberDiff line change
@@ -1,73 +1,3 @@
1-
/**
2-
* Between Two Sets
3-
*
4-
* https://www.hackerrank.com/challenges/between-two-sets
5-
*
6-
* Difficulty: #easy
7-
* Category: #implementation
8-
*
9-
* There will be two arrays of integers. Determine all integers that satisfy
10-
* the following two conditions:
11-
*
12-
* 1. The elements of the first array are all factors of the integer being
13-
* considered
14-
* 2. The integer being considered is a factor of all elements of the second
15-
* array
16-
* These numbers are referred to as being between the two arrays. Determine
17-
* how many such numbers exist.
18-
*
19-
* # Example
20-
* a = [2, 6]
21-
* b = [24, 36]
22-
*
23-
* There are two numbers between the arrays: 6 and 12.
24-
* 6%2 = 0, 6%6 = 0, 24%6 = 0 and 36%6 = 0 for the first value.
25-
* 12%2 = 0, 12%6 = 0, and 24%12 = 0, 36%12 = 0 for the second value. Return 2.
26-
*
27-
* # Function Description
28-
* Complete the getTotalX function in the editor below. It should return the
29-
* number of integers that are betwen the sets.
30-
*
31-
* getTotalX has the following parameter(s):
32-
*
33-
* * int a[n]: an array of integers
34-
* * int b[m]: an array of integers
35-
*
36-
* # Returns
37-
* * int: the number of integers that are between the sets
38-
*
39-
* # Input Format
40-
* The first line contains two space-separated integers, n and m, the number
41-
* of elements in arrays a and b.
42-
* The second line contains n distinct space-separated integers a[i] where
43-
* 0 <= i < n.
44-
* The third line contains m distinct space-separated integers b[j] where
45-
* 0 <= j < m.
46-
*
47-
* # Constraionts
48-
* * 1 <= n, m < 10
49-
* * 1 <= a[i] <= 100
50-
* * 1 <= b[j] <= 100
51-
*
52-
* # Sample Input
53-
* ```
54-
* 2 3
55-
* 2 4
56-
* 12 32 96
57-
* ```
58-
*
59-
* # Sample Output
60-
* ```
61-
* 3
62-
* ```
63-
* # Explanation
64-
* 2 and 4 divide evenly into 4, 8, 12 and 16.
65-
* 4, 8 and 16 divide evenly into 16, 32, 96.
66-
* 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.
67-
*/
68-
69-
// import { logger as console } from '../../logger';
70-
711
export function isFactor(n: number, group: number[]): boolean {
722
let result = true;
733
let i = 0;
Lines changed: 124 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,124 @@
1+
# [Subarray Division](https://www.hackerrank.com/challenges/the-birthday-bar)
2+
3+
- Difficulty: #easy
4+
- Category: #implementation
5+
6+
Two children, Lily and Ron, want to share a chocolate bar. Each of the squares has an integer on it.
7+
8+
Lily decides to share a contiguous segment of the bar selected such that:
9+
10+
The length of the segment matches Ron's birth month, and,
11+
The sum of the integers on the squares is equal to his birth day.
12+
Determine how many ways she can divide the chocolate.
13+
14+
## Example
15+
16+
$ s = [2, 2, 1, 3, 2] $ \
17+
$ d = 4 $ \
18+
$ m = 2 $
19+
20+
Lily wants to find segments summing to Ron's birth day, $ d = 4 $ with a length
21+
equalling his birth month, $ m = 2 $. In this case, there are two segments
22+
meeting her criteria: $ [2, 2] $ and $ [1, 3] $.
23+
24+
## Function Description
25+
26+
Complete the birthday function in the editor below.
27+
28+
birthday has the following parameter(s):
29+
30+
- int s[n]: the numbers on each of the squares of chocolate
31+
- int d: Ron's birth day
32+
- int m: Ron's birth month
33+
34+
## Returns
35+
36+
- int: the number of ways the bar can be divided
37+
38+
## Input Format
39+
40+
The first line contains an integer , the number of squares in the chocolate
41+
bar.
42+
The second line contains n space-separated integers $ s[i] $, the numbers on the
43+
chocolate squares where $ 0 \leq i < n $.
44+
The third line contains two space-separated integers, d and m, Ron's
45+
birth day and his birth month.
46+
47+
## Constraints
48+
49+
$ 1 \leq n \leq 100 $ \
50+
$ 1 \leq s[i] \leq 5, where (0 \leq i < n) $ \
51+
$ 1 \leq d \leq 31 $ \
52+
$ 1 \leq m \leq 12 $
53+
54+
## Sample Input 0
55+
56+
```text
57+
5
58+
1 2 1 3 2
59+
3 2
60+
```
61+
62+
## Sample Output 0
63+
64+
```text
65+
2
66+
```
67+
68+
## Explanation 0
69+
70+
Lily wants to give Ron $ m = 2 $ squares summing to $ d = 3 $. The following two
71+
segments meet the criteria:
72+
73+
```mermaid
74+
graph LR
75+
A[1] --- |1 + 2 = 3|B[2] --- |2 + 1 = 3|C[1] --- D[3] --- E[2]
76+
```
77+
78+
## Sample Input 1
79+
80+
```text
81+
6
82+
1 1 1 1 1 1
83+
3 2
84+
```
85+
86+
## Sample Output 1
87+
88+
```text
89+
0
90+
```
91+
92+
## Explanation 1
93+
94+
Lily only wants to give Ron $ m = 2 $ consecutive squares of chocolate whose
95+
integers sum to $ d = 3 $. There are no possible pieces satisfying these
96+
constraints:
97+
98+
```mermaid
99+
graph LR
100+
101+
A[1] --- B[1] --- C[1] --- D[1] --- E[1] --- F[1]
102+
```
103+
104+
Thus, we print 0 as our answer.
105+
106+
## Sample Input 2
107+
108+
```text
109+
1
110+
4
111+
4 1
112+
```
113+
114+
## Sample Output 2
115+
116+
```text
117+
1
118+
```
119+
120+
## Explanation 2
121+
122+
Lily only wants to give Ron m = 1 square of chocolate with an integer value
123+
of d = 4. Because the only square of chocolate in the bar satisfies this
124+
constraint, we print 1 as our answer.

src/hackerrank/implementation/birthday.ts

Lines changed: 0 additions & 113 deletions
Original file line numberDiff line numberDiff line change
@@ -1,116 +1,3 @@
1-
/**
2-
* Subarray Division
3-
*
4-
* https://www.hackerrank.com/challenges/the-birthday-bar
5-
*
6-
* Difficulty: #easy
7-
* Category: #implementation
8-
*
9-
* Two children, Lily and Ron, want to share a chocolate bar. Each of the squares has an integer on it.
10-
*
11-
* Lily decides to share a contiguous segment of the bar selected such that:
12-
*
13-
* The length of the segment matches Ron's birth month, and,
14-
* The sum of the integers on the squares is equal to his birth day.
15-
* Determine how many ways she can divide the chocolate.
16-
*
17-
* Example
18-
* s = [2, 2, 1, 3, 2]
19-
* d = 4
20-
* m = 2
21-
*
22-
* Lily wants to find segments summing to Ron's birth day, d = 4 with a length
23-
* equalling his birth month, m = 2. In this case, there are two segments
24-
* meeting her criteria: [2, 2] and [1, 3].
25-
*
26-
* # Function Description
27-
* Complete the birthday function in the editor below.
28-
*
29-
* birthday has the following parameter(s):
30-
*
31-
* * int s[n]: the numbers on each of the squares of chocolate
32-
* * int d: Ron's birth day
33-
* * int m: Ron's birth month
34-
*
35-
* # Returns
36-
* * int: the number of ways the bar can be divided
37-
*
38-
* # Input Format
39-
* The first line contains an integer , the number of squares in the chocolate
40-
* bar.
41-
* The second line contains n space-separated integers s[i], the numbers on the
42-
* chocolate squares where 0 <= i < n.
43-
* The third line contains two space-separated integers, d and m, Ron's
44-
* birth day and his birth month.
45-
*
46-
* # Constraints
47-
* 1 <= n <= 100
48-
* 1 <= s[i] <= 5, where (0 <= i < n)
49-
* 1 <= d <= 31
50-
* 1 <= m <= 12
51-
*
52-
* # Sample Input 0
53-
* ```
54-
* 5
55-
* 1 2 1 3 2
56-
* 3 2
57-
* ```
58-
*
59-
* # Sample Output 0
60-
* ```
61-
* 2
62-
* ```
63-
*
64-
* # Explanation 0
65-
* Lily wants to give Ron m = 2 squares summing to d = 3. The following two
66-
* segments meet the criteria:
67-
*
68-
* ```mermaid
69-
* graph LR
70-
* A[1] --- |1 + 2 = 3|B[2] --- |2 + 1 = 3|C[1] --- D[3] --- E[2]
71-
* ```
72-
*
73-
* # Sample Input 1
74-
* ```
75-
* 6
76-
* 1 1 1 1 1 1
77-
* 3 2
78-
* ```
79-
*
80-
* # Sample Output 1
81-
* ```
82-
* 0
83-
* ```
84-
*
85-
* # Explanation 1
86-
* Lily only wants to give Ron m = 2 consecutive squares of chocolate whose
87-
* integers sum to d = 3. There are no possible pieces satisfying these
88-
* constraints:
89-
*
90-
* ```mermaid
91-
* graph LR
92-
* A[1] --- B[2] --- C[1] --- D[3] --- E[2]
93-
* ```
94-
* Thus, we print as our answer.
95-
*
96-
* #Sample Input 2
97-
* ```
98-
* 1
99-
* 4
100-
* 4 1
101-
* ```
102-
*
103-
* Sample Output 2
104-
* ```
105-
* 1
106-
* ```
107-
*
108-
* Explanation 2
109-
* Lily only wants to give Ron m = 1 square of chocolate with an integer value
110-
* of d = 4. Because the only square of chocolate in the bar satisfies this
111-
* constraint, we print 1 as our answer.
112-
*/
113-
1141
import { logger as console } from '../../logger';
1152

1163
export function birthday(s: number[], d: number, m: number): number {

0 commit comments

Comments
 (0)