Skip to content

Commit 40355ec

Browse files
committed
[Hacker Rank]: Sales by Match doc moved as Markdown
1 parent 8082155 commit 40355ec

File tree

2 files changed

+70
-67
lines changed

2 files changed

+70
-67
lines changed
Lines changed: 70 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,70 @@
1+
# [Sales by Match](https://www.hackerrank.com/challenges/sock-merchant)
2+
3+
Difficulty: #easy
4+
Category: #implementation
5+
6+
There is a large pile of socks that must be paired by color. Given an array
7+
of integers representing the color of each sock, determine how many pairs
8+
of socks with matching colors there are.
9+
10+
## Example
11+
12+
$ n = 7 $ \
13+
$ ar = [1, 2, 1, 2, 1, 3, 2] $
14+
15+
There is one pair of color $ 1 $ and one of color $ 2 $. There are three odd socks
16+
left, one of each color. The number of pairs is $ 2 $.
17+
18+
## Function Description
19+
20+
Complete the sockMerchant function in the editor below.
21+
22+
sockMerchant has the following parameter(s):
23+
24+
- int n: the number of socks in the pile
25+
- int ar[n]: the colors of each sock
26+
27+
## Returns
28+
29+
- int: the number of pairs
30+
31+
## Input Format
32+
33+
The first line contains an integer n, the number of socks represented in ar.
34+
The second line contains n space-separated integers, ar[i], the colors of
35+
the socks in the pile.
36+
37+
## Constraints
38+
39+
$ 1 \leq n < 100 $ \
40+
$ 1 \leq ar[i] \leq 100 $ where $ 0 \leq i < n $
41+
42+
## Sample Input
43+
44+
```text
45+
STDIN Function
46+
----- --------
47+
9 n = 9
48+
10 20 20 10 10 30 50 10 20 ar = [10, 20, 20, 10, 10, 30, 50, 10, 20]
49+
```
50+
51+
Sample Output
52+
53+
```text
54+
3
55+
```
56+
57+
## Explanation
58+
59+
```mermaid
60+
graph LR
61+
A((10)) --- B((20)) --- C((20)) ---
62+
D((10)) --- E((10)) --- F((30)) ---
63+
G((50)) --- H((10)) --- I((20))
64+
65+
A <-- pair --> D
66+
B <-- pair --> C
67+
E <-- pair --> H
68+
```
69+
70+
There are three pairs of socks.

src/hackerrank/implementation/sockMerchant.ts

Lines changed: 0 additions & 67 deletions
Original file line numberDiff line numberDiff line change
@@ -1,70 +1,3 @@
1-
/**
2-
* Sales by Match
3-
*
4-
* https://www.hackerrank.com/challenges/sock-merchant
5-
*
6-
* Difficulty: #easy
7-
* Category: #implementation
8-
*
9-
* There is a large pile of socks that must be paired by color. Given an array
10-
* of integers representing the color of each sock, determine how many pairs
11-
* of socks with matching colors there are.
12-
*
13-
* # Example
14-
* n = 7
15-
* ar = [1, 2, 1, 2, 1, 3, 2]
16-
*
17-
* There is one pair of color 1 and one of color 2. There are three odd socks
18-
* left, one of each color. The number of pairs is 2.
19-
*
20-
* # Function Description
21-
* Complete the sockMerchant function in the editor below.
22-
*
23-
* sockMerchant has the following parameter(s):
24-
* * int n: the number of socks in the pile
25-
* * int ar[n]: the colors of each sock
26-
*
27-
* # Returns
28-
* * int: the number of pairs
29-
*
30-
* # Input Format
31-
* The first line contains an integer n, the number of socks represented in ar.
32-
* The second line contains n space-separated integers, ar[i], the colors of
33-
* the socks in the pile.
34-
*
35-
* # Constraints
36-
* 1 <= n < 100
37-
* 1 <= ar[i] <= 100 where 0 <= i < n
38-
*
39-
* # Sample Input
40-
* ```
41-
* STDIN Function
42-
* ----- --------
43-
* 9 n = 9
44-
* 10 20 20 10 10 30 50 10 20 ar = [10, 20, 20, 10, 10, 30, 50, 10, 20]
45-
* ```
46-
*
47-
* Sample Output
48-
* ```
49-
* 3
50-
* ```
51-
*
52-
* # Explanation
53-
* ```mermaid
54-
* graph LR
55-
*
56-
* A((10)) --- B((20)) --- C((20)) ---
57-
* D((10)) --- E((10)) --- F((30)) ---
58-
* G((50)) --- H((10)) --- I((20))
59-
*
60-
* A <-- pair --> D
61-
* B <-- pair --> C
62-
* E <-- pair --> H
63-
* ```
64-
*
65-
* There are three pairs of socks.
66-
*/
67-
681
import { logger as console } from '../../logger';
692

703
export function sockMerchant(n: number, ar: number[]): number {

0 commit comments

Comments
 (0)