0% found this document useful (0 votes)
351 views11 pages

Take - Home - Test 1

Test de investigación

Uploaded by

Karina Alvarez
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
351 views11 pages

Take - Home - Test 1

Test de investigación

Uploaded by

Karina Alvarez
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as PDF, TXT or read online on Scribd
You are on page 1/ 11

Beginning October 1, 2022, the Codility platform will no longer support your browser version.

Continue using Codility with supported browsers.

Alejandra García Román


Candidate Session Status: completed
E-mail: ID: SCAUQA-S7M Invitation: sent
[email protected] Time limit: 75 min. Created on: 2022-09-22 23:14 UTC
Report recipients: Started on: 2022-09-25 17:18 UTC
[email protected] Finished on: 2022-09-25 18:32 UTC
Accessed from: 189.203.192.41,
189.203.192.41
Invited by: [email protected]

 Notes:
N/A

Similarity Check
Status: not found
No similar solutions have been detected.

Test score

13%
Tasks in test Score Impact
1 McqMssql1 59% Low
Submitted in: Multiple-choice questions

2 SqlCardPayments 0% Regular
Submitted in: SQL (PostgreSQL)

3 ABString 0% Low
Submitted in: Python

Tasks Details
MX Data ETL - Python – Alejandra García Román – task 1 of 3

1. McqMssql1 Task Score Correctness Performance


Easy

A set of easy questions about Microsoft SQL Server and T-SQL. 59 Not assessed Not assessed

Candidate's answers Result

Question 1 Correct answers 4/4

You have written the following SQL query, which calculates the total value of each customer’s orders:

SELECT CustomerId, SUM(OrderValue) AS Total


FROM dbo.Order
GROUP BY CustomerId

You need to modify this query in order to nd only those customers whose orders exceed a total value of 1000. How can you do that?

A: Add the following line after the line with the FROM statement:

WHERE OrderValue > 1000

B: Add the following line at the end of the query:

HAVING SUM(OrderValue) > 1000

C: Add the following line at the end of the query:

WHERE SUM(OrderValue) > 1000

D: Add the following line after the line with the FROM statement:

HAVING SUM(OrderValue) > 1000

Question 2 Correct answers 4/4

What is the maximum number of clustered indexes per table?

A: 1

B: 2

C: You can create as many clustered indexes as non-clustered indexes.

D: There is no limit.

Question 3 Correct answers 4/4

You want to concatenate the results of three queries into a single result set. Additionally, all duplicates should be removed. Which operator
will you use?

A: INTERSECT

B: UNION

C: UNION ALL

D: EXCEPT

Question 4 Correct answers 1/4

You wrote an INSERT statement that inserts data into a dbo.Order table with an auto-incremented/identity column. This column is called Id.
Now you need to read the value generated for the Id column for the row inserted by your INSERT statement. What should you do?

A: Use the SCOPE_IDENTITY function.


B: SELECT TOP(1) Id FROM dbo.Order ORDER BY Id ASC

C: SELECT TOP(1) Id FROM dbo.Order ORDER BY Id DESC

D: Add an OUTPUT clause to the INSERT statement.

Question 5 Correct answers 3/4

You need to convert an expression of one type into another type. However, if a conversion is not possible, you do not want an error to be
raised. Which function can you use?

A: CAST

B: TRY_CAST

C: CONVERT

D: TRY_CONVERT

Question 6 Correct answers 4/4

How can you effectively nd the list of all triggers at the table level de ned in a given database?

A: You can use SQL Server Management Studio to browse all the tables one by one and, for each table, check if there are any triggers

de ned.

B: You can write a query based on sys.triggers.

C: You can use a SHOW TRIGGERS statement.

D: You can call the system function GET_TRIGGERS.

Question 7 Correct answers 3/4

You wrote a script that creates a stored procedure. It begins as follows:

CREATE PROCEDURE dbo.deleteOrder ( @OrderId INT )


AS
SET NOCOUNT ON
...

The problem is that it can only be executed once; i.e. if you try to execute it more than once, an error informing you that a given stored
procedure already exists will be raised. How would you x this issue so that the script can be executed once, twice or many times?

A: Change the rst line of the script to:

ALTER PROCEDURE …

B: Add the following code at the beginning of the script:

