Skip to content

Commit

Permalink
Add problem solving (basic)
Browse files Browse the repository at this point in the history
  • Loading branch information
kilian-hu committed Sep 15, 2021
1 parent 0215d7e commit 707eb07
Show file tree
Hide file tree
Showing 218 changed files with 24,254 additions and 0 deletions.
37 changes: 37 additions & 0 deletions certificates/README.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,37 @@
# Certificates

To get a certificate, two problems have to be solved within 90 minutes.

The following is an incomplete list of possible problems per certificate as of 2021.09.15:

- [Problem Solving (Basic)](problem-solving-basic)
- [Active Traders](problem-solving-basic/active-traders)
- [Balanced System Files Partition](problem-solving-basic/balanced-system-files-partition)
- [Longest Subarray](problem-solving-basic/longest-subarray)
- [Maximum Cost of Laptop Count](problem-solving-basic/maximum-cost-of-laptop-count)
- [Nearly Similar Rectangles](problem-solving-basic/nearly-similar-rectangles)
- [Parallel Processing](problem-solving-basic/parallel-processing)
- [Password Decryption](problem-solving-basic/password-decryption)
- [Road Repair](problem-solving-basic/road-repair)
- [String Anagram](problem-solving-basic/string-anagram)
- [Subarray Sums](problem-solving-basic/subarray-sums)
- [Unexpected Demand](problem-solving-basic/unexpected-demand)
- [Usernames Changes](problem-solving-basic/usernames-changes)
- [Vowel Substring](problem-solving-basic/vowel-substring)
- [Problem Solving (Intermediate)](problem-solving-intermediate)
- [Bitwise AND](problem-solving-intermediate/bitwise-and)
- [Equalizing Array Elements](problem-solving-intermediate/equalizing-array-elements)
- [File Renaming](problem-solving-intermediate/file-renaming)
- [Hotel Construction](problem-solving-intermediate/hotel-construction)
- [Largest Area](problem-solving-intermediate/largest-area)
- [Maximum Subarray Value](problem-solving-intermediate/maximum-subarray-value)
- [Nice Teams](problem-solving-intermediate/nice-teams)
- [Sorted Sums](problem-solving-intermediate/sorted-sums)
- [Task of Pairing](problem-solving-intermediate/task-of-pairing)
- [User-Friendly Password System](problem-solving-intermediate/user-friendly-password-system)

Besides the solutions, there are Python 3 and C++ code stubs and some test cases so you can first try to solve the problems without time pressure if you want to. Keep in mind that most of this is uncommented code that just gets the job done. Nothing more.

# TODO
- Find more efficient solution for [Maximum Subarray Value](problem-solving-intermediate/maximum-subarray-value). It's getting timeouts for a few test cases.
- Verify correctness of [Nice Teams](problem-solving-intermediate/nice-teams).
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
![problem](problem.png)
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
40 changes: 40 additions & 0 deletions certificates/problem-solving-basic/active-traders/solution.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,40 @@
#!/bin/python3

import math
import os
import random
import re
import sys

from collections import defaultdict

#
# Complete the 'mostActive' function below.
#
# The function is expected to return a STRING_ARRAY.
# The function accepts STRING_ARRAY customers as parameter.
#

def mostActive(customers):
d = defaultdict(int)
for c in customers:
d[c] += 1
return sorted([c for c, cnt in d.items() if cnt / len(customers) >= 0.05])

if __name__ == '__main__':
fptr = open(os.environ['OUTPUT_PATH'], 'w')

customers_count = int(input().strip())

customers = []

for _ in range(customers_count):
customers_item = input()
customers.append(customers_item)

result = mostActive(customers)

fptr.write('\n'.join(result))
fptr.write('\n')

fptr.close()
76 changes: 76 additions & 0 deletions certificates/problem-solving-basic/active-traders/stub.cc
Original file line number Diff line number Diff line change
@@ -0,0 +1,76 @@
#include <bits/stdc++.h>

using namespace std;

string ltrim(const string &);
string rtrim(const string &);



/*
* Complete the 'mostActive' function below.
*
* The function is expected to return a STRING_ARRAY.
* The function accepts STRING_ARRAY customers as parameter.
*/

vector<string> mostActive(vector<string> customers) {

}

int main()
{
ofstream fout(getenv("OUTPUT_PATH"));

string customers_count_temp;
getline(cin, customers_count_temp);

int customers_count = stoi(ltrim(rtrim(customers_count_temp)));

vector<string> customers(customers_count);

for (int i = 0; i < customers_count; i++) {
string customers_item;
getline(cin, customers_item);

customers[i] = customers_item;
}

vector<string> result = mostActive(customers);

for (int i = 0; i < result.size(); i++) {
fout << result[i];

if (i != result.size() - 1) {
fout << "\n";
}
}

fout << "\n";

fout.close();

return 0;
}

string ltrim(const string &str) {
string s(str);

s.erase(
s.begin(),
find_if(s.begin(), s.end(), not1(ptr_fun<int, int>(isspace)))
);

return s;
}

