Skip to content

Commit 83fdb88

Browse files
committed
Add more solutions (30 / 48)
1 parent ed8bc8b commit 83fdb88

File tree

13 files changed

+264
-178
lines changed

13 files changed

+264
-178
lines changed

‎Algorithms/Implementation/acm-icpc-team.cpp‎

Lines changed: 0 additions & 39 deletions
This file was deleted.

‎Algorithms/Implementation/encryption.cpp‎

Lines changed: 0 additions & 38 deletions
This file was deleted.

‎Algorithms/Implementation/find-digits.cpp‎

Lines changed: 0 additions & 26 deletions
This file was deleted.

‎Algorithms/Implementation/taum-and-bday.cpp‎

Lines changed: 0 additions & 25 deletions
This file was deleted.

‎README.md‎

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -7,7 +7,7 @@ I felt guilty for those who had watched and starred my repository. Thus, I'm try
77
|Domain|Status|Last Updated|
88
|---|---|---|
99
|[Algorithms - Warmup](domains/algorithms/warmup/README.md)|9 / 9|1/21/2017|
10-
|[Algorithms - Implementation](domains/algorithms/implementation/README.md)|24 / 48|2/5/2017|
10+
|[Algorithms - Implementation](domains/algorithms/implementation/README.md)|30 / 48|2/5/2017|
1111
|*Algorithms - Constructive Algorithms*|||
1212
|*Algorithms - Strings*|||
1313
|*Algorithms - Sorting*|||

‎algorithms/implementation/kaprekar-numbers.cpp‎

Lines changed: 0 additions & 47 deletions
This file was deleted.

‎domains/algorithms/implementation/README.md‎

Lines changed: 26 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,7 @@
22