IF OBJECT_ID ( 'dbo.deleteOrder', 'P' ) IS NOT NULL


DROP PROCEDURE dbo.deleteOrder
GO

C: Add the following code at the beginning of the script:

DROP PROCEDURE dbo.deleteOrder


GO

D: Add the following code at the beginning of the script:

IF EXISTS(SELECT 1 FROM sys.procedures WHERE Name = 'deleteOrder')


DROP PROCEDURE dbo.deleteOrder
GO

Correct answers 4/5


Correct answers 4/5
Question 8
You have written the following query, which counts the number of orders for each customer:

SELECT c.CustomerId, COUNT(1) AS NoOfOrders


FROM dbo.Customer AS c
INNER JOIN dbo.Order AS o ON c.CustomerId = o.CustomerId
GROUP BY c.CustomerId

The problem is that it does not return customers that have no orders. How would you x this problem?

A: Replace INNER JOIN with RIGHT JOIN.

B: Replace INNER JOIN with LEFT JOIN.

C: Replace INNER JOIN with LEFT OUTER JOIN.

D: Replace INNER JOIN with CROSS JOIN.

E: Replace INNER JOIN with RIGHT OUTER JOIN.

Question 9 Correct answers 4/4

You are working with a database that is case insensitive. You would like to change it so that all operations are case sensitive. What should
you do?

A: It is not possible. MSSQL Server is designed to be case insensitive.

B: You need to change the collation at the database level. You can do that with an ALTER DATABASE COLLATE statement.

C: This option is set when a database is created and cannot be changed later on.

D: You need to change the collation at the table level. For each table in a database you need to execute an ALTER TABLE COLLATE

statement.

Question 10 Correct answers 2/5

You started a new transaction:

BEGIN TRANSACTION

Then you executed the following script:

CREATE TABLE dbo.Temp...


INSERT INTO dbo.Order VALUES...
DELETE FROM dbo.Order WHERE OrderId > 100

In the end, you decided to roll back the transaction. What is the nal effect?

A: The INSERT and DELETE statements will be rolled back, but a new table will have been created in the database.

B: The rollback will not succeed because DML and DDL statements have been mixed in the script.

C: Both DML and DDL statements will be rolled back.

D: All three statements will be rolled back.

E: Only the table creation statement will be rolled back.

Solution See Live Version

Programming language used: Multiple-choice questions

Total time used: 10 minutes


Effective time used: 10 minutes

Notes: not de ned yet


MX Data ETL - Python – Alejandra García Román – task 2 of 3

2. SqlCardPayments Task Score Correctness Performance


Hard

Given the history of transactions in a bank account, compute the nal balance taking the credit
card fee into account. 0 0 Not assessed

Task description

You are given a history of your bank account transactions for the year 2020. Each transaction was either a credit card payment or an incoming
transfer.

There is a fee for holding a credit card which you have to pay every month. The cost you are charged each month is 5. However, you are not charged
for a given month if you made at least three credit card payments for a total cost of at least 100 within that month. Note that this fee is not included
in the supplied history of transactions.

At the beginning of the year, the balance of your account was 0. Your task is to compute the balance at the end of the year.

You are given a table transactions with the following structure:

create table transactions (


amount integer not null,
date date not null
);

Each row of the table contains information about a single transaction: the amount of money (amount) and the date when the transaction
happened (date). If the amount value is negative, it is a credit card payment. Otherwise, it is an incoming transfer. There are no transactions with
an amount of 0.

Write an SQL query that returns a table containing one column, balance. The table should contain one row with the total balance of your account
at the end of the year, including the fee for holding a credit card.

Examples:

1. Given table:

+--------+------------+
| amount | date |
+--------+------------+
| 1000 | 2020-01-06 |
| -10 | 2020-01-14 |
| -75 | 2020-01-20 |
| -5 | 2020-01-25 |
| -4 | 2020-01-29 |
| 2000 | 2020-03-10 |
| -75 | 2020-03-12 |
| -20 | 2020-03-15 |
| 40 | 2020-03-15 |
| -50 | 2020-03-17 |
| 200 | 2020-10-10 |
| -200 | 2020-10-10 |
+--------+------------+

your query should return:

+---------+
| balance |
+---------+
| 2746 |
+---------+