string rtrim(const string &str) {
string s(str);

s.erase(
find_if(s.rbegin(), s.rend(), not1(ptr_fun<int, int>(isspace))).base(),
s.end()
);

return s;
}
38 changes: 38 additions & 0 deletions certificates/problem-solving-basic/active-traders/stub.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,38 @@
#!/bin/python3

import math
import os
import random
import re
import sys



#
# Complete the 'mostActive' function below.
#
# The function is expected to return a STRING_ARRAY.
# The function accepts STRING_ARRAY customers as parameter.
#

def mostActive(customers):
# Write your code here
pass

if __name__ == '__main__':
fptr = open(os.environ['OUTPUT_PATH'], 'w')

customers_count = int(input().strip())

customers = []

for _ in range(customers_count):
customers_item = input()
customers.append(customers_item)

result = mostActive(customers)

fptr.write('\n'.join(result))
fptr.write('\n')

fptr.close()
Original file line number Diff line number Diff line change
@@ -0,0 +1,21 @@
20
Omega
Alpha
Omega
Alpha
Omega
Alpha
Omega
Alpha
Omega
Alpha
Omega
Alpha
Omega
Alpha
Omega
Alpha
Omega
Alpha
Omega
Beta
Original file line number Diff line number Diff line change
@@ -0,0 +1,22 @@
21
Alpha
Beta
Zeta
Beta
Zeta
Zeta
Epsilon
Beta
Zeta
Beta
Zeta
Beta
Delta
Zeta
Beta
Zeta
Beta
Zeta
Beta
Zeta
Beta
Original file line number Diff line number Diff line change
@@ -0,0 +1,25 @@
24
Dog
Goes
Woof
Cat
Goes
Meow
Bird
Goes
Tweet
And
Mouse
Goes
Squeek
Cow
Goes
Moo
Frog
Goes
Croak
And
The
Elephant
Goes
Toot
Original file line number Diff line number Diff line change
@@ -0,0 +1,21 @@
20
Bey
Ddtlcouegmdbyfwu
Ppuvhifnuap
Ppuvhifnuap
Ppuvhifnuap
Ppuvhifnuap
Ddtlcouegmdbyfwu
Ddtlcouegmdbyfwu
Ppuvhifnuap
Ppuvhifnuap
Ppuvhifnuap
Ppuvhifnuap
Ddtlcouegmdbyfwu
Ppuvhifnuap
Ddtlcouegmdbyfwu
Ppuvhifnuap
Ppuvhifnuap
Ppuvhifnuap
Ppuvhifnuap
Ppuvhifnuap
Original file line number Diff line number Diff line change
@@ -0,0 +1,21 @@
20
Bfeo
Xjgwxtrxi
Pnnpmud
Pnnpmud
Xjgwxtrxi
Wdswxxrx
Wdswxxrx
Xjgwxtrxi
Wdswxxrx
Xjgwxtrxi
Pnnpmud
Wdswxxrx
Xjgwxtrxi
Wdswxxrx
Xjgwxtrxi
Xjgwxtrxi
Wdswxxrx
Wdswxxrx
Xjgwxtrxi
Xjgwxtrxi
Original file line number Diff line number Diff line change
@@ -0,0 +1,21 @@
20
Ampprswkdkobdagw
Wcfa
Zooot
Zn
Zooot
Wufeesrvn
Zn
Xillkfdvpfpxabqlngd
Zn
Zn
Qvwdrm
Zn
Zooot
Qvwdrm
Zooot
Zn
Zn
Zooot
Xillkfdvpfpxabqlngd
Rskcw
Original file line number Diff line number Diff line change
@@ -0,0 +1,21 @@
20
Exouyfjhnwp
Van
Tanwwyoosxtnex
Omkfnkswrawkjxw
Zskzazjqtlkiqydpt
Omkfnkswrawkjxw
Van
Sndpvannrywfrnrghlj
Tanwwyoosxtnex
Van
Qpxnlkcwdpdksw
Qpxnlkcwdpdksw
Tanwwyoosxtnex
Zskzazjqtlkiqydpt
Sndpvannrywfrnrghlj
Zskzazjqtlkiqydpt
Tanwwyoosxtnex
Sndpvannrywfrnrghlj
Van
Zskzazjqtlkiqydpt
Original file line number Diff line number Diff line change
@@ -0,0 +1,21 @@
20
Ami
Wuxavlwftgyxxhpygs
Wk
Vwfnbngh
Wmzheqx
Wuxavlwftgyxxhpygs
Oxhaiafmvkb
Wk
Wuxavlwftgyxxhpygs
Wmzheqx
Vwfnbngh
Vwfnbngh
Wmzheqx
Ocni
Xjmornquma
Wmzheqx
Xjmornquma
Ltpwmhqw
Wk
Ocni
Loading

0 comments on commit 707eb07

Please sign in to comment.