- Tax payer (at least for now)
- Grass planter
- Home cook
coding-test-study's Introduction
coding-test-study's People
coding-test-study's Issues
hackerrank/counting-valleys
#!/bin/python3
import math
import os
import random
import re
import sys
#
# Complete the 'countingValleys' function below.
#
# The function is expected to return an INTEGER.
# The function accepts following parameters:
# 1. INTEGER steps
# 2. STRING path
#
def countingValleys(steps, path):
# Write your code here
level = 0
count = 0
for c in path:
if c == "U":
level += 1
else:
level -= 1
if level == -1 and c == "D":
count += 0.5
elif level == 0 and c == "U":
count += 0.5
return int(count)
if __name__ == '__main__':
fptr = open(os.environ['OUTPUT_PATH'], 'w')
steps = int(input().strip())
path = input()
result = countingValleys(steps, path)
fptr.write(str(result) + '\n')
fptr.close()
hackerrank/arrays-left-rotation
#include <bits/stdc++.h>
using namespace std;
vector<string> split_string(string);
// Complete the rotLeft function below.
vector<int> rotLeft(vector<int> a, int d) {
int effectiveRotLeft = d % a.size();
vector<int> answer;
for (int i = effectiveRotLeft; i < a.size(); i++) {
answer.push_back(a[i]);
}
for (int i = 0; i < effectiveRotLeft; i++) {
answer.push_back(a[i]);
}
return answer;
}
int main()
{
ofstream fout(getenv("OUTPUT_PATH"));
string nd_temp;
getline(cin, nd_temp);
vector<string> nd = split_string(nd_temp);
int n = stoi(nd[0]);
int d = stoi(nd[1]);
string a_temp_temp;
getline(cin, a_temp_temp);
vector<string> a_temp = split_string(a_temp_temp);
vector<int> a(n);
for (int i = 0; i < n; i++) {
int a_item = stoi(a_temp[i]);
a[i] = a_item;
}
vector<int> result = rotLeft(a, d);
for (int i = 0; i < result.size(); i++) {
fout << result[i];
if (i != result.size() - 1) {
fout << " ";
}
}
fout << "\n";
fout.close();
return 0;
}
vector<string> split_string(string input_string) {
string::iterator new_end = unique(input_string.begin(), input_string.end(), [] (const char &x, const char &y) {
return x == y and x == ' ';
});
input_string.erase(new_end, input_string.end());
while (input_string[input_string.length() - 1] == ' ') {
input_string.pop_back();
}
vector<string> splits;
char delimiter = ' ';
size_t i = 0;
size_t pos = input_string.find(delimiter);
while (pos != string::npos) {
splits.push_back(input_string.substr(i, pos - i));
i = pos + 1;
pos = input_string.find(delimiter, i);
}
splits.push_back(input_string.substr(i, min(pos, input_string.length()) - i + 1));
return splits;
}
hackerrank/sales-by-match
#!/bin/python3
import math
import os
import random
import re
import sys
# Complete the sockMerchant function below.
def sockMerchant(n, ar):
count = 0
hash_table = set()
for a in ar:
if a not in hash_table:
hash_table.add(a)
elif a in hash_table:
hash_table.remove(a)
count += 1
return count
if __name__ == '__main__':
fptr = open(os.environ['OUTPUT_PATH'], 'w')
n = int(input())
ar = list(map(int, input().rstrip().split()))
result = sockMerchant(n, ar)
fptr.write(str(result) + '\n')
fptr.close()
hackerrank/jumping-on-the-clouds
#!/bin/python3
import math
import os
import random
import re
import sys
# Complete the jumpingOnClouds function below.
def jumpingOnClouds(c):
jumps = 0
i = 0
while i < len(c) - 1:
if i + 2 < len(c) and c[i + 2] == 0:
i += 2
else:
i += 1
jumps += 1
return jumps
if __name__ == '__main__':
fptr = open(os.environ['OUTPUT_PATH'], 'w')
n = int(input())
c = list(map(int, input().rstrip().split()))
result = jumpingOnClouds(c)
fptr.write(str(result) + '\n')
fptr.close()
hackerrank/repeated-string
#!/bin/python3
import math
import os
import random
import re
import sys
# Complete the repeatedString function below.
def repeatedString(s, n):
base = n // len(s)
modulo = n % len(s)
count_base = 0
for c in s:
if c == "a":
count_base += 1
count_modulo = 0
for c in s[:modulo]:
if c == "a":
count_modulo += 1
return count_base * base + count_modulo
if __name__ == '__main__':
fptr = open(os.environ['OUTPUT_PATH'], 'w')
s = input()
n = int(input())
result = repeatedString(s, n)
fptr.write(str(result) + '\n')
fptr.close()
hackerrank/2d-array-ds
#include <bits/stdc++.h>
using namespace std;
// Complete the hourglassSum function below.
int hourglassSum(vector<vector<int>> arr) {
int max_sum = -9999;
int challenger = 0;
for (int i = 0; i < 4; i++) {
for (int j = 0; j < 4; j++) {
challenger = arr[i][j] + arr[i][j + 1] + arr[i][j + 2] + arr[i + 1][j + 1] + arr[i + 2][j] + arr[i + 2][j + 1] + arr[i + 2][j + 2];
max_sum = challenger <= max_sum? max_sum: challenger;
}
}
return max_sum;
}
int main()
{
ofstream fout(getenv("OUTPUT_PATH"));
vector<vector<int>> arr(6);
for (int i = 0; i < 6; i++) {
arr[i].resize(6);
for (int j = 0; j < 6; j++) {
cin >> arr[i][j];
}
cin.ignore(numeric_limits<streamsize>::max(), '\n');
}
int result = hourglassSum(arr);
fout << result << "\n";
fout.close();
return 0;
}
Recommend Projects
-
React
A declarative, efficient, and flexible JavaScript library for building user interfaces.
-
Vue.js
๐ Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.
-
Typescript
TypeScript is a superset of JavaScript that compiles to clean JavaScript output.
-
TensorFlow
An Open Source Machine Learning Framework for Everyone
-
Django
The Web framework for perfectionists with deadlines.
-
Laravel
A PHP framework for web artisans
-
D3
Bring data to life with SVG, Canvas and HTML. ๐๐๐
-
Recommend Topics
-
javascript
JavaScript (JS) is a lightweight interpreted programming language with first-class functions.
-
web
Some thing interesting about web. New door for the world.
-
server
A server is a program made to process requests and deliver data to clients.
-
Machine learning
Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.
-
Visualization
Some thing interesting about visualization, use data art
-
Game
Some thing interesting about game, make everyone happy.
Recommend Org
-
Facebook
We are working to build community through open source technology. NB: members must have two-factor auth.
-
Microsoft
Open source projects and samples from Microsoft.
-
Google
Google โค๏ธ Open Source for everyone.
-
Alibaba
Alibaba Open Source for everyone
-
D3
Data-Driven Documents codes.
-
Tencent
China tencent open source team.