33
This repository keeps a list of the problems in [Algorithms - Implementation](https://www.hackerrank.com/domains/algorithms/implementation). The threshold I'm currently using is 15, 30 and 45 minutes for each easy, medium and hard problem, respectively.
44

5-
## Submissions (24 / 48)
5+
## Submissions (30 / 48)
66

77
|Problem|Solution|Difficulty|Date|Time|#Sub|Comment|
88
|---|---|---|---|---|---|---|
@@ -29,4 +29,28 @@ This repository keeps a list of the problems in [Algorithms - Implementation](ht
2929
|[Non-Divisible Subset](https://www.hackerrank.com/challenges/non-divisible-subset)|[non-divisible-subset.cpp](non-divisible-subset.cpp)|Medium|2/5/2017|4'32"|1||
3030
|[Repeated String](https://www.hackerrank.com/challenges/repeated-string)|[repeated-string.cpp](repeated-string.cpp)|Easy|2/5/2017|3'01"|1||
3131
|[Jumping on the Clouds](https://www.hackerrank.com/challenges/jumping-on-the-clouds)|[jumping-on-the-clouds.cpp](jumping-on-the-clouds.cpp)|Easy|2/5/2017|4'41"|1||
32-
|[Equalize the Array](https://www.hackerrank.com/challenges/equality-in-a-array)|[equality-in-a-array.cpp](equality-in-a-array.cpp)|Easy|2/5/2017|2'17"|1||
32+
|[Equalize the Array](https://www.hackerrank.com/challenges/equality-in-a-array)|[equality-in-a-array.cpp](equality-in-a-array.cpp)|Easy|2/5/2017|2'17"|1||
33+
|[ACM ICPC Team](https://www.hackerrank.com/challenges/acm-icpc-team)|[acm-icpc-team.cpp](acm-icpc-team.cpp)|Easy|2/5/2017|4'05"|1||
34+
|[Taum and B'day](https://www.hackerrank.com/challenges/taum-and-bday)|[taum-and-bday.cpp](taum-and-bday.cpp)|Easy|2/5/2017|3'57"|1||
35+
|[Encryption](https://www.hackerrank.com/challenges/encryption)|[encryption.cpp](encryption.cpp)|Medium|2/5/2017|11'30"|1||
36+
|[Bigger is Greater](https://www.hackerrank.com/challenges/bigger-is-greater)|[bigger-is-greater.cpp](bigger-is-greater.cpp)|Medium|2/5/2017|13'49"|1||
37+
|[Modified Kaprekar Numbers](https://www.hackerrank.com/challenges/kaprekar-numbers)|[kaprekar-numbers.cpp](kaprekar-numbers.cpp)|Easy|2/5/2017|5'09"|1||
38+
|[Beautiful Triplets](https://www.hackerrank.com/challenges/beautiful-triplets)|[beautiful-triplets.cpp](beautiful-triplets.cpp)|Easy|2/5/2017|3'58"|2||
39+
|[Manasa and Stones](https://www.hackerrank.com/challenges/manasa-and-stones)|manasa-and-stones.cpp|Easy|||||
40+
|[Minimum Distances](https://www.hackerrank.com/challenges/minimum-distances)|minimum-distances.cpp|Easy|||||
41+
|[The Time in Words](https://www.hackerrank.com/challenges/the-time-in-words)|the-time-in-words.cpp|Medium|||||
42+
|[Cavity Map](https://www.hackerrank.com/challenges/cavity-map)|cavity-map.cpp|Easy|||||
43+
|[Chocolate Feast](https://www.hackerrank.com/challenges/chocolate-feast)|chocolate-feast.cpp|Easy|||||
44+
|[Service Lane](https://www.hackerrank.com/challenges/service-lane)|service-lane.cpp|Easy|||||
45+
|[Lisa's Workbook](https://www.hackerrank.com/challenges/lisa-workbook)|lisa-workbook.cpp|Easy|||||
46+
|[The Grid Search](https://www.hackerrank.com/challenges/the-grid-search)|the-grid-search.cpp|Medium|||||
47+
|[Flatland Space Stations](https://www.hackerrank.com/challenges/flatland-space-stations)|flatland-space-stations.cpp|Easy|||||
48+
|[Fair Rations](https://www.hackerrank.com/challenges/fair-rations)|fair-rations.cpp|Easy|||||
49+
|[Happy Ladybugs](https://www.hackerrank.com/challenges/happy-ladybugs)|happy-ladybugs.cpp|Easy|||||
50+
|[Strange Counter](https://www.hackerrank.com/challenges/strange-code)|strange-code.cpp|Easy|||||
51+
|[Almost Sorted](https://www.hackerrank.com/challenges/almost-sorted)|almost-sorted.cpp|Medium|||||
52+
|[Absolute Permutation](https://www.hackerrank.com/challenges/absolute-permutation)|absolute-permutation.cpp|Medium|||||
53+
|[The Bomberman Game](https://www.hackerrank.com/challenges/bomber-man)|bomber-man.cpp|Medium|||||
54+
|[Ema's Supercomputer](https://www.hackerrank.com/challenges/two-pluses)|two-pluses.cpp|Medium|||||
55+
|[Larry's Array](https://www.hackerrank.com/challenges/larrys-array)|larrys-array.cpp|Medium|||||
56+
|[Matrix Layer Rotation](https://www.hackerrank.com/challenges/matrix-rotation-algo)|matrix-rotation-algo.cpp|Hard|||||
Lines changed: 44 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,44 @@
1+
/*
2+
acm-icpc-team.cpp
3+
ACM ICPC Team
4+
*/
5+
6+
#include <iostream>
7+
#include <string>
8+
#include <vector>
9+
using namespace std;
10+
11+
vector<vector<bool> > v;
12+
13+
int main() {
14+
int n, m;
15+
cin >> n >> m;
16+
v.resize(n);
17+
for (int i = 0; i < n; i++) {
18+
v[i].resize(m);
19+
string str;
20+
cin >> str;
21+
for (int j = 0; j < m; j++) {
22+
v[i][j] = str[j] - '0';
23+
}
24+
}
25+
int maxTopic = 0, maxCnt = 0;
26+
for (int i = 0; i < n; i++) {
27+
for (int j = i + 1; j < n; j++) {
28+
int cntTopic = 0;
29+
for (int k = 0; k < m; k++) {
30+
if (v[i][k] || v[j][k]) {
31+
cntTopic++;
32+
}
33+
}
34+
if (cntTopic > maxTopic) {
35+
maxTopic = cntTopic;
36+
maxCnt = 1;
37+
} else if (cntTopic == maxTopic) {
38+
maxCnt++;
39+
}
40+
}
41+
}
42+
cout << maxTopic << endl << maxCnt << endl;
43+
return 0;
44+
}
Lines changed: 34 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,34 @@
1+
/*
2+
beautiful-triplets.cpp
3+
Beautiful triplets
4+
5+
My first submission got WA. I've created an array `h` of size that is exactly
6+
20001. Clearly this has some out-of-bound issues when checking h[v[i] + d] and
7+
h[v[i] + d + d].
8+
*/
9+
10+
#include <iostream>
11+
#include <vector>
12+
using namespace std;
13+
14+
vector<int> v;
15+
bool h[21001];
16+
17+
int main() {
18+
int n, d;
19+
cin >> n >> d;
20+
for (int i = 0; i < n; i++) {
21+
int num;
22+
cin >> num;
23+
v.push_back(num);
24+
h[num] = true;
25+
}
26+
int cnt = 0;
27+
for (int i = 0; i < n; i++) {
28+
if (h[v[i] + d] && h[v[i] + d + d]) {
29+
cnt++;
30+
}
31+
}
32+
cout << cnt << endl;
33+
return 0;
34+
}
Lines changed: 42 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,42 @@
1+
/*
2+
bigger-is-greater.cpp
3+
Bigger is Greater
4+
*/
5+
6+
#include <algorithm>
7+
#include <iostream>
8+
#include <string>
9+
using namespace std;
10+
11+
int main() {
12+
int t;
13+
cin >> t;
14+
while (t--) {
15+
string s;
16+
cin >> s;
17+
int pos = -1;
18+
for (int i = s.size() - 1; i > 0; i--) {
19+
if (s[i] > s[i - 1]) {
20+
pos = i;
21+
break;
22+
}
23+
}
24+
if (pos == -1) {
25+
cout << "no answer" << endl;
26+
} else {
27+
int minVal = 1000, maxIdx = -1;
28+
for (int i = pos; i < s.size(); i++) {
29+
if (s[i] > s[pos - 1]) {
30+
if (s[i] < minVal || (s[i] == minVal && i > maxIdx)) {
31+
minVal = s[i];
32+
maxIdx = i;
33+
}
34+
}
35+
}
36+
swap(s[pos - 1], s[maxIdx]);
37+
reverse(s.begin() + pos, s.end());
38+
cout << s << endl;
39+
}
40+
}
41+
return 0;
42+
}

0 commit comments

Comments
 (0)