├── Results └── Europe.png ├── .github ├── Global Coding Challenge_ex_1.pdf ├── Global Coding Challenge_ex_2.pdf ├── Global Coding Challenge_ex_3.pdf ├── Global Coding Challenge_ex_4.pdf ├── Global Coding Challenge_ex_5.pdf ├── Global Coding Challenge_ex_6.pdf ├── Global Coding Challenge_ex_7.pdf ├── Global Coding Challenge_ex_8.pdf └── Global Coding Challenge_ex_9.pdf ├── Question1 ├── Python │ └── Question1.py ├── Readme.md └── CPP │ └── Question1.cpp ├── Question2 ├── Python │ └── Question2.py ├── Readme.md ├── Java │ └── Question2.java └── CPP │ └── Question2.cpp ├── Question8 ├── Python │ └── Question8.py ├── Readme.md ├── Java │ └── Question8.java └── CPP │ └── Question8.cpp ├── Question6 ├── Python │ └── Question6.py ├── Readme.md ├── CPP │ └── Question6.cpp └── Java │ └── Question6.java ├── LICENSE ├── Question9 ├── Python │ └── Question9.py ├── CPP │ └── Question9.cpp └── Readme.md ├── Question4 ├── Python │ └── Question4.py ├── CPP │ └── Question4.cpp ├── Readme.md └── Java │ └── Question4.java ├── Question3 ├── CPP │ └── Question3.cpp └── Readme.md ├── Question7 ├── Readme.md ├── Python │ └── Question7.py ├── Java │ └── Question7.java └── CPP │ └── Question7.cpp ├── Question5 ├── Readme.md └── CPP │ └── Question5.cpp ├── README.md └── .gitignore /Results/Europe.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/ZdrzalikPrzemyslaw/2020-Credit-Suisse-Global-Coding-Challenge/HEAD/Results/Europe.png -------------------------------------------------------------------------------- /.github/Global Coding Challenge_ex_1.pdf: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/ZdrzalikPrzemyslaw/2020-Credit-Suisse-Global-Coding-Challenge/HEAD/.github/Global Coding Challenge_ex_1.pdf -------------------------------------------------------------------------------- /.github/Global Coding Challenge_ex_2.pdf: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/ZdrzalikPrzemyslaw/2020-Credit-Suisse-Global-Coding-Challenge/HEAD/.github/Global Coding Challenge_ex_2.pdf -------------------------------------------------------------------------------- /.github/Global Coding Challenge_ex_3.pdf: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/ZdrzalikPrzemyslaw/2020-Credit-Suisse-Global-Coding-Challenge/HEAD/.github/Global Coding Challenge_ex_3.pdf -------------------------------------------------------------------------------- /.github/Global Coding Challenge_ex_4.pdf: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/ZdrzalikPrzemyslaw/2020-Credit-Suisse-Global-Coding-Challenge/HEAD/.github/Global Coding Challenge_ex_4.pdf -------------------------------------------------------------------------------- /.github/Global Coding Challenge_ex_5.pdf: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/ZdrzalikPrzemyslaw/2020-Credit-Suisse-Global-Coding-Challenge/HEAD/.github/Global Coding Challenge_ex_5.pdf -------------------------------------------------------------------------------- /.github/Global Coding Challenge_ex_6.pdf: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/ZdrzalikPrzemyslaw/2020-Credit-Suisse-Global-Coding-Challenge/HEAD/.github/Global Coding Challenge_ex_6.pdf -------------------------------------------------------------------------------- /.github/Global Coding Challenge_ex_7.pdf: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/ZdrzalikPrzemyslaw/2020-Credit-Suisse-Global-Coding-Challenge/HEAD/.github/Global Coding Challenge_ex_7.pdf -------------------------------------------------------------------------------- /.github/Global Coding Challenge_ex_8.pdf: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/ZdrzalikPrzemyslaw/2020-Credit-Suisse-Global-Coding-Challenge/HEAD/.github/Global Coding Challenge_ex_8.pdf -------------------------------------------------------------------------------- /.github/Global Coding Challenge_ex_9.pdf: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/ZdrzalikPrzemyslaw/2020-Credit-Suisse-Global-Coding-Challenge/HEAD/.github/Global Coding Challenge_ex_9.pdf -------------------------------------------------------------------------------- /Question1/Python/Question1.py: -------------------------------------------------------------------------------- 1 | # You may change this function parameters 2 | def findMaxProfit(predictedSharePrices): 3 | # Participants code will be here 4 | maks = predictedSharePrices[1] - predictedSharePrices[0] 5 | minimum = predictedSharePrices[0] 6 | 7 | for i in predictedSharePrices: 8 | if i < minimum: 9 | minimum = i 10 | elif i - minimum > maks: 11 | maks = i - minimum 12 | 13 | 14 | return maks 15 | 16 | 17 | def main(): 18 | line = input().split() 19 | numOfPredictedDay = int(line[0]) 20 | predictedSharePrices = list(map(int, line[1:])) 21 | 22 | answer = findMaxProfit(predictedSharePrices) 23 | 24 | # Please do not remove the below line. 25 | print(answer) 26 | # Do not print anything after this line 27 | 28 | 29 | if __name__ == '__main__': 30 | main() 31 | -------------------------------------------------------------------------------- /Question2/Python/Question2.py: -------------------------------------------------------------------------------- 1 | # You may change this function parameters 2 | def findMaxProfit(numOfPredictedTimes, predictedSharePrices): 3 | dictionary = {i: j for i, j in enumerate(predictedSharePrices)} 4 | suma = 0 5 | i = 0 6 | while i < numOfPredictedTimes: 7 | j = i 8 | while j + 1 < numOfPredictedTimes and dictionary[j + 1] > dictionary[j]: 9 | j += 1 10 | suma += dictionary[j] - dictionary[i] 11 | i = j + 1 12 | return suma 13 | 14 | 15 | def main(): 16 | line = input().split() 17 | numOfPredictedTimes = int(line[0]) 18 | predictedSharePrices = list(map(int, line[1:])) 19 | 20 | answer = findMaxProfit(numOfPredictedTimes, predictedSharePrices) 21 | # Do not remove below line 22 | print(answer) 23 | # Do not print anything after this line 24 | 25 | 26 | if __name__ == '__main__': 27 | main() 28 | -------------------------------------------------------------------------------- /Question8/Python/Question8.py: -------------------------------------------------------------------------------- 1 | # Participants may update the following function parameters 2 | def countNumberOfWays(numOfUnits, coins): 3 | history = [0] * (numOfUnits + 1) 4 | history[0] = 1 5 | for coin in range(len(coins)): 6 | for j in range(coins[coin], numOfUnits + 1): 7 | history[j] += history[j - coins[coin]] 8 | return history[numOfUnits] 9 | 10 | 11 | def main(): 12 | firstLine = input().split(" ") 13 | secondLine = input().split(" ") 14 | 15 | numOfUnits = int(firstLine[0]) 16 | numOfCoinTypes = int(firstLine[1]) 17 | coins = list(map(int, secondLine)) 18 | 19 | # Participants may update the following function parameters 20 | answer = countNumberOfWays(numOfUnits, coins) 21 | 22 | # Please do not remove the below line. 23 | print(answer) 24 | # Do not print anything after this line 25 | 26 | 27 | if __name__ == '__main__': 28 | main() 29 | -------------------------------------------------------------------------------- /Question6/Python/Question6.py: -------------------------------------------------------------------------------- 1 | import math 2 | 3 | 4 | # You may change this function parameters 5 | def encrypt(words): 6 | words.replace(" ", "") 7 | sqrt = math.sqrt(len(words)) 8 | rows = int(math.floor(sqrt)) 9 | cols = int(math.ceil(sqrt)) 10 | if rows * cols < len(words): 11 | rows += 1 12 | return_string = [] 13 | for i in range(0, rows * cols): 14 | val = ((i % rows) * cols) + (int(i / rows)) 15 | if val < len(words): 16 | return_string.append(words[val]) 17 | if (i + 1) % rows == 0: 18 | return_string.append(" ") 19 | 20 | # Participants code will be here 21 | return "".join(return_string) 22 | 23 | 24 | def main(): 25 | words = input() 26 | 27 | answer = encrypt(words) 28 | 29 | # Please do not remove the below line. 30 | print(answer) 31 | # Do not print anything after this line 32 | 33 | 34 | if __name__ == '__main__': 35 | main() 36 | -------------------------------------------------------------------------------- /Question6/Readme.md: -------------------------------------------------------------------------------- 1 | # [Question 6 - Encrypting Messages](https://github.com/ZdrzalikPrzemyslaw/2020-Credit-Suisse-Global-Coding-Challenge/blob/master/.github/Global%20Coding%20Challenge_ex_6.pdf) 2 | 3 | - Data encryption prevents data visibility in the event of its unauthorized access. 4 | - Consider the following encryption algorithm to encipher a given string input. Firstly, discard all 5 | spaces of the string. Then store all the characters within a matrix, according to the constraints 6 | below, to get the encoded string output. 7 | 8 | 9 | ## Constraints 10 | 11 | - floor(squareRoot(stringLength)) <= matrixRows <= matrixColumns <= 12 | ceil(squareRoot(stringLength)) 13 | - matrixRows x matrixColumns >= stringLength 14 | - Choose the matrix with the smallest area. 15 | - Print out the characters of the first column, then embed a space before printing out the 16 | following column, etc. 17 | 18 | ## Input format 19 | 20 | - A string 21 | 22 | ## Output format 23 | 24 | - An encrypted string -------------------------------------------------------------------------------- /Question1/Readme.md: -------------------------------------------------------------------------------- 1 | # [Question 1 - Profit Maximization](https://github.com/ZdrzalikPrzemyslaw/2020-Credit-Suisse-Global-Coding-Challenge/blob/master/.github/Global%20Coding%20Challenge_ex_1.pdf) 2 | 3 | Emilia, a quantitative researcher, predicts how the closing share price of a stock moves over time. 4 | She wants to find the maximum possible profit of a stock over a given period of time, using 5 | only one buy and one sell operation according to a given sequence of predicted share prices. 6 | 7 | ## Constraints 8 | 9 | - Short selling is not allowed. 10 | - All of the predicted share prices are positive integers. 11 | 12 | ## Input format 13 | 14 | - The first integer input is the number of predicted days. 15 | - The subsequent integer input is a sequence of positive integers. The element at position i refers to 16 | the predicted share price of a given stock on the ith day. 17 | 18 | ## Output format 19 | 20 | - An integer which is the maximum possible profit with only one buy and one sell operation 21 | -------------------------------------------------------------------------------- /Question6/CPP/Question6.cpp: -------------------------------------------------------------------------------- 1 | #include 2 | 3 | using namespace std; 4 | 5 | string encrypt(string words) 6 | { 7 | words.erase(std::remove(words.begin(), words.end(), ' '), words.end()); 8 | double esquerte = sqrt(words.length()); 9 | int rows = floor(esquerte); 10 | int cols = ceil(esquerte); 11 | if (rows * cols < words.length()) 12 | rows++; 13 | string return_string = ""; 14 | 15 | for (int i = 0; i < rows * cols; i++) 16 | { 17 | int iprzecols = i / rows; 18 | int val = (i % rows) * cols + iprzecols; 19 | if (val < words.length()) 20 | return_string += words[val]; 21 | if ((i + 1) % rows == 0) 22 | return_string += " "; 23 | } 24 | 25 | return return_string; 26 | } 27 | 28 | int main() 29 | { 30 | string words; 31 | getline(cin, words); 32 | 33 | string result = encrypt(words); 34 | 35 | // Do not remove below line 36 | cout << result << "\n"; 37 | // Do not print anything after this line 38 | 39 | return 0; 40 | } -------------------------------------------------------------------------------- /LICENSE: -------------------------------------------------------------------------------- 1 | MIT License 2 | 3 | Copyright (c) 2020 Zdrzalik Przemyslaw 4 | 5 | Permission is hereby granted, free of charge, to any person obtaining a copy 6 | of this software and associated documentation files (the "Software"), to deal 7 | in the Software without restriction, including without limitation the rights 8 | to use, copy, modify, merge, publish, distribute, sublicense, and/or sell 9 | copies of the Software, and to permit persons to whom the Software is 10 | furnished to do so, subject to the following conditions: 11 | 12 | The above copyright notice and this permission notice shall be included in all 13 | copies or substantial portions of the Software. 14 | 15 | THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR 16 | IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, 17 | FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE 18 | AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER 19 | LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, 20 | OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE 21 | SOFTWARE. 22 | -------------------------------------------------------------------------------- /Question9/Python/Question9.py: -------------------------------------------------------------------------------- 1 | def organizingContainers(kontener): 2 | size_box = [0] * len(kontener) 3 | transaction_count_type = [0] * len(kontener) 4 | 5 | for i, kont_out in enumerate(kontener): 6 | for j, kont_in in enumerate(kont_out): 7 | size_box[j] += kont_in 8 | transaction_count_type[i] += kont_in 9 | 10 | sorted(size_box) 11 | sorted(transaction_count_type) 12 | for i, j in zip(size_box, transaction_count_type): 13 | if i != j: 14 | return "Impossible" 15 | return "Possible" 16 | 17 | 18 | if __name__ == "__main__": 19 | q = int(input().strip()) 20 | answer = "" 21 | for a0 in range(q): 22 | n = int(input().strip()) 23 | container = [] 24 | for container_i in range(n): 25 | container_t = [int(container_temp) for container_temp in input().strip().split(' ')] 26 | container.append(container_t) 27 | result = organizingContainers(container) 28 | if (answer == ""): 29 | answer = str(result) 30 | else: 31 | answer = answer + "," + str(result) 32 | # Do not remove below line 33 | print(answer) 34 | # Do not print anything after this line 35 | -------------------------------------------------------------------------------- /Question2/Readme.md: -------------------------------------------------------------------------------- 1 | # [Question 2 - Profit Maximization - Extended](https://github.com/ZdrzalikPrzemyslaw/2020-Credit-Suisse-Global-Coding-Challenge/blob/master/.github/Global%20Coding%20Challenge_ex_2.pdf) 2 | 3 | Emilia can now use multiple buy and sell operations over a given period of time. 4 | Given a sequence of predicted share prices, she wants to find the maximum possible profit while 5 | using the smallest number of trading operations throughout the given time. 6 | 7 | 8 | ## Constraints 9 | 10 | - Short selling is not allowed. 11 | - All of the predicted share prices are positive integers. 12 | - You can only execute one buy or one sell operation of a share on a given day. 13 | - Only one share can be bought or sold at a time. 14 | - You are not required to execute a buy or sell operation every day. 15 | 16 | 17 | ## Input format 18 | 19 | - The first integer input is the number of predicted days. 20 | - The subsequent integer input is a sequence of positive integers. The element at position i refers to 21 | the predicted share price of a given stock on the ith day. 22 | 23 | 24 | ## Output format 25 | 26 | - An integer that is the maximum profit using the smallest number of trading operations throughout 27 | the given time. 28 | 29 | -------------------------------------------------------------------------------- /Question8/Readme.md: -------------------------------------------------------------------------------- 1 | # [Question 8 -Counting Change](https://github.com/ZdrzalikPrzemyslaw/2020-Credit-Suisse-Global-Coding-Challenge/blob/master/.github/Global%20Coding%20Challenge_ex_8.pdf) 2 | 3 | - James has recently started working in a currency exchange office at the airport. As many people 4 | are buying different types of currencies before they go on holiday, he ends up working with various 5 | types of coins. James would like to find all possible ways of making change for a desired amount 6 | using different coins. 7 | - For example, if James has 3 different types of coins, and the value of each is given as 15, 31 and 8 | 9, an amount of 63 can be made in two ways: {9, 9, 15, 15, 15} and {9, 9, 9, 9, 9, 9, 9}. 9 | - Create a countNumberOfWays function which returns an integer denoting the number of possible 10 | ways to give change. 11 | 12 | ## Input format 13 | 14 | - The first line: 15 | - n: an integer, is the desired amount. 16 | - m: an integer, is the number of different coin types. 17 | - The second line: 18 | - coins: space-separated distinct integers describing the respective values of each coin. 19 | 20 | ## Output format 21 | 22 | - An integer denoting the number of possible ways to make change for the desired amount. 23 | 24 | -------------------------------------------------------------------------------- /Question4/Python/Question4.py: -------------------------------------------------------------------------------- 1 | # Participants may update the following function parameters 2 | 3 | def maximumExpectedMoney(noOfTradesAvailable, maximumTradesAllowed, p, x, y): 4 | values_list = [] 5 | for p1, x1, y1 in zip(p, x, y): 6 | gain = p1 * x1 7 | loss = (1 - p1) * y1 8 | val = gain - loss 9 | if val >= 0: 10 | values_list.append(val) 11 | values_list.sort(reverse=True) 12 | suma = 0 13 | for i, e in enumerate(values_list): 14 | suma += e 15 | if (i + 1) == maximumTradesAllowed: 16 | break 17 | return suma 18 | 19 | 20 | def main(): 21 | # This part may require participants to fill +in as well. 22 | noOfTradesAvailable, maximumTradesAllowed = list(map(int, input().split())) 23 | p = list(map(float, input().split())) 24 | x = list(map(float, input().split())) 25 | y = list(map(float, input().split())) 26 | # Participants may update the following function parameters 27 | answer = maximumExpectedMoney(noOfTradesAvailable, maximumTradesAllowed, p, x, y) 28 | # Do not remove below line 29 | string = '{0:.2f}'.format(answer) 30 | print(string) 31 | # Do not print anything after this line 32 | 33 | 34 | if __name__ == '__main__': 35 | main() 36 | -------------------------------------------------------------------------------- /Question8/Java/Question8.java: -------------------------------------------------------------------------------- 1 | import java.io.*; 2 | import java.util.*; 3 | import java.util.stream.Stream; 4 | 5 | class Solution { 6 | 7 | // You may change this function parameters 8 | static long countNumberOfWays(int amount, int[] coins) { 9 | long[] history = new long[amount + 1]; 10 | Arrays.fill(history, 0); 11 | history[0] = 1; 12 | for (int coin : coins) 13 | for (int j = coin; j <= amount; j++) 14 | history[j] += history[j - coin]; 15 | return history[amount]; 16 | } 17 | 18 | 19 | private static final Scanner scanner = new Scanner(System.in); 20 | 21 | public static void main(String[] args) throws IOException { 22 | String[] firstLine = scanner.nextLine().split(" "); 23 | String[] secondLine = scanner.nextLine().split(" "); 24 | scanner.close(); 25 | 26 | int numOfUnits = Integer.parseInt(firstLine[0]); 27 | int numOfCoinTypes = Integer.parseInt(firstLine[1]); 28 | int[] coins = Stream.of(secondLine).mapToInt(Integer::parseInt).toArray(); 29 | 30 | long result = countNumberOfWays(numOfUnits, coins); 31 | // Please do not remove the below line. 32 | System.out.println(result); 33 | // Do not print anything after this line 34 | } 35 | } 36 | -------------------------------------------------------------------------------- /Question3/CPP/Question3.cpp: -------------------------------------------------------------------------------- 1 | #include 2 | using namespace std; 3 | string find_min_days(int profit[], int price[], int day_count, int size) 4 | { 5 | string return_string = ""; 6 | for (int i = 0; i < size; i++) 7 | { 8 | int start = 1; 9 | int end = INT32_MAX; 10 | 11 | for (int j = 0; j < day_count; j++) 12 | { 13 | for (int k = j + 1; k < day_count; k++) 14 | { 15 | 16 | if (price[k] - price[j] == profit[i] && ((k + 1) <= end)) 17 | { 18 | end = k + 1; 19 | start = j + 1; 20 | break; 21 | } 22 | /* code */ 23 | } 24 | } 25 | if (end == INT32_MAX) 26 | return_string += "-1,"; 27 | else 28 | { 29 | 30 | return_string += std::to_string(start); 31 | return_string += " "; 32 | return_string += std::to_string(end); 33 | return_string += ","; 34 | } 35 | } 36 | return_string = return_string.substr(0, return_string.size() - 1); 37 | 38 | //Participants code will be here 39 | return return_string; 40 | } 41 | 42 | int main() 43 | { 44 | int n, d, i; 45 | string answer = ""; 46 | cin >> n >> d; 47 | int price[n]; 48 | int profit[d]; 49 | for (i = 0; i < n; i++) 50 | cin >> price[i]; 51 | for (i = 0; i < d; i++) 52 | cin >> profit[i]; 53 | answer = find_min_days(profit, price, n, d); 54 | 55 | // Do not remove below line 56 | cout << answer << endl; 57 | // Do not print anything after this line 58 | 59 | return 0; 60 | } -------------------------------------------------------------------------------- /Question4/CPP/Question4.cpp: -------------------------------------------------------------------------------- 1 | #include 2 | using namespace std; 3 | long double maximumExpectedMoney(int n, int m, double p[], double x[], double y[]) 4 | { 5 | std::vector values; 6 | for (int i = 0; i < n; i++) 7 | { 8 | double chance = p[i]; 9 | double poss_gain = x[i]; 10 | double poss_loss = y[i]; 11 | double result = ((chance * poss_gain) - ((1 - chance) * poss_loss)); 12 | if (result > 0) 13 | values.push_back(result); 14 | } 15 | std::sort(values.begin(), values.end(), std::greater()); 16 | long double sum = 0; 17 | int count = 0; 18 | for (auto &i : values) 19 | { 20 | count++; 21 | sum += i; 22 | if (count == m) 23 | break; 24 | } 25 | return sum; 26 | } 27 | 28 | int main() 29 | { 30 | int n, m; 31 | 32 | cin >> n >> m; 33 | double p[n], x[n], y[n]; 34 | 35 | for (int i = 0; i < n; i++) 36 | cin >> p[i]; 37 | for (int i = 0; i < n; i++) 38 | cin >> x[i]; 39 | for (int i = 0; i < n; i++) 40 | cin >> y[i]; 41 | 42 | long double result = maximumExpectedMoney(n, m, p, x, y); 43 | result = std::round(result * 100) / 100; 44 | cout << std::fixed; 45 | cout << std::setprecision(2); 46 | 47 | // Do not remove below line 48 | cout << result << endl; 49 | // Do not print anything after this line 50 | 51 | return 0; 52 | } -------------------------------------------------------------------------------- /Question2/Java/Question2.java: -------------------------------------------------------------------------------- 1 | import java.io.*; 2 | import java.lang.reflect.Array; 3 | import java.util.*; 4 | import java.util.stream.Stream; 5 | 6 | class Solution { 7 | 8 | // You may change this function parameters 9 | static int findMaxProfit(int numOfPredictedDays, int[] predictedSharePrices) { 10 | int sum = 0; 11 | for (int i = 0; i < numOfPredictedDays; ) { 12 | int j = i; 13 | 14 | int x = i + 1; 15 | while (x < numOfPredictedDays && predictedSharePrices[x] > predictedSharePrices[j]) { 16 | x++; 17 | j++; 18 | } 19 | sum += predictedSharePrices[j] - predictedSharePrices[i]; 20 | i = x; 21 | } 22 | return sum; 23 | } 24 | 25 | private static final Scanner scanner = new Scanner(System.in); 26 | 27 | public static void main(String[] args) throws IOException { 28 | String[] firstLine = scanner.nextLine().split(" "); 29 | int[] firstLineArr = Stream.of(firstLine).mapToInt(Integer::parseInt).toArray(); 30 | int numOfPredictedTimes = firstLineArr[0]; 31 | int[] predictedSharePrices = Arrays.copyOfRange(firstLineArr, 1, firstLineArr.length); 32 | scanner.close(); 33 | 34 | int result = findMaxProfit(numOfPredictedTimes, predictedSharePrices); 35 | // Please do not remove the below line. 36 | System.out.println(result); 37 | // Do not print anything after this line 38 | } 39 | } 40 | -------------------------------------------------------------------------------- /Question3/Readme.md: -------------------------------------------------------------------------------- 1 | # [Question 3 - Profit Model for John](https://github.com/ZdrzalikPrzemyslaw/2020-Credit-Suisse-Global-Coding-Challenge/blob/master/.github/Global%20Coding%20Challenge_ex_3.pdf) 2 | 3 | John has recently started stock trading. He has predicted share prices for a particular company, 4 | over the next N days. John wants to analyze this data to build a model which will predict the best 5 | day to buy and sell the shares to achieve a specific profit. If there are multiple approaches of 6 | buying and selling shares to achieve this profit, John would like to know which of these will achieve 7 | the profit the earliest. 8 | 9 | ## Constraints 10 | 11 | - Only 1 share can be bought. 12 | - Short selling is not allowed. 13 | - 1 ≤ N ≤ 100000 14 | - 1 ≤ D ≤ 10 15 | - 1 ≤ N , D ≤ 1000000 16 | 17 | ## Input format 18 | 19 | - The first line contains two integers N and D, where N is the number of days for which he is 20 | predicting the share values and D is the number of different profits he would like to achieve. 21 | - The next line contains N space separated integers, where N is the value of the share on the i+1th 22 | day. 23 | - The next D lines contain a single integer D , where D is the profit that needs to be made. 24 | 25 | ## Output format 26 | 27 | - Print in the same line two space separated integers - the day on which the share was bought and 28 | the day on which the share was sold. The buy and sell days for different profits should be 29 | separated by , . If it is not possible to achieve the desirable profit, print -1. 30 | -------------------------------------------------------------------------------- /Question2/CPP/Question2.cpp: -------------------------------------------------------------------------------- 1 | #include 2 | 3 | using namespace std; 4 | 5 | int findMaxProfit(int numOfPredictedTimes, vector predictedSharePrices) { 6 | int sum = 0; 7 | for (int i = 0; i < numOfPredictedTimes; ) { 8 | int j = i; 9 | 10 | while (j + 1 < numOfPredictedTimes && predictedSharePrices[j + 1] > predictedSharePrices[j]) { 11 | j++; 12 | } 13 | sum += predictedSharePrices[j] - predictedSharePrices[i]; 14 | i = j + 1; 15 | } 16 | return sum; 17 | } 18 | 19 | vector splitStringToInt(const string& str, char delim) { 20 | vector strings; 21 | size_t start; 22 | size_t end = 0; 23 | while ((start = str.find_first_not_of(delim, end)) != string::npos) { 24 | end = str.find(delim, start); 25 | strings.push_back(stoi(str.substr(start, end - start))); 26 | } 27 | return strings; 28 | } 29 | 30 | void printVector(vector vec) { 31 | for (vector::const_iterator i = vec.begin(); i != vec.end(); ++i) { 32 | cout << *i << ' '; 33 | } 34 | cout << endl; 35 | } 36 | 37 | int main() { 38 | string firstLine; 39 | getline(cin, firstLine); 40 | 41 | vector firstLineVec = splitStringToInt(firstLine, ' '); 42 | int numOfPredictedTimes = firstLineVec[0]; 43 | vector predictedSharePrices(firstLineVec.begin()+1, firstLineVec.end()); 44 | 45 | 46 | int result = findMaxProfit(numOfPredictedTimes, predictedSharePrices); 47 | 48 | // Do not remove below line 49 | cout << result << "\n"; 50 | // Do not print anything after this line` 51 | 52 | return 0; 53 | } -------------------------------------------------------------------------------- /Question7/Readme.md: -------------------------------------------------------------------------------- 1 | # [Question 7 - Q&A community](https://github.com/ZdrzalikPrzemyslaw/2020-Credit-Suisse-Global-Coding-Challenge/blob/master/.github/Global%20Coding%20Challenge_ex_7.pdf) 2 | 3 | - There is a Q&A community where users can raise questions and answer questions raised by 4 | others, to earn credits. However, there are some users within the community who are suspected to 5 | have cheated, therefore, they require validation. 6 | - The following cases are treated as suspicious 7 | - User A answers User B's question and User B answers User A's question 8 | - If two or more users, which are considered suspicious, answer user C's question then user C is also considered suspicious. 9 | - Find the suspicious users. 10 | 11 | ## Constraints 12 | 13 | - Every user can only ask a maximum of one question. 14 | - Not every user needs to ask or answer a question, at least 2 users do. 15 | - A user can answer questions without asking a question. 16 | - A user cannot answer their own question. 17 | - 1 < userId < 10000 18 | - 1 < Number of questions < 10000 19 | 20 | ## Input format 21 | 22 | - The first line contains only one integer, which is the number of questions answered in the 23 | community. 24 | - The second line contains integers which refer to questions. The first integer is the questioner's ID 25 | and the subsequent integer(s) is the answerer's ID(s). Each question detail is separated by , .
26 | For example: 27 | 28 | >3
29 | >1 2,2 1,3 1 2 30 | 31 | - There are three questions answered in the community. User 1's question is answered by User 2. 32 | User 2's question is answered by User 1. User 3's question is answered by Users 1 & 2. 33 | 34 | 35 | ## Output format 36 | 37 | - A string that contains all suspicious User ID(s), sorted in ascending order, separated by , .
38 | For example: 39 | 40 | >1,2,3 41 | -------------------------------------------------------------------------------- /Question5/Readme.md: -------------------------------------------------------------------------------- 1 | # [Question 5 - Perfect Matching](https://github.com/ZdrzalikPrzemyslaw/2020-Credit-Suisse-Global-Coding-Challenge/blob/master/.github/Global%20Coding%20Challenge_ex_5.pdf) 2 | 3 | - Credit Suisse organizes a private banking career information session for its potential future private 4 | bankers and currently employed private bankers. There are n private bankers and m participants. 5 | - Assume for each participant, they want to meet a number of private bankers and similarly, for each 6 | private banker they want to recruit a number of participants. However, only one-on-one meetings 7 | are possible. So for each session, one participant can only meet one banker. 8 | - If Credit Suisse has a list of preferences from participants and private bankers, how many sessions 9 | are needed in order to fulfil everyone's preferences? 10 | 11 | ## Constraints 12 | 13 | - Every banker and participant must have at least one preference. 14 | 15 | ## Input format 16 | 17 | - The first line relates to the private bankers, and the second line relates to the participants. 18 | - The first integer in each line is the number of bankers/participants. 19 | - The subsequent integer input is the preference of bankers/participants, the preference of each 20 | person is separated by , .
For example: 21 | > 2 1&2,2
22 | > 2 1,2 23 | 24 | - The first line of input means that there are two private bankers. The preference of banker 1 is to 25 | meet participants 1 & 2, and the preference of banker 2 is to meet participant 2 only. 26 | - The second line of input means that there are two participants. The preference of participant 1 is to 27 | meet banker 1 only, and the preference of participant 2 is to meet banker 2 only. 28 | 29 | ## Output format 30 | 31 | - An integer that is the minimum number of sessions required to fulfil everyone's preferences. 32 | -------------------------------------------------------------------------------- /Question6/Java/Question6.java: -------------------------------------------------------------------------------- 1 | import java.io.*; 2 | import java.util.*; 3 | import java.util.stream.Stream; 4 | 5 | class Solution { 6 | 7 | static String encrypt(String words) { 8 | words = words.replaceAll(" ", ""); 9 | int rows = (int) Math.floor(Math.sqrt(words.length())); 10 | int cols = (int) Math.ceil(Math.sqrt(words.length())); 11 | if (rows * cols < words.length()) 12 | rows++; 13 | String[][] str = new String[rows][cols]; 14 | int count = 0; 15 | StringBuilder stringBuilder = new StringBuilder(); 16 | for (int i = 0; i < rows; i++) { 17 | for (int j = 0; j < cols; j++) { 18 | if (j * cols + i < words.length()) { 19 | stringBuilder.append(words, j * cols + i, j * cols + i + 1); 20 | count++; 21 | if (count == words.length()) { 22 | break; 23 | } 24 | } 25 | } 26 | stringBuilder.append(" "); 27 | } 28 | // for (int i = 0; i < cols; i++) { 29 | // for (int j = 0; j < rows; j++) { 30 | // if (str[j][i] != null) 31 | // stringBuilder.append(str[j][i]); 32 | // } 33 | // stringBuilder.append(" "); 34 | // } 35 | // Participant's code will go here 36 | return stringBuilder.toString(); 37 | } 38 | 39 | private static final Scanner scanner = new Scanner(System.in); 40 | 41 | public static void main(String[] args) throws IOException { 42 | String words = scanner.nextLine(); 43 | scanner.close(); 44 | 45 | String result = encrypt(words); 46 | // Please do not remove the below line. 47 | System.out.println(result); 48 | // Do nore print anything after this line 49 | } 50 | } -------------------------------------------------------------------------------- /Question4/Readme.md: -------------------------------------------------------------------------------- 1 | # [Question 4 - Risk Trading](https://github.com/ZdrzalikPrzemyslaw/2020-Credit-Suisse-Global-Coding-Challenge/blob/master/.github/Global%20Coding%20Challenge_ex_4.pdf) 2 | 3 | ## Disclaimer - the solutions provided passed at best 87 tests out of 90 4 | 5 | Whenever a company trades securities, there are various risks involved with the trade. Risk 6 | analysis is done for each trade in order to make the maximum profit from that trade. Each available 7 | trade can have the following properties: 8 | 9 | - Probability that the trade will make a profit (p). 10 | - Probability that the trade will make a loss (1-p). 11 | - Potential profit of the trade (x). 12 | - Potential loss of the trade (y). 13 | 14 | Find and print the maximum expected amount of money the company can make by performing at 15 | most m of the n trades, given the values of m, n, x, y and p. 16 | 17 | ## Constraints 18 | 19 | - 1 ≤ n, m ≤ 100000 20 | - 0 ≤ x, y ≤ 100 21 | - 0 ≤ p ≤ 1 22 | - All x, y and p are floating-point numbers scaled to exactly two decimal places (i.e 2.45 23 | format). 24 | 25 | ## Input format 26 | 27 | - The first line contains two space-separated integers denoting the respective values n (the number 28 | of trades available) and m (the maximum number of trades allowed). 29 | - The second line contains p space-separated floating-point numbers describing the respective 30 | values of p , where each p denotes the probability that the ith transaction will result in a profit. 31 | - The third line contains x space-separated floating-point numbers describing the respective values 32 | of x , where each x denotes the potential profit of the ith transaction. 33 | - The fourth line contains y space-separated floating-point numbers describing the respective values 34 | of y , where each y denotes the potential loss of the ith transaction. 35 | 36 | ## Output format 37 | 38 | - Print the maximum expected amount of money that can be made by performing at most m of the n 39 | available trades. Scale your answer to exactly 2 decimal places. 40 | -------------------------------------------------------------------------------- /Question4/Java/Question4.java: -------------------------------------------------------------------------------- 1 | import java.io.*; 2 | import java.text.DecimalFormat; 3 | import java.util.*; 4 | import java.util.stream.Stream; 5 | 6 | class Solution { 7 | 8 | // You may change this function parameters 9 | public static double maximumExpectedMoney(int n, int m, double[] p, double[] x, double[] y) { 10 | List values = new ArrayList<>(); 11 | for (int i = 0; i < n; i++) { 12 | double probability = p[i]; 13 | double gain = x[i]; 14 | double loss = y[i]; 15 | double res = ((probability * gain) - ((1 - probability) * loss)); 16 | if (res > 0) 17 | values.add(res); 18 | } 19 | values.sort(Collections.reverseOrder()); 20 | double sum = 0; 21 | int how_many = 0; 22 | for (double d : values) { 23 | sum += d; 24 | how_many++; 25 | if (how_many == m) 26 | return sum; 27 | } 28 | sum = Math.round(sum * 100.0) / 100.0; 29 | return sum; 30 | } 31 | 32 | public static void main(String[] args) throws IOException { 33 | Scanner in = new Scanner(System.in); 34 | // in.useLocale(Locale.ENGLISH); 35 | 36 | int n = in.nextInt(); 37 | int m = in.nextInt(); 38 | 39 | double[] p = new double[n]; 40 | double[] x = new double[n]; 41 | double[] y = new double[n]; 42 | double result = 0; 43 | 44 | //get input 45 | for (int i = 0; i < n; i++) 46 | p[i] = in.nextDouble(); 47 | for (int i = 0; i < n; i++) 48 | x[i] = in.nextDouble(); 49 | for (int i = 0; i < n; i++) 50 | y[i] = in.nextDouble(); 51 | 52 | 53 | result = maximumExpectedMoney(n, m, p, x, y); 54 | DecimalFormat df = new DecimalFormat("0.00"); 55 | // Do not remove below line 56 | System.out.println(df.format(result)); 57 | // Do not print anything after this line 58 | 59 | in.close(); 60 | } 61 | } -------------------------------------------------------------------------------- /Question9/CPP/Question9.cpp: -------------------------------------------------------------------------------- 1 | #include 2 | #include 3 | #include 4 | #include 5 | #include 6 | #include 7 | #include 8 | #include 9 | #include 10 | #include 11 | #include 12 | #include 13 | #include 14 | #include 15 | #include 16 | #include 17 | #include 18 | #include 19 | #include 20 | #include 21 | #include 22 | #include 23 | 24 | using namespace std; 25 | string organizingContainers(vector> container) 26 | { 27 | int32_t size_box[container.size()] = {0}; 28 | int32_t transaction_count_type[container.size()] = {0}; 29 | for (int i = 0; i < container.size(); i++) 30 | { 31 | for (int j = 0; j < container.size(); j++) 32 | { 33 | size_box[j] += container[i][j]; 34 | transaction_count_type[i] += container[i][j]; 35 | } 36 | } 37 | 38 | sort(size_box, size_box + container.size()); 39 | sort(transaction_count_type, transaction_count_type + container.size()); 40 | 41 | for (int i = 0; i < container.size(); i++) 42 | { 43 | if (size_box[i] != transaction_count_type[i]) 44 | return "Impossible"; 45 | } 46 | return "Possible"; 47 | } 48 | 49 | int main() 50 | { 51 | int q; 52 | cin >> q; 53 | string answer = ""; 54 | for (int a0 = 0; a0 < q; a0++) 55 | { 56 | int n; 57 | cin >> n; 58 | vector> M(n, vector(n)); 59 | for (int M_i = 0; M_i < n; M_i++) 60 | { 61 | for (int M_j = 0; M_j < n; M_j++) 62 | { 63 | cin >> M[M_i][M_j]; 64 | } 65 | } 66 | 67 | string result = organizingContainers(M); 68 | if (answer == "") 69 | answer = result; 70 | else 71 | answer = answer + "," + result; 72 | } 73 | 74 | // Do not remove below line 75 | cout << answer << endl; 76 | // Do not print anything after this line 77 | 78 | return 0; 79 | } -------------------------------------------------------------------------------- /README.md: -------------------------------------------------------------------------------- 1 | # [2020 Credit Suisse Global Coding Challenge](https://www.credit-suisse.com/pwp/hr/en/codingchallenge/#/) 2 | 3 | 4 | ![Status](https://img.shields.io/badge/status-finished-%2300b4f0.svg) 5 | [![License](https://img.shields.io/badge/license-MIT-blue.svg)](LICENSE.md) 6 | 7 | 8 | 9 | --- 10 | 11 |

12 | This project contains the implementations of the functions for the nine questions in 2020 Credit Suisse Global Coding Challenge. 13 |
14 |

15 | 16 | ## 📝 Table of Contents 17 | - [Results](#results) 18 | - [Question set](#question_set) 19 | - [Authors](#authors) 20 | 21 | ## 🏆 Results 22 | 23 | Second place on the European Individual Leaderboard 24 | 25 |
26 | result_page 27 |
28 | 29 | 30 | ## 🎓 Question set 31 | 32 | - [Question 1](https://github.com/ZdrzalikPrzemyslaw/2020-Credit-Suisse-Global-Coding-Challenge/tree/master/Question1) 33 | - [Question 2](https://github.com/ZdrzalikPrzemyslaw/2020-Credit-Suisse-Global-Coding-Challenge/tree/master/Question2) 34 | - [Question 3](https://github.com/ZdrzalikPrzemyslaw/2020-Credit-Suisse-Global-Coding-Challenge/tree/master/Question3) 35 | - [Question 4](https://github.com/ZdrzalikPrzemyslaw/2020-Credit-Suisse-Global-Coding-Challenge/tree/master/Question4) 36 | - [Question 5](https://github.com/ZdrzalikPrzemyslaw/2020-Credit-Suisse-Global-Coding-Challenge/tree/master/Question5) 37 | - [Question 6](https://github.com/ZdrzalikPrzemyslaw/2020-Credit-Suisse-Global-Coding-Challenge/tree/master/Question6) 38 | - [Question 7](https://github.com/ZdrzalikPrzemyslaw/2020-Credit-Suisse-Global-Coding-Challenge/tree/master/Question7) 39 | - [Question 8](https://github.com/ZdrzalikPrzemyslaw/2020-Credit-Suisse-Global-Coding-Challenge/tree/master/Question8) 40 | - [Question 9](https://github.com/ZdrzalikPrzemyslaw/2020-Credit-Suisse-Global-Coding-Challenge/tree/master/Question9) 41 | 42 | ## ✍️ Authors 43 | 44 | - [@ZdrzalikPrzemyslaw](https://github.com/ZdrzalikPrzemyslaw) 45 | -------------------------------------------------------------------------------- /Question8/CPP/Question8.cpp: -------------------------------------------------------------------------------- 1 | #include 2 | 3 | using namespace std; 4 | long countNumberOfWays(int amount, vector coins, int numOfCoinTypes) 5 | { 6 | unsigned long history[amount + 1] = {0}; 7 | history[0] = 1; 8 | for (auto const &coin : coins) 9 | for (int j = coin; j <= amount; j++) 10 | history[j] += history[j - coin]; 11 | return history[amount]; 12 | } 13 | 14 | vector split(const string &str, char delim) 15 | { 16 | vector strings; 17 | size_t start; 18 | size_t end = 0; 19 | while ((start = str.find_first_not_of(delim, end)) != string::npos) 20 | { 21 | end = str.find(delim, start); 22 | strings.push_back(str.substr(start, end - start)); 23 | } 24 | return strings; 25 | } 26 | 27 | vector splitStringToInt(const string &str, char delim) 28 | { 29 | vector strings; 30 | size_t start; 31 | size_t end = 0; 32 | while ((start = str.find_first_not_of(delim, end)) != string::npos) 33 | { 34 | end = str.find(delim, start); 35 | strings.push_back(stoi(str.substr(start, end - start))); 36 | } 37 | return strings; 38 | } 39 | 40 | void printVector(vector vec) 41 | { 42 | for (vector::const_iterator i = vec.begin(); i != vec.end(); ++i) 43 | { 44 | cout << *i << ' '; 45 | } 46 | cout << endl; 47 | } 48 | 49 | void printVector(vector vec) 50 | { 51 | for (vector::const_iterator i = vec.begin(); i != vec.end(); ++i) 52 | { 53 | cout << *i << ' '; 54 | } 55 | cout << endl; 56 | } 57 | 58 | int main() 59 | { 60 | string firstLine; 61 | getline(cin, firstLine); 62 | 63 | vector firstLineVec = splitStringToInt(firstLine, ' '); 64 | int numOfUnits = firstLineVec[0]; 65 | int numOfCoinTypes = firstLineVec[1]; 66 | 67 | string coins; 68 | getline(cin, coins); 69 | 70 | vector coinsVec = splitStringToInt(coins, ' '); 71 | 72 | long result = countNumberOfWays(numOfUnits, coinsVec, numOfCoinTypes); 73 | 74 | // Do not remove below line 75 | cout << result << "\n"; 76 | // Do not print anything after this line 77 | 78 | return 0; 79 | } 80 | -------------------------------------------------------------------------------- /Question1/CPP/Question1.cpp: -------------------------------------------------------------------------------- 1 | #include 2 | 3 | using namespace std; 4 | void printVector(vector vec); 5 | 6 | int findMaxProfit(int numOfPredictedDays, vector predictedSharePrices) 7 | { 8 | std::vector vec(numOfPredictedDays); 9 | int x = 0; 10 | std::iota(vec.begin(), vec.end(), x++); 11 | sort(vec.begin(), vec.end(), [&](int i, int j) { return predictedSharePrices[i] < predictedSharePrices[j]; }); 12 | int max_value = 0; 13 | int highestValueInPrices = predictedSharePrices[vec[numOfPredictedDays - 1]]; 14 | int lowest_index = vec.front(); 15 | for (int &i : vec) 16 | { 17 | if (highestValueInPrices - predictedSharePrices[i] < max_value) 18 | break; 19 | if (i <= lowest_index) 20 | { 21 | lowest_index = i; 22 | for (int j = i; j < numOfPredictedDays; j++) 23 | { 24 | int value = predictedSharePrices[j] - predictedSharePrices[i]; 25 | if (value > max_value) 26 | max_value = value; 27 | } 28 | } 29 | } 30 | return max_value; 31 | } 32 | 33 | vector splitStringToInt(const string &str, char delim) 34 | { 35 | vector strings; 36 | size_t start; 37 | size_t end = 0; 38 | while ((start = str.find_first_not_of(delim, end)) != string::npos) 39 | { 40 | end = str.find(delim, start); 41 | strings.push_back(stoi(str.substr(start, end - start))); 42 | } 43 | return strings; 44 | } 45 | 46 | void printVector(vector vec) 47 | { 48 | for (vector::const_iterator i = vec.begin(); i != vec.end(); ++i) 49 | { 50 | cout << *i << ' '; 51 | } 52 | cout << endl; 53 | } 54 | 55 | int main() 56 | { 57 | string firstLine; 58 | getline(cin, firstLine); 59 | 60 | vector firstLineVec = splitStringToInt(firstLine, ' '); 61 | int numOfPredictedDays = firstLineVec[0]; 62 | vector predictedSharePrices(firstLineVec.begin() + 1, firstLineVec.end()); 63 | 64 | int result = findMaxProfit(numOfPredictedDays, predictedSharePrices); 65 | 66 | // Do not remove this line 67 | cout << result << "\n"; 68 | // Do not print anything after this line 69 | 70 | return 0; 71 | } -------------------------------------------------------------------------------- /Question7/Python/Question7.py: -------------------------------------------------------------------------------- 1 | # Participants may update the following function parameters 2 | def findSuspiciousUserId(numOfQuestions, questionAndAnswerListOfList): 3 | size_of = 0 4 | my_dict = {} 5 | 6 | for i in questionAndAnswerListOfList: 7 | if i[0] > size_of: 8 | size_of = i[0] 9 | my_dict[i[0]] = i[1:] 10 | 11 | usersIndex = {} 12 | for i in range(numOfQuestions): 13 | usersIndex[questionAndAnswerListOfList[i][0]] = i 14 | 15 | suspUsers = set() 16 | 17 | for i, k in my_dict.items(): 18 | for j in k: 19 | if i != j and i not in suspUsers: 20 | if i in my_dict[j]: 21 | suspUsers.add(i) 22 | suspUsers.add(j) 23 | 24 | prev_size = -1 25 | while prev_size < len(suspUsers): 26 | prev_size = len(suspUsers) 27 | for i, k in my_dict.items(): 28 | if i not in suspUsers: 29 | count = 0 30 | for j in k: 31 | if j in suspUsers: 32 | count += 1 33 | if count == 2: 34 | suspUsers.add(i) 35 | break 36 | 37 | ret_str = [] 38 | for i in range(size_of + 1): 39 | if i in suspUsers: 40 | ret_str.append(i.__str__()) 41 | ret_str.append(',') 42 | ret_str = ret_str[:-1] 43 | 44 | # Participants code will be here 45 | return "".join(ret_str) 46 | 47 | 48 | def main(): 49 | firstLine = input().split(" ") 50 | secondLine = input() 51 | 52 | # Sample input: 53 | # 3 54 | # 1 2,2 1,3 1 2 55 | 56 | numOfQuestions = int(firstLine[0]) 57 | questionAndAnswers = secondLine.split(",") 58 | questionAndAnswerListOfList = parseQuestionAndAnswer(questionAndAnswers) 59 | 60 | # Participants may update the following function parameters 61 | answer = findSuspiciousUserId(numOfQuestions, questionAndAnswerListOfList) 62 | 63 | # Please do not remove the below line. 64 | print(answer) 65 | # Do not print anything after this line 66 | 67 | 68 | def parseQuestionAndAnswer(questionAndAnswers): 69 | questionAndAnswerListOfList = [] 70 | for index in range(0, len(questionAndAnswers)): 71 | questionAndAnswerList = questionAndAnswers[index].split(" ") 72 | questionAndAnswerListOfList.append([int(x) for x in questionAndAnswerList]) 73 | return questionAndAnswerListOfList 74 | 75 | 76 | if __name__ == '__main__': 77 | main() 78 | -------------------------------------------------------------------------------- /Question7/Java/Question7.java: -------------------------------------------------------------------------------- 1 | import java.io.*; 2 | import java.util.*; 3 | import java.util.stream.Stream; 4 | 5 | class Solution { 6 | 7 | // You may change this function parameters 8 | static String findSuspiciousUserId(int numOfQuestions, int[][] questionAndAnswerArrOfArr) { 9 | 10 | int sizeOf = 0; 11 | for (int[] v : questionAndAnswerArrOfArr) { 12 | if (v[0] > sizeOf) 13 | sizeOf = v[0]; 14 | } 15 | boolean[] suspUsers = new boolean[sizeOf + 1]; 16 | int[] usersIndex = new int[sizeOf + 1]; 17 | for (int i = 0; i < numOfQuestions; i++) { 18 | usersIndex[questionAndAnswerArrOfArr[i][0]] = i; 19 | } 20 | 21 | for (int[] i : questionAndAnswerArrOfArr) { 22 | for (int j : i) { 23 | if (i[0] != j && (!suspUsers[i[0]])) { 24 | if (Arrays.stream(questionAndAnswerArrOfArr[usersIndex[j]]).anyMatch(num -> true)) { 25 | suspUsers[i[0]] = true; 26 | suspUsers[j] = true; 27 | } 28 | } 29 | } 30 | } 31 | 32 | int suspAmount = 0; 33 | int prev_size = -1; 34 | while (prev_size < suspAmount) { 35 | prev_size = suspAmount; 36 | for (int[] i : questionAndAnswerArrOfArr) { 37 | if (!suspUsers[i[0]]) { 38 | int count = 0; 39 | for (int j : i) { 40 | if (suspUsers[j]) { 41 | count++; 42 | if (count == 2) { 43 | suspUsers[i[0]] = true; 44 | suspAmount++; 45 | break; 46 | } 47 | } 48 | } 49 | } 50 | } 51 | } 52 | StringBuilder stringBuilder = new StringBuilder(); 53 | for (int i = 1; i <= sizeOf; i++) { 54 | if (suspUsers[i]) 55 | stringBuilder.append(i).append(","); 56 | } 57 | stringBuilder.setLength(stringBuilder.length() - 1); 58 | return stringBuilder.toString(); 59 | } 60 | 61 | private static final Scanner scanner = new Scanner(System.in); 62 | 63 | public static void main(String[] args) throws IOException { 64 | // Sample input: 65 | // 3 66 | // 1 2,2 1,3 1 2 67 | String[] firstLine = scanner.nextLine().split(" "); 68 | String secondLine = scanner.nextLine(); 69 | scanner.close(); 70 | 71 | int numOfQuestions = Integer.parseInt(firstLine[0]); 72 | String[] questionAndAnswers = secondLine.split(","); 73 | int[][] questionAndAnswerArrOfArr = parseQuestionAndAnswer(questionAndAnswers); 74 | 75 | String result = findSuspiciousUserId(numOfQuestions, questionAndAnswerArrOfArr); 76 | // Please do not remove the below line. 77 | System.out.println(result); 78 | // Do not print anything after this line 79 | } 80 | 81 | private static int[][] parseQuestionAndAnswer(String[] questionAndAnswers) { 82 | return Arrays.stream(questionAndAnswers) 83 | .map(questionAndAnswer -> { 84 | String[] questionAndAnswerArr = questionAndAnswer.split(" "); 85 | return Stream.of(questionAndAnswerArr).mapToInt(Integer::parseInt).toArray(); 86 | }) 87 | .toArray(int[][]::new); 88 | } 89 | } -------------------------------------------------------------------------------- /Question9/Readme.md: -------------------------------------------------------------------------------- 1 | # [Question 9 - Unauthorized Transactions](https://github.com/ZdrzalikPrzemyslaw/2020-Credit-Suisse-Global-Coding-Challenge/blob/master/.github/Global%20Coding%20Challenge_ex_9.pdf) 2 | 3 | - It is important that banks recognize unauthorized transactions in order to protect their clients. Leon 4 | has recently started working at a large credit card company where his role is to investigate 5 | fraudulent credit card transactions. He is attempting to sort transactions, depending on their fraud 6 | probability, into separate boxes. 7 | - Let t = 2 mean that Leon has 2 types of transactions and 2 different boxes, both labelled from 0 to 8 | t-1. The current organization of the transactions in each box can be shown using a matrix M (size 9 | t x t). Consider M = [[8, 3], [3, 9]]: 10 | 11 | 12 | 13 | 14 | 15 | 16 | 17 | 18 | 19 | 20 | 21 | 22 | 23 | 24 | 25 | 26 | 27 |
Type 0Type 1
Box 083
Box 139
28 | 29 | 30 | - In this table, we can see in box 0 there are 8 transactions of type 0 and 3 transactions of type 1. In 31 | box 1, there are 3 transactions of type 0 and 9 transactions of type 1. Leon is able to switch, in a 32 | single operation, two transactions in different boxes. He can switch a type 0 transaction from Box 1 33 | with a type 1 transaction from Box 0. As shown below. 34 | 35 | 36 | 37 | 38 | 39 | 40 | 41 | 42 | 43 | 44 | 45 | 46 | 47 | 48 | 49 | 50 | 51 | 52 |
Type 0Type 1
Box 092
Box 1210
53 | 54 | - He can continue doing this until he has all transactions of type 0 in box 0 and all transactions of 55 | type 1 in box 1. The sorted boxes are reflected in the Matrix table below. There can be multiple 56 | different ways of sorting the transactions. 57 | 58 | 59 | 60 | 61 | 62 | 63 | 64 | 65 | 66 | 67 | 68 | 69 | 70 | 71 | 72 | 73 | 74 |
Type 0Type 1
Box 0110
Box 1012
75 | 76 | - These switching operations need to fulfil the following condition in order for the transactions to be 77 | sorted: 78 | - Every box has only transactions of the same type. Two transactions of the same type cannot 79 | be located in two different boxes. 80 | - The first line contains an integer n, the number of unsorted problems. Attempt to sort n different 81 | unsorted problems, each in the form of a matrix M. 82 | - Each of the next n sets contains: 83 | - Integer t represents the number of boxes (rows) and transaction types (columns). 84 | - The next t lines contains integers, separated using a space, for row M[i]. 85 | 86 | 87 | 88 | ## Constraints 89 | 90 | - A box is a two dimensional array of integers, illustrating the number of transactions of each 91 | type found in each box. 92 | - 1 ≤ n ≤10 93 | - 1 ≤ t ≤ 100. 94 | - 0 ≤ M[box][Transaction type] ≤ 100000 95 | 96 | ## Input format 97 | 98 | - The first line contains an integer n, the number of unsorted problems. Attempt to sort n different 99 | unsorted problems, each in the form of a matrix M. 100 | - Each of the next n sets contains: 101 | - Integer t represents the number of boxes (rows) and transaction types (columns). 102 | - The next t lines contains integers, separated using a space, for row M[i]. 103 | 104 | ## Output format 105 | 106 | - A string that contains all suspicious User ID(s), sorted in ascending order, separated by , .
107 | For example: 108 | 109 | >1,2,3 110 | -------------------------------------------------------------------------------- /Question7/CPP/Question7.cpp: -------------------------------------------------------------------------------- 1 | #include 2 | 3 | using namespace std; 4 | string findSuspiciousUserId(int numOfQuestions, vector> questionAndAnswerVecOfVec) 5 | { 6 | int sizeOf = 0; 7 | for (auto &v : questionAndAnswerVecOfVec) 8 | { 9 | if (v[0] > sizeOf) 10 | sizeOf = v[0]; 11 | } 12 | bool suspUsers[sizeOf + 1] = {false}; 13 | int usersIndex[sizeOf + 1]; 14 | 15 | for (int i = 0; i < numOfQuestions; i++) 16 | { 17 | usersIndex[questionAndAnswerVecOfVec[i][0]] = i; 18 | } 19 | 20 | for (auto const &i : questionAndAnswerVecOfVec) 21 | { 22 | for (auto const &j : i) 23 | { 24 | if (i[0] != j && (!suspUsers[i[0]])) 25 | { 26 | auto vec = questionAndAnswerVecOfVec[usersIndex[j]]; 27 | if (std::find(vec.begin(), vec.end(), i[0]) != vec.end()) 28 | { 29 | suspUsers[i[0]] = true; 30 | suspUsers[j] = true; 31 | } 32 | } 33 | } 34 | } 35 | 36 | int suspAmount = 0; 37 | 38 | int prev_size = -1; 39 | while (prev_size < suspAmount) 40 | { 41 | prev_size = suspAmount; 42 | for (auto &i : questionAndAnswerVecOfVec) 43 | { 44 | if (!suspUsers[i[0]]) 45 | { 46 | int count = 0; 47 | for (auto &j : i) 48 | { 49 | if (suspUsers[j]) 50 | { 51 | count++; 52 | if (count == 2) 53 | { 54 | suspUsers[i[0]] = true; 55 | suspAmount++; 56 | break; 57 | } 58 | } 59 | } 60 | } 61 | } 62 | } 63 | 64 | string retStr = ""; 65 | for (int i = 1; i < sizeOf + 1; i++) 66 | { 67 | if (suspUsers[i]) 68 | { 69 | retStr += std::to_string(i); 70 | retStr += ","; 71 | } 72 | } 73 | retStr = retStr.substr(0, retStr.length() - 1); 74 | 75 | // Participant's code will go here 76 | return retStr; 77 | } 78 | 79 | vector split(const string &str, char delim) 80 | { 81 | vector strings; 82 | size_t start; 83 | size_t end = 0; 84 | while ((start = str.find_first_not_of(delim, end)) != string::npos) 85 | { 86 | end = str.find(delim, start); 87 | strings.push_back(str.substr(start, end - start)); 88 | } 89 | return strings; 90 | } 91 | 92 | vector splitStringToInt(const string &str, char delim) 93 | { 94 | vector strings; 95 | size_t start; 96 | size_t end = 0; 97 | while ((start = str.find_first_not_of(delim, end)) != string::npos) 98 | { 99 | end = str.find(delim, start); 100 | strings.push_back(stoi(str.substr(start, end - start))); 101 | } 102 | return strings; 103 | } 104 | 105 | void printVector(vector vec) 106 | { 107 | for (vector::const_iterator i = vec.begin(); i != vec.end(); ++i) 108 | { 109 | cout << *i << ' '; 110 | } 111 | cout << endl; 112 | } 113 | 114 | void printVector(vector vec) 115 | { 116 | for (vector::const_iterator i = vec.begin(); i != vec.end(); ++i) 117 | { 118 | cout << *i << ' '; 119 | } 120 | cout << endl; 121 | } 122 | 123 | int main() 124 | { 125 | string firstLine; 126 | getline(cin, firstLine); 127 | 128 | int numOfQuestions = strtol(firstLine.c_str(), NULL, 10); 129 | ; 130 | 131 | string questionAndAnswerStr; 132 | getline(cin, questionAndAnswerStr); 133 | 134 | vector> questionAndAnswerVecOfVec; 135 | vector questionAndAnswerVecByComma = split(questionAndAnswerStr, ','); 136 | 137 | for (vector::const_iterator i = questionAndAnswerVecByComma.begin(); i != questionAndAnswerVecByComma.end(); ++i) 138 | { 139 | vector bankerPreferenceVecByAnd = splitStringToInt(*i, ' '); 140 | questionAndAnswerVecOfVec.push_back(bankerPreferenceVecByAnd); 141 | } 142 | 143 | string result = findSuspiciousUserId(numOfQuestions, questionAndAnswerVecOfVec); 144 | 145 | // Do not remove below line 146 | cout << result << "\n"; 147 | // Do not print anything after this line 148 | 149 | return 0; 150 | } -------------------------------------------------------------------------------- /Question5/CPP/Question5.cpp: -------------------------------------------------------------------------------- 1 | #include 2 | 3 | using namespace std; 4 | int calculateMinimumSession(int numOfBankers, int numOfParticipants, vector> bankersPreferences, vector> participantsPreferences) 5 | { 6 | 7 | int participantVisitsCount[numOfParticipants] = {0}; 8 | int bankersVisitsCount[numOfBankers] = {0}; 9 | int max = 0; 10 | 11 | for (int i = 0; i < numOfBankers; i++) 12 | { 13 | for (auto const &j : bankersPreferences[i]) 14 | { 15 | participantVisitsCount[j - 1]++; 16 | bool has_met = false; 17 | for (auto const & k : participantsPreferences[j - 1]) 18 | { 19 | if (i == (k - 1)) 20 | { 21 | has_met = true; 22 | break; 23 | } 24 | } 25 | if (!has_met) 26 | bankersVisitsCount[i]++; 27 | } 28 | } 29 | for (int i = 0; i < numOfParticipants; i++) 30 | { 31 | for (auto const &j : participantsPreferences[i]) 32 | { 33 | bankersVisitsCount[j - 1]++; 34 | bool has_met = false; 35 | for (int k : bankersPreferences[j - 1]) 36 | { 37 | if (i == (k - 1)) 38 | { 39 | has_met = true; 40 | break; 41 | } 42 | } 43 | if (!has_met) 44 | participantVisitsCount[i]++; 45 | } 46 | } 47 | 48 | for (auto const &i : participantVisitsCount) 49 | { 50 | if (max < i) 51 | max = i; 52 | } 53 | for (auto const &i : bankersVisitsCount) 54 | { 55 | if (max < i) 56 | max = i; 57 | } 58 | 59 | return max; 60 | } 61 | 62 | vector split(const string &str, char delim) 63 | { 64 | vector strings; 65 | size_t start; 66 | size_t end = 0; 67 | while ((start = str.find_first_not_of(delim, end)) != string::npos) 68 | { 69 | end = str.find(delim, start); 70 | strings.push_back(str.substr(start, end - start)); 71 | } 72 | return strings; 73 | } 74 | 75 | vector splitStringToInt(const string &str, char delim) 76 | { 77 | vector strings; 78 | size_t start; 79 | size_t end = 0; 80 | while ((start = str.find_first_not_of(delim, end)) != string::npos) 81 | { 82 | end = str.find(delim, start); 83 | strings.push_back(stoi(str.substr(start, end - start))); 84 | } 85 | return strings; 86 | } 87 | 88 | void printVector(vector vec) 89 | { 90 | for (vector::const_iterator i = vec.begin(); i != vec.end(); ++i) 91 | { 92 | cout << *i << ' '; 93 | } 94 | cout << endl; 95 | } 96 | 97 | void printVector(vector vec) 98 | { 99 | for (vector::const_iterator i = vec.begin(); i != vec.end(); ++i) 100 | { 101 | cout << *i << ' '; 102 | } 103 | cout << endl; 104 | } 105 | 106 | int main() 107 | { 108 | int numOfBankers, numOfParticipants; 109 | vector> bankersPreferences, participantsPreferences; 110 | 111 | cin >> numOfBankers; 112 | 113 | string bankersPreferencesStr; 114 | cin >> bankersPreferencesStr; 115 | vector bankersPreferencesVecByComma = split(bankersPreferencesStr, ','); 116 | 117 | for (vector::const_iterator i = bankersPreferencesVecByComma.begin(); i != bankersPreferencesVecByComma.end(); ++i) 118 | { 119 | vector bankerPreferenceVecByAnd = splitStringToInt(*i, '&'); 120 | bankersPreferences.push_back(bankerPreferenceVecByAnd); 121 | } 122 | 123 | string participantsPreferencesStr; 124 | cin >> numOfParticipants; 125 | cin >> participantsPreferencesStr; 126 | vector participantsPreferencesVecByComma = split(participantsPreferencesStr, ','); 127 | 128 | for (vector::const_iterator i = participantsPreferencesVecByComma.begin(); i != participantsPreferencesVecByComma.end(); ++i) 129 | { 130 | vector participantPreferenceVecByAnd = splitStringToInt(*i, '&'); 131 | participantsPreferences.push_back(participantPreferenceVecByAnd); 132 | } 133 | 134 | int result = calculateMinimumSession(numOfBankers, numOfParticipants, bankersPreferences, participantsPreferences); 135 | 136 | // Do not remove below line 137 | cout << result << "\n"; 138 | // Do not print anything after this line 139 | 140 | return 0; 141 | } -------------------------------------------------------------------------------- /.gitignore: -------------------------------------------------------------------------------- 1 | 2 | # Created by https://www.toptal.com/developers/gitignore/api/c++,java,python,intellij+all,visualstudiocode 3 | # Edit at https://www.toptal.com/developers/gitignore?templates=c++,java,python,intellij+all,visualstudiocode 4 | 5 | ### C++ ### 6 | # Prerequisites 7 | *.d 8 | 9 | # Compiled Object files 10 | *.slo 11 | *.lo 12 | *.o 13 | *.obj 14 | 15 | # Precompiled Headers 16 | *.gch 17 | *.pch 18 | 19 | # Compiled Dynamic libraries 20 | *.so 21 | *.dylib 22 | *.dll 23 | 24 | # Fortran module files 25 | *.mod 26 | *.smod 27 | 28 | # Compiled Static libraries 29 | *.lai 30 | *.la 31 | *.a 32 | *.lib 33 | 34 | # Executables 35 | *.exe 36 | *.out 37 | *.app 38 | 39 | ### Intellij+all ### 40 | # Covers JetBrains IDEs: IntelliJ, RubyMine, PhpStorm, AppCode, PyCharm, CLion, Android Studio, WebStorm and Rider 41 | # Reference: https://intellij-support.jetbrains.com/hc/en-us/articles/206544839 42 | 43 | # User-specific stuff 44 | .idea/**/workspace.xml 45 | .idea/**/tasks.xml 46 | .idea/**/usage.statistics.xml 47 | .idea/**/dictionaries 48 | .idea/**/shelf 49 | 50 | # Generated files 51 | .idea/**/contentModel.xml 52 | 53 | # Sensitive or high-churn files 54 | .idea/**/dataSources/ 55 | .idea/**/dataSources.ids 56 | .idea/**/dataSources.local.xml 57 | .idea/**/sqlDataSources.xml 58 | .idea/**/dynamic.xml 59 | .idea/**/uiDesigner.xml 60 | .idea/**/dbnavigator.xml 61 | 62 | # Gradle 63 | .idea/**/gradle.xml 64 | .idea/**/libraries 65 | 66 | # Gradle and Maven with auto-import 67 | # When using Gradle or Maven with auto-import, you should exclude module files, 68 | # since they will be recreated, and may cause churn. Uncomment if using 69 | # auto-import. 70 | # .idea/artifacts 71 | # .idea/compiler.xml 72 | # .idea/jarRepositories.xml 73 | # .idea/modules.xml 74 | # .idea/*.iml 75 | # .idea/modules 76 | # *.iml 77 | # *.ipr 78 | 79 | # CMake 80 | cmake-build-*/ 81 | 82 | # Mongo Explorer plugin 83 | .idea/**/mongoSettings.xml 84 | 85 | # File-based project format 86 | *.iws 87 | 88 | # IntelliJ 89 | out/ 90 | 91 | # mpeltonen/sbt-idea plugin 92 | .idea_modules/ 93 | 94 | # JIRA plugin 95 | atlassian-ide-plugin.xml 96 | 97 | # Cursive Clojure plugin 98 | .idea/replstate.xml 99 | 100 | # Crashlytics plugin (for Android Studio and IntelliJ) 101 | com_crashlytics_export_strings.xml 102 | crashlytics.properties 103 | crashlytics-build.properties 104 | fabric.properties 105 | 106 | # Editor-based Rest Client 107 | .idea/httpRequests 108 | 109 | # Android studio 3.1+ serialized cache file 110 | .idea/caches/build_file_checksums.ser 111 | 112 | ### Intellij+all Patch ### 113 | # Ignores the whole .idea folder and all .iml files 114 | # See https://github.com/joeblau/gitignore.io/issues/186 and https://github.com/joeblau/gitignore.io/issues/360 115 | 116 | .idea/ 117 | 118 | # Reason: https://github.com/joeblau/gitignore.io/issues/186#issuecomment-249601023 119 | 120 | *.iml 121 | modules.xml 122 | .idea/misc.xml 123 | *.ipr 124 | 125 | # Sonarlint plugin 126 | .idea/sonarlint 127 | 128 | ### Java ### 129 | # Compiled class file 130 | *.class 131 | 132 | # Log file 133 | *.log 134 | 135 | # BlueJ files 136 | *.ctxt 137 | 138 | # Mobile Tools for Java (J2ME) 139 | .mtj.tmp/ 140 | 141 | # Package Files # 142 | *.jar 143 | *.war 144 | *.nar 145 | *.ear 146 | *.zip 147 | *.tar.gz 148 | *.rar 149 | 150 | # virtual machine crash logs, see http://www.java.com/en/download/help/error_hotspot.xml 151 | hs_err_pid* 152 | 153 | ### Python ### 154 | # Byte-compiled / optimized / DLL files 155 | __pycache__/ 156 | *.py[cod] 157 | *$py.class 158 | 159 | # C extensions 160 | 161 | # Distribution / packaging 162 | .Python 163 | build/ 164 | develop-eggs/ 165 | dist/ 166 | downloads/ 167 | eggs/ 168 | .eggs/ 169 | lib/ 170 | lib64/ 171 | parts/ 172 | sdist/ 173 | var/ 174 | wheels/ 175 | pip-wheel-metadata/ 176 | share/python-wheels/ 177 | *.egg-info/ 178 | .installed.cfg 179 | *.egg 180 | MANIFEST 181 | 182 | # PyInstaller 183 | # Usually these files are written by a python script from a template 184 | # before PyInstaller builds the exe, so as to inject date/other infos into it. 185 | *.manifest 186 | *.spec 187 | 188 | # Installer logs 189 | pip-log.txt 190 | pip-delete-this-directory.txt 191 | 192 | # Unit test / coverage reports 193 | htmlcov/ 194 | .tox/ 195 | .nox/ 196 | .coverage 197 | .coverage.* 198 | .cache 199 | nosetests.xml 200 | coverage.xml 201 | *.cover 202 | *.py,cover 203 | .hypothesis/ 204 | .pytest_cache/ 205 | pytestdebug.log 206 | 207 | # Translations 208 | *.mo 209 | *.pot 210 | 211 | # Django stuff: 212 | local_settings.py 213 | db.sqlite3 214 | db.sqlite3-journal 215 | 216 | # Flask stuff: 217 | instance/ 218 | .webassets-cache 219 | 220 | # Scrapy stuff: 221 | .scrapy 222 | 223 | # Sphinx documentation 224 | docs/_build/ 225 | doc/_build/ 226 | 227 | # PyBuilder 228 | target/ 229 | 230 | # Jupyter Notebook 231 | .ipynb_checkpoints 232 | 233 | # IPython 234 | profile_default/ 235 | ipython_config.py 236 | 237 | # pyenv 238 | .python-version 239 | 240 | # pipenv 241 | # According to pypa/pipenv#598, it is recommended to include Pipfile.lock in version control. 242 | # However, in case of collaboration, if having platform-specific dependencies or dependencies 243 | # having no cross-platform support, pipenv may install dependencies that don't work, or not 244 | # install all needed dependencies. 245 | #Pipfile.lock 246 | 247 | # PEP 582; used by e.g. github.com/David-OConnor/pyflow 248 | __pypackages__/ 249 | 250 | # Celery stuff 251 | celerybeat-schedule 252 | celerybeat.pid 253 | 254 | # SageMath parsed files 255 | *.sage.py 256 | 257 | # Environments 258 | .env 259 | .venv 260 | env/ 261 | venv/ 262 | ENV/ 263 | env.bak/ 264 | venv.bak/ 265 | pythonenv* 266 | 267 | # Spyder project settings 268 | .spyderproject 269 | .spyproject 270 | 271 | # Rope project settings 272 | .ropeproject 273 | 274 | # mkdocs documentation 275 | /site 276 | 277 | # mypy 278 | .mypy_cache/ 279 | .dmypy.json 280 | dmypy.json 281 | 282 | # Pyre type checker 283 | .pyre/ 284 | 285 | # pytype static type analyzer 286 | .pytype/ 287 | 288 | # profiling data 289 | .prof 290 | 291 | ### VisualStudioCode ### 292 | .vscode/* 293 | !.vscode/tasks.json 294 | !.vscode/launch.json 295 | *.code-workspace 296 | 297 | ### VisualStudioCode Patch ### 298 | # Ignore all local history of files 299 | .history 300 | .ionide 301 | 302 | # End of https://www.toptal.com/developers/gitignore/api/c++,java,python,intellij+all,visualstudiocode 303 | --------------------------------------------------------------------------------