-
Notifications
You must be signed in to change notification settings - Fork 24
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Showing
27 changed files
with
652 additions
and
5 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,6 @@ | ||
add_hackerrank(prime-date prime-date.cpp) | ||
add_hackerrank_py(prime-date.py) | ||
|
||
dirty_cpp(prime-date) | ||
add_hackerrank_py(zig-zag-sequence.py) | ||
add_hackerrank(zig-zag-sequence zig-zag-sequence.cpp) |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,13 @@ | ||
|
||
### [Algorithms](https://www.hackerrank.com/domains/algorithms) | ||
The true test of problem solving: when one realizes that time and memory aren't infinite. | ||
|
||
|
||
|
||
#### [Debugging](https://www.hackerrank.com/domains/algorithms/algo-debugging) | ||
|
||
Name | Preview | Code | Difficulty | ||
---- | ------- | ---- | ---------- | ||
[Prime Dates](https://www.hackerrank.com/challenges/prime-date)|Find the number of prime dates in a range|[C++](prime-date.cpp) [Python](prime-date.py)|Medium | ||
[Zig Zag Sequence](https://www.hackerrank.com/challenges/zig-zag-sequence)|Find a zig zag sequence of the given array.|[C++](zig-zag-sequence.cpp) [Python](zig-zag-sequence.py)|Medium | ||
|
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,84 @@ | ||
// Algorithms > Debugging > Prime Dates | ||
// Find the number of prime dates in a range | ||
// | ||
// https://www.hackerrank.com/challenges/prime-date/problem | ||
// challenge id: 63495 | ||
// | ||
|
||
#include <bits/stdc++.h> | ||
using namespace std; | ||
|
||
int month[15]; | ||
|
||
void updateLeapYear(int year) { | ||
if(year % 400 == 0) { | ||
month[2] = 29; | ||
} else if(year % 100 == 0) { | ||
month[2] = 28; | ||
} else if(year % 4 == 0) { | ||
month[2] = 29; | ||
} else { | ||
month[2] = 28; | ||
} | ||
} | ||
|
||
void storeMonth() { | ||
month[1] = 31; | ||
month[2] = 28; | ||
month[3] = 31; | ||
month[4] = 30; | ||
month[5] = 31; | ||
month[6] = 30; | ||
month[7] = 31; | ||
month[8] = 31; | ||
month[9] = 30; | ||
month[10] = 31; | ||
month[11] = 30; | ||
month[12] = 31; | ||
} | ||
|
||
int findLuckyDates(int d1, int m1, int y1, int d2, int m2, int y2) { | ||
storeMonth(); | ||
|
||
int result = 0; | ||
|
||
while(true) { | ||
int x = d1; | ||
x = x * 100 + m1; | ||
x = x * 10000 + y1; | ||
if(x % 4 == 0 || x % 7 == 0) { | ||
result = result + 1; | ||
} | ||
if(d1 == d2 && m1 == m2 && y1 == y2) { | ||
break; | ||
} | ||
updateLeapYear(y1); | ||
d1 = d1 + 1; | ||
if(d1 > month[m1]) { | ||
m1 = m1 + 1; | ||
d1 = 1; | ||
if(m1 > 12) { | ||
y1 = y1 + 1; | ||
m1 = 1; | ||
} | ||
} | ||
} | ||
return result; | ||
} | ||
|
||
int main() { | ||
string str; | ||
int d1, m1, y1, d2, m2, y2; | ||
getline(cin, str); | ||
for(int i = 0; i < str.size(); i++) { | ||
if(str[i] == '-') { | ||
str[i] = ' '; | ||
} | ||
} | ||
stringstream ss; | ||
ss << str; | ||
ss >> d1 >> m1 >> y1 >> d2 >> m2 >> y2; | ||
|
||
int result = findLuckyDates(d1, m1, y1, d2, m2, y2); | ||
cout << result << endl; | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,70 @@ | ||
# Algorithms > Debugging > Prime Dates | ||
# Find the number of prime dates in a range | ||
# | ||
# https://www.hackerrank.com/challenges/prime-date/problem | ||
# challenge id: 63495 | ||
# | ||
|
||
import re | ||
month = [] | ||
|
||
def updateLeapYear(year): | ||
if year % 400 == 0: | ||
month[2] = 29 | ||
elif year % 100 == 0: | ||
month[2] = 28 | ||
elif year % 4 == 0: | ||
month[2] = 29 | ||
else: | ||
month[2] = 28 | ||
|
||
def storeMonth(): | ||
month[1] = 31 | ||
month[2] = 28 | ||
month[3] = 31 | ||
month[4] = 30 | ||
month[5] = 31 | ||
month[6] = 30 | ||
month[7] = 31 | ||
month[8] = 31 | ||
month[9] = 30 | ||
month[10] = 31 | ||
month[11] = 30 | ||
month[12] = 31 | ||
|
||
def findPrimeDates(d1, m1, y1, d2, m2, y2): | ||
storeMonth() | ||
result = 0 | ||
|
||
while(True): | ||
x = d1 | ||
x = x * 100 + m1 | ||
x = x * 10000 + y1 | ||
if x % 4 == 0 or x % 7 == 0: | ||
result = result + 1 | ||
if d1 == d2 and m1 == m2 and y1 == y2: | ||
break | ||
updateLeapYear(y1) | ||
d1 = d1 + 1 | ||
if d1 > month[m1]: | ||
m1 = m1 + 1 | ||
d1 = 1 | ||
if m1 > 12: | ||
y1 = y1 + 1 | ||
m1 = 1 | ||
return result; | ||
|
||
for i in range(1, 15): | ||
month.append(31) | ||
|
||
line = input() | ||
date = re.split('-| ', line) | ||
d1 = int(date[0]) | ||
m1 = int(date[1]) | ||
y1 = int(date[2]) | ||
d2 = int(date[3]) | ||
m2 = int(date[4]) | ||
y2 = int(date[5]) | ||
|
||
result = findPrimeDates(d1, m1, y1, d2, m2, y2) | ||
print(result) |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,44 @@ | ||
// Algorithms > Debugging > Zig Zag Sequence | ||
// Find a zig zag sequence of the given array. | ||
// | ||
// https://www.hackerrank.com/challenges/zig-zag-sequence/problem | ||
// challenge id: 63282 | ||
// | ||
|
||
#include <bits/stdc++.h> | ||
using namespace std; | ||
|
||
void findZigZagSequence(vector < int > a, int n){ | ||
sort(a.begin(), a.end()); | ||
int mid = (n - 1)/2; | ||
swap(a[mid], a[n-1]); | ||
|
||
int st = mid + 1; | ||
int ed = n - 2; | ||
while(st <= ed){ | ||
swap(a[st], a[ed]); | ||
st = st + 1; | ||
ed = ed - 1; | ||
} | ||
for(int i = 0; i < n; i++){ | ||
if(i > 0) cout << " "; | ||
cout << a[i]; | ||
} | ||
cout << endl; | ||
} | ||
|
||
int main() { | ||
int n, x; | ||
int test_cases; | ||
cin >> test_cases; | ||
|
||
for(int cs = 1; cs <= test_cases; cs++){ | ||
cin >> n; | ||
vector < int > a; | ||
for(int i = 0; i < n; i++){ | ||
cin >> x; | ||
a.push_back(x); | ||
} | ||
findZigZagSequence(a, n); | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,31 @@ | ||
# Algorithms > Debugging > Zig Zag Sequence | ||
# Find a zig zag sequence of the given array. | ||
# | ||
# https://www.hackerrank.com/challenges/zig-zag-sequence/problem | ||
# challenge id: 63282 | ||
# | ||
|
||
def findZigZagSequence(a, n): | ||
a.sort() | ||
mid = int((n - 1)/2) | ||
a[mid], a[n-1] = a[n-1], a[mid] | ||
|
||
st = mid + 1 | ||
ed = n - 2 | ||
while(st <= ed): | ||
a[st], a[ed] = a[ed], a[st] | ||
st = st + 1 | ||
ed = ed - 1 | ||
|
||
for i in range (n): | ||
if i == n-1: | ||
print(a[i]) | ||
else: | ||
print(a[i], end = ' ') | ||
return | ||
|
||
test_cases = int(input()) | ||
for cs in range (test_cases): | ||
n = int(input()) | ||
a = list(map(int, input().split())) | ||
findZigZagSequence(a, n) |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,13 @@ | ||
# Mathematics > Algebra > Sherlock and Square | ||
# Help Sherlock in finding the total side lengths of squares. | ||
# | ||
# https://www.hackerrank.com/challenges/sherlock-and-square/problem | ||
# https://www.hackerrank.com/contests/w11/challenges/sherlock-and-square | ||
# challenge id: 4429 | ||
# | ||
|
||
MOD = 1000000007 | ||
|
||
for _ in range(int(input())): | ||
n = int(input()) | ||
print((pow(2, n + 1, MOD) + 2) % MOD) |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.