The balance without the credit card fee would be 2801. You are charged a fee for every month except March, which in total equates to 11 * 5 = 55.

In March, you had three transactions for a total cost of 75 + 20 + 50 = 145, thus you are not charged the fee. In January, you had four card
payments for a total cost of 10 + 75 + 5 + 4 = 94, which is less than 100; thus you are charged. In October, you had one card payment for a total
cost of 200 but you need to have at least three payments in a month; thus you are charged. In all other months (February, April, ...) you had no card
payments, thus you are charged.

The nal balance is 2801 - 55 = 2746.

2. Given table:
+--------+------------+
| amount | date |
+--------+------------+
| 1 | 2020-06-29 |
| 35 | 2020-02-20 |
| -50 | 2020-02-03 |
| -1 | 2020-02-26 |
| -200 | 2020-08-01 |
| -44 | 2020-02-07 |
| -5 | 2020-02-25 |
| 1 | 2020-06-29 |
| 1 | 2020-06-29 |
| -100 | 2020-12-29 |
| -100 | 2020-12-30 |
| -100 | 2020-12-31 |
+--------+------------+

your query should return:

+---------+
| balance |
+---------+
| -612 |
+---------+

The balance excluding the fee would be -562. You are not charged the fee in February since you had four card payments for a total cost of 50 + 1 +
44 + 5 = 100 in that month. You are also not charged the fee in December since you had three card payments for a total cost of 100 + 100 + 100 =
300. The nal balance is -562 - 10 * 5 = -612.

3. Given table:

+--------+------------+
| amount | date |
+--------+------------+
| 6000 | 2020-04-03 |
| 5000 | 2020-04-02 |
| 4000 | 2020-04-01 |
| 3000 | 2020-03-01 |
| 2000 | 2020-02-01 |
| 1000 | 2020-01-01 |
+--------+------------+

Your query should return:

+---------+
| balance |
+---------+
| 20940 |
+---------+

You earned 21000 but you are charged a fee for every month. The nal balance is 21000 - 12 * 5 = 20940.

Assume that:

column date contains only dates between 2020-01-01 and 2020-12-31;


column amount contains only non-zero values.

Copyright 2009–2022 by Codility Limited. All Rights Reserved. Unauthorized copying, publication or disclosure prohibited.

Solution See Live Version

Programming language used: SQL (PostgreSQL)

Total time used: 46 minutes

Effective time used: 46 minutes


Notes: not de ned yet

Source code

Code: 18:13:02 UTC, sql-postgres, nal, score: 0

1-- write your code in PostgreSQL 9.4


2
3select sum() from (
4select
5case
6when num_trans > 3 and (sum(test) * -1) > 100
7then sum (test) + num_trans * 5
8
9from
10(SELECT
11sum (amount) test,
12count (amount) num_trans,
13extract (month from date)
14from transactions
15where amount < 0
16group by extract (month from date)
17)
18union all
19select sum(amount) test from transactions
20where amount >10
21)

Analysis summary
The following issues have been detected: runtime errors.

For example, for the input [] the solution terminated unexpectedly.

Analysis

Example tests
example1 ✘ RUNTIME ERROR
First example test. tested program terminated with exit code 1

example2 ✘ RUNTIME ERROR


Second example test. tested program terminated with exit code 1

example3 ✘ RUNTIME ERROR


Third example test. tested program terminated with exit code 1

Correctness tests
corner_case ✘ RUNTIME ERROR
Zero or one transaction. tested program terminated with exit code 1

handwritten_tests ✘ RUNTIME ERROR


Small handwritten tests. tested program terminated with exit code 1

random ✘ RUNTIME ERROR


Randomly generated tests. tested program terminated with exit code 1

one_month_only ✘ RUNTIME ERROR


All transactions occurred within one month. tested program terminated with exit code 1

payments_only ✘ RUNTIME ERROR


All transactions were card payments. tested program terminated with exit code 1

no_fee_each_month ✘ RUNTIME ERROR


There is no fee charged for any month. tested program terminated with exit code 1

fee_every_month ✘ RUNTIME ERROR


The fee is charged for every month. tested program terminated with exit code 1

edge_cases ✘ RUNTIME ERROR


