Skip to content

Instantly share code, notes, and snippets.

@wardbeyens
Created January 16, 2023 11:14
Show Gist options
  • Save wardbeyens/ff7cf82e7cd571a8523d4464f2dd11b0 to your computer and use it in GitHub Desktop.
Save wardbeyens/ff7cf82e7cd571a8523d4464f2dd11b0 to your computer and use it in GitHub Desktop.

Technical Trial

This document was created to learn from my mistakes. My final score was 5/12, of this I was shocked. With this document, I am trying to see where and how I answered incorrectly.

Question 1 (Correct)

Sophie = 4;
Bart = 3 * Sophie + 4; // 16
Marie = 10 + Sophie - (Sophie + Bart / 2);
// 10 + 4 - (4 + 16 / 2) = 14 - (4 + 8) = 14 - 12 = 2

Marie = 2;

Answer: Marie = 2

Question 2 (Correct)

8 + John * 10 - 6 / 2 + John = 49

8 + John * 10 - 3 + John = 49
11 John = 49 - 8 + 3
11 John = 44
John = 4

Answer: John = 4

Question 3 (Wrong)

How many times will ProcessA be executed in this code?

Count = 1
Repeat
    ProcessA()
    Count = Count + 2
Until Count = 8

Answer: 4

Answers:

Answers Solution
0
1
4
7
Non of the above True

Why am i wrong?

I'd read it as greater than or equal to.

Loops forever because Count is never an even number.

Question 4 (Wrong)

Function ABC(message, X)
    If x = 0
        message = message & "0"
    Else
        message = message & ABC(message, x - 1)
    End
    Return message
End Function

What would be the resulting value of "message" when we execute the following code?

message = ""
y = 5
message = ABC(message, y)

My answer: "000000"

Thoughts:

  1. This is a recursive function with base case: message & "0" so the base case is "0"

  2. (message & (message & (message & (message & (message & "0")))))

  3. "000000"

Why am i wrong?

A counting error. Because the base case is message & "0" which results in "0",but I still took the message from the base case into my calculations.

The resulting value of "message" would be the string "00000", as the function ABC is recursively appending the character "0" to the "message" string, and the input value for "x" is 5, so it will append "0" to the "message" string 5 times.

message = ABC(message, y) = ABC("", 5) = ABC("0", 4) = ABC("00", 3) = ABC("000", 2) = ABC("0000", 1) = ABC("00000", 0) = "00000"

Question 5 (Wrong)

You get
- an array of numbers (e.g. {1,7,5,3,9})
- and a given number (e.g. 10)

The function FindPair needs to find the pair of numbers from that array:
- of which the sum is equal to the given number
- and that are the closest (positions) to each other in that array.

In the example case, the result is 7 and 3.
FYI 1 and 9 are also equal to 10, but they are further away from each other in the array compared to 7 and 3.

What has to come at ###XXX###?

