Skip to content

Navigation Menu

Sign in
Appearance settings

Search code, repositories, users, issues, pull requests...

Provide feedback

We read every piece of feedback, and take your input very seriously.

Saved searches

Use saved searches to filter your results more quickly

Sign up
Appearance settings

Commit 90bdef8

Browse files
Add 372_Perfectly-Balanced to DailyProgrammer
1 parent df10705 commit 90bdef8

File tree

3 files changed

+35
-0
lines changed

3 files changed

+35
-0
lines changed
Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,3 @@
1+
// ===================================
2+
// ProbName - Solution
3+
// ===================================
Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1 @@
1+
# ProbName - Notes
Lines changed: 31 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,31 @@
1+
# Challenge #372 [Easy]: Perfectly balanced
2+
3+
Given a string containing only the characters x and y, find whether there are the same number of xs and ys.
4+
5+
```
6+
balanced("xxxyyy") => true
7+
balanced("yyyxxx") => true
8+
balanced("xxxyyyy") => false
9+
balanced("yyxyxxyxxyyyyxxxyxyx") => true
10+
balanced("xyxxxxyyyxyxxyxxyy") => false
11+
balanced("") => true
12+
balanced("x") => false
13+
```
14+
15+
### Optional bonus
16+
17+
Given a string containing only lowercase letters, find whether every letter that appears in the string appears the same number of times. Don't forget to handle the empty string ("") correctly!
18+
19+
```
20+
balanced_bonus("xxxyyyzzz") => true
21+
balanced_bonus("abccbaabccba") => true
22+
balanced_bonus("xxxyyyzzzz") => false
23+
balanced_bonus("abcdefghijklmnopqrstuvwxyz") => true
24+
balanced_bonus("pqq") => false
25+
balanced_bonus("fdedfdeffeddefeeeefddf") => false
26+
balanced_bonus("www") => true
27+
balanced_bonus("x") => true
28+
balanced_bonus("") => true
29+
```
30+
31+
Note that `balanced_bonus` behaves differently than balanced for a few inputs, e.g. `"x"`.

0 commit comments

Comments
(0)

AltStyle によって変換されたページ (->オリジナル) /