Maximal edge tests. tested program terminated with exit code 1
zero_balance ✘ RUNTIME ERROR
The nal balance, excluding a fee, is equal to 0. tested program terminated with exit code 1
MX Data ETL - Python – Alejandra García Román – task 3 of 3

3. ABString Task Score Correctness Performance


Easy

Check, whether in a given string all letters 'a' occur before all letters 'b'. 0 0 0

Task description

Write a function solution that, given a string S consisting of N letters 'a' and/or 'b' returns True when all occurrences of letter 'a' are before all
occurrences of letter 'b' and returns False otherwise.

Examples:

1. Given S = "aabbb", the function should return True.

2. Given S = "ba", the function should return False.

3. Given S = "aaa", the function should return True. Note that 'b' does not need to occur in S.

4. Given S = "b", the function should return True. Note that 'a' does not need to occur in S.

5. Given S = "abba", the function should return False.

Write an e cient algorithm for the following assumptions:

N is an integer within the range [1..300,000];


string S consists only of the characters "a" and/or "b".

Copyright 2009–2022 by Codility Limited. All Rights Reserved. Unauthorized copying, publication or disclosure prohibited.

Solution See Live Version

Programming language used: Python

Total time used: 20 minutes

Effective time used: 20 minutes

Notes: not de ned yet

Source code

Code: 18:32:44 UTC, py, nal, score: 0

1# you can write to stdout for debugging purposes, e.g.


2# print("this is a debug message")
3
4def solution(S):
5 # write your code in Python 3.6
6
7 for s
8 if s[1] ='b' s[1] ='a' or and len(s) =1
9 True
10 exit
11 else
12 if s[i] = 'a' and s[i-1] ='a'
13 True
14 else
15 if s[i-1] = 'b' and s[i] ='a'
16 false
17 exit
18 pass
Analysis summary
The following issues have been detected: runtime errors.

For example, for the input 'b' the solution terminated unexpectedly.

Analysis

Example tests
example1 ✘ RUNTIME ERROR
First example test. tested program terminated with exit code 1

example2 ✘ RUNTIME ERROR


Second example test. tested program terminated with exit code 1

example3 ✘ RUNTIME ERROR


Third example test. tested program terminated with exit code 1

example4 ✘ RUNTIME ERROR


Fourth example test. tested program terminated with exit code 1

example5 ✘ RUNTIME ERROR


Fifth example test. tested program terminated with exit code 1

Correctness tests
one_letter ✘ RUNTIME ERROR
Strings with only one character repeated N times. tested program terminated with exit code 1

rst ✘ RUNTIME ERROR


Strings that detect if solution omits rst character. tested program terminated with exit code 1

last ✘ RUNTIME ERROR


Strings that detect if solution omits last character. tested program terminated with exit code 1

true ✘ RUNTIME ERROR


Strings with positive answer (aaa..ab..bbb). tested program terminated with exit code 1

swapped ✘ RUNTIME ERROR


Strings in form 'bbb..ba..aaa'. tested program terminated with exit code 1

ip ✘ RUNTIME ERROR
Strings in form 'aaa..abbb..b' with ipped letters on some substring. tested program terminated with exit code 1

alteration ✘ RUNTIME ERROR


Strings where 'a's and 'b's interlace. tested program terminated with exit code 1

anti_random ✘ RUNTIME ERROR


Strings in form 'aaa..abab..bbb'. It is hard to determine the answer by taking random pairs tested program terminated with exit code 1
of indices.

tiny_di cult ✘ RUNTIME ERROR


N <= 20. Score x 2. tested program terminated with exit code 1

Performance tests
small_random ✘ RUNTIME ERROR
Random strings. N <= 1000. tested program terminated with exit code 1

small_di cult ✘ RUNTIME ERROR


N <= 1000. tested program terminated with exit code 1

medium_random ✘ RUNTIME ERROR


Random strings. N <= 100'000. tested program terminated with exit code 1

medium_di cult ✘ RUNTIME ERROR


N <= 100'000. Score x 2. tested program terminated with exit code 1

large_random ✘ RUNTIME ERROR


Random strings. N <= 300'000. tested program terminated with exit code 1

big_di cult ✘ RUNTIME ERROR


N <= 300'000. Score x 2. tested program terminated with exit code 1

You might also like