|
1 | 1 | A repository of coding challenges/tasks I came across in various job interviews. |
2 | 2 | I mostly do backend programming in Go and PHP, so here you can find some solutions. |
3 | 3 |
|
4 | | -The solutions to the tasks do not fulfill to be the shortest, fastest or cleanest solutions. |
| 4 | +--- |
5 | 5 |
|
6 | | -## Tasks |
| 6 | +I am moving off Github to Codeberg. |
7 | 7 |
|
8 | | -Each task should come with a solution plus some tests to verify. |
9 | | - |
10 | | -### Task 1 |
11 | | - |
12 | | -Create a function `maskify` to mask digits of a credit card number with `#`. |
13 | | - |
14 | | -**Requirements:** |
15 | | - |
16 | | -- Do not mask the first digit and the last four digits |
17 | | -- Do not mask non-digit chars |
18 | | -- Do not mask if the input is less than 6 |
19 | | -- Return '' when input is empty |
20 | | - |
21 | | -### Task 2 |
22 | | - |
23 | | -Create a function `number_to_ordinal` to create an ordinal number for a given input. |
24 | | -Ordinal numbers in English have something like `st`, `nd`, `rd`, etc. |
25 | | - |
26 | | -**Requirements:** |
27 | | - |
28 | | -- Apply for number 1 to 1001... if that works any given number will do ;-) |
29 | | - |
30 | | -### Task 3 |
31 | | - |
32 | | -Create a calculator for [Reverse Polish Notation](https://en.wikipedia.org/wiki/Reverse_Polish_notation). |
33 | | -Write a `calculate` function that accepts an input and returns the result of the operation. |
34 | | - |
35 | | -**Requirements:** |
36 | | - |
37 | | -- Support the mathematical operations for `+`, `-`, `*` and `/` |
38 | | -- Check for invalid syntax, like `2 3+`. There is a space missing. |
39 | | -- Return 0 (integer) when nothing is entered |
40 | | -- Return the numeric value when no operand is given, like `1 2 3.5` return `3.5` |
41 | | - |
42 | | -### Task 4 |
43 | | - |
44 | | -Given you have an array of numbers, you move inside the array by the value of the current element. |
45 | | -Write a function `jump_out_of_array` that outputs |
46 | | - |
47 | | -- the amount of jumps until you jump out of the array |
48 | | -- `-1` when you reach the end of the array but do not jump out |
49 | | - |
50 | | -**Requirements:** |
51 | | - |
52 | | -- Array size is indefinite |
53 | | -- Array elements are integers, positive and negative |
54 | | - |
55 | | -**Example:** |
56 | | - |
57 | | -Given an array of `A[2, 3, -1, 1, 6, 4]`. |
58 | | - |
59 | | - |
60 | | - |
61 | | -- Jump 1: `A[0]` + `2` = `A[2]` |
62 | | -- Jump 2: `A[2]` + `(-1)` = `A[1]` |
63 | | -- Jump 3: `A[1]` + `3` = `A[4]` |
64 | | -- Jump 4: `A[4]` + `6` = out of range |
65 | | - |
66 | | -So the result is `4`, you need `4` jumps to jump out of the array. |
67 | | - |
68 | | -### Task 5 |
69 | | - |
70 | | -Find the k-complement pairs in an array of a given number. Write a function `k_complement` that that outputs the amount |
71 | | -of pairs. |
72 | | - |
73 | | -**Requirements:** |
74 | | - |
75 | | -_Do not_ use nested loops to solve this problem, because of a time complexity of the loop solution. |
76 | | -[Check this thread](https://stackoverflow.com/questions/11032015/how-to-find-time-complexity-of-an-algorithm) to see what time complexity of an algorithm means. |
77 | | - |
78 | | -**Example:** |
79 | | - |
80 | | -- `A[0]` + `A[8]` = `1` + `5` = `6` |
81 | | -- `A[1]` + `A[6]` = `8` + `-2` = `6` |
82 | | -- `A[4]` + `A[8]` = `1` + `5` = `6` |
83 | | -- `A[5]` + `A[5]` = `3` + `3` = `6` |
84 | | -- `A[5]` + `A[5]` = `3` + `3` = `6` |
85 | | -- `A[6]` + `A[1]` = `-2` + `8` = `6` |
86 | | -- `A[8]` + `A[0]` = `5` + `1` = `6` |
87 | | - |
88 | | -The result here is `7`. |
89 | | - |
90 | | -### Task 6 |
91 | | - |
92 | | -Calculate the [Fibonacci number](https://en.wikipedia.org/wiki/Fibonacci_number) of a given number |
93 | | -and return the last `6` non-zero numbers. |
94 | | - |
95 | | -**Requirements:** |
96 | | - |
97 | | -- Use a recursive approach instead of looping through. |
98 | | -- Throw an exception when passing in a negative number |
99 | | - |
100 | | -**Example:** |
101 | | - |
102 | | -- `F8` = `21`, return `21` |
103 | | -- `F38` = `39088169`, return `88169` |
104 | | - |
105 | | -### Task 7 |
106 | | - |
107 | | -Given the follwing function you should suggest what could be improved. There are no other documents explaining why this function has been written or what the purpose is/should be. |
108 | | - |
109 | | -**Example in python** |
110 | | - |
111 | | -```python |
112 | | -def multiply(x, y): |
113 | | - if y > 0: |
114 | | - return (1 + multiply(x, y-1)) |
115 | | - else: |
116 | | - return 0 |
117 | | -``` |
118 | | - |
119 | | -**Possible considerations:** |
120 | | - |
121 | | -- Does the function really _multiply_ two values? |
122 | | -- Could the in-built multiply function be used? |
123 | | -- Is a recursive function the way to go? |
124 | | -- What can happen when using this with big numbers, f. ex. > 1.000.000? |
125 | | -- Type hints |
126 | | - |
127 | | -### Task 8 |
128 | | - |
129 | | -Do an in-place mirroring of a one dimensional array. In-place switching is key here as the input array can be very big |
130 | | -and no additional memory should be occupied - see [Space Complexity](https://www.geeksforgeeks.org/g-fact-86/). |
131 | | - |
132 | | -**Requirements:** |
133 | | - |
134 | | -- In-place mirroring |
135 | | -- Handle array with even and odd amount of items |
136 | | -- Do not use the [`array_reverse`](https://www.php.net/manual/de/function.array-reverse.php) function in PHP |
137 | | - |
138 | | -**Example:** |
139 | | - |
140 | | -- Even amount: `[8,5,1,4]` -> `[4,1,5,8]` |
141 | | -- Odd amount: `[6,2,7,9,3]` -> `[3,9,7,2,6]` |
142 | | - |
143 | | -## Contribute |
144 | | - |
145 | | -Feel free to contribute. Use the issue list to propose new tasks or open PRs. Just provide proper tests |
146 | | -and description and requirements for the tasks. |
| 8 | +This package has been migrated to https://codeberg.org/codedge/coding-challenges. |
| 9 | +If you encounter any issues, please open an issue at the new location. |
0 commit comments