`
Function FindPair(array Arr, int Sum){
    array Result;
    int Closest_Position = Arr.length;

    For(###XXX###){

        If(Arr[a]+Arr[b]==Sum){
            If(b-a < Closest_Position){
                Closest_Position = b-a;
                Result[0] = Arr[a];
                Result[1] = Arr[b];
            }
        }
    }
}

Answer: b = a; b < Arr.length; b++ correct answer: b = a + 1; b < Arr.length; b++

Why am i wrong?

A loop inside a loop. 'a' will be the first number in the pair and b will be the second. The outer loop will iterate through the array, starting at the first element, and the inner loop will check each number after the outer loop's current index to see if it is equal to the Sum.

Explanation

The function FindPair() takes in two inputs, an array Arr and an integer Sum. It also initializes an array Result and an integer Closest_Position which is set to the length of the input array.

The outer for loop starts at index 0 and continues until the second to last element of the array. It assigns the current index to the variable a.

The inner for loop starts at the next index after a (a+1) and continues until the last element of the array. It assigns the current index to the variable b.

Within the nested loops, the code checks if the sum of the elements at index a and b is equal to the input Sum.

If the sum is equal to the input Sum, the code then checks if the difference between the indices of b and a is less than the current value of Closest_Position.

If the difference is less than the current value of Closest_Position, the value of Closest_Position is updated to the current difference, and the elements at index a and b are assigned to the first and second elements of the Result array, respectively.

After the nested loops have finished running, the Result array will contain the closest pair of elements whose sum is equal to the input Sum.

Note that the return statement is missing in the code. The function should return the Result array for the caller to use.

It's also worth noting that depending on the size of the array and the number of potential pairs, this code will have a time complexity of O(n^2) which can be quite slow for large arrays.

Example

I can provide an example of how the code would execute with the input array of {1,7,5,3,9} and the input number of 10:

  1. The function FindPair() is called with the input array {1,7,5,3,9} and the input number 10.
  2. The Result array is initialized as an empty array and the Closest_Position variable is set to the length of the input array, 5.
  3. The outer loop starts with a = 0 and Arr[a] = 1
  4. The inner loop starts with b = 1 and Arr[b] = 7
  5. The code checks if Arr[a] + Arr[b] = 1 + 7 = 8, which is not equal to the input Sum of 10, so the inner loop continues with b = 2 and Arr[b] = 5
  6. The code checks if Arr[a] + Arr[b] = 1 + 5 = 6, which is not equal to the input Sum of 10, so the inner loop continues with b = 3 and Arr[b] = 3
  7. The code checks if Arr[a] + Arr[b] = 1 + 3 = 4, which is not equal to the input Sum of 10, so the inner loop continues with b = 4 and Arr[b] = 9
  8. The inner loop has completed and a is incremented to 1.
  9. The inner loop starts with b = 2 and Arr[b] = 5
  10. The code checks if Arr[a] + Arr[b] = 7 + 5 = 12, which is not equal to the input Sum of 10, so the inner loop continues with b = 3 and Arr[b] = 3
  11. The code checks if Arr[a] + Arr[b] = 7 + 3 = 10, which is equal to the input Sum of 10.
  12. The code checks if b - a = 3 - 1 = 2 is less than the current value of Closest_Position = 5, so it updates Closest_Position to 2, and assigns Arr[a] = 7 and Arr[b] = 3 to the first and second elements of the Result array, respectively.
  13. The inner loop continues but no other pair whose sum equal to 10 is found.
  14. The outer loop continues with a = 2, 3, and 4 and no other pair whose sum equal to 10 is found.
  15. The nested loops have finished running and the Result array contains the pair {7, 3} This is the output of the function, the closest pair of elements whose sum is equal to the input Sum.

Question 6 (Correct)

You receive the following 2 excel spreadsheet files (See image).
With hundreds of records
You need to determine which customers are present in both spreadsheets. how would you do this? which excel formula would you use?

- match()
- index()
- vlookup()

Answer: vlookup()

The best Excel formula to use in this situation would be the "VLOOKUP" formula. VLOOKUP allows you to search for a specific value in a table and return a corresponding value from a different column.

Here's an example of how you would use VLOOKUP to determine which customers are present in both spreadsheets:

Assign a unique identifier to each customer, such as a customer ID or email address. In the first spreadsheet, create a new column with a heading of "Unique ID" and fill in the appropriate customer IDs. In the second spreadsheet, also create a new column with the heading "Unique ID" and fill in the appropriate customer IDs. In a new sheet, create a new column with the heading "Customer ID" and use the VLOOKUP formula to search for the customer ID in both spreadsheets. The formula should look something like this: =VLOOKUP(A2, Sheet1!A:B, 2, FALSE) where A2 is the cell containing the customer ID you are searching for, Sheet1!A:B is the range of cells in the first spreadsheet that contains the customer IDs, 2 is the column number of the corresponding customer name, and FALSE specifies an exact match. Repeat the VLOOKUP formula for the second spreadsheet. You can use conditional formatting to highlight the matched ID. By doing this, you will have a list of customers that are present in both spreadsheets, with the customer name next to the matched ID.

Question 7 (Correct)

Which tag (text) should be put at "..." to end this XML text properly?
<ProcessingInformation>
    <Program>06/08/2018</Program>
    <StartTime>17:52:58</StartTime>
    <StopTime>17:53:05</StopTime>
    <Status>SUCCESS</Status>
...

Answer: </ProcessingInformation>

Question 8 (Correct)

After this execution, what is the final value of i?
NB: Modulo function return the remainder of the devision

tab is an array of 5 integers
int i = 0;

tab[0]= 10;
tab[1]= 4;
tab[2]= 3;
tab[3]= 1;
tab[4]= 5;

For j = 0 to 4
if mod(j,2) = 0 then i = i + tab[j]
end for

Answer: 18

The final value of i would be 18. The for loop iterates through the values of j from 0 to 4 and if the remainder of j divided by 2 is 0, it adds the corresponding value in the tab array to i. So it would add tab[0] (10), tab[2] (3), and tab[4] (5) to i, resulting in a final value of 10 + 3 + 5 = 18.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment