Uploaded by Jordhan Carvalho

LeanonSystems Logicsandprogramming

advertisement
Leanon Systems
Recruitment Process
Technical test: Logics and Programing
Part 1 – Mathematics and Logic
1 - A group of friends at a party drink soda or beer. Thirteen friends drink soda, ten drink
beer, and five drink soda and beer. How many friends are present at the party?
Answer:
The problem states that the group of friends at the party only drinks soda or beer. With that in
mind, we can assume that the five friends who drink both soda and beer actually choose one
or the other, but not both at the same time. So, we have 13 friends who drink soda, 10 friends
who drink beer, and 5 friends who drink either soda or beer, which would be included in one
of the first two groups. Therefore, the total number of friends is 13 (soda) + 10 (beer),
resulting in a total of 23 friends.
2 - Sarah assumes her watch is 5 minutes late, but it is actually 10 minutes early. Sarah
arrives for an appointment thinking she is 15 minutes late compared to the scheduled time.
When did she actually arrive? On time, late or early? In case she arrived early, by how many
minutes?
Answer:
She arrives at the exact time of the appointment. In this case, we have three time variables to
consider: the watch time, Sarah's perception of time, and the real-world time. Let's imagine
the appointment is scheduled for 00:00 (midnight) in the real-world time. If Sarah perceives
herself as being 15 minutes late (00:15), and she believes her watch is 5 minutes behind, we
find that the watch displays 00:10. However, since the watch is actually 10 minutes ahead of
the real time, the current real-world time remains at 00:00.
3 - A pizzeria carries out a promotion with the ad "Buy one and get another one for half the
price". A different promotion that offers the same discount percentage is:
(a) "Take two, pay one"
(b) "Take three and pay one"
(c) "Take three, pay two"
(x) "Take four and pay for three"
(e) "Take five, pay four"
4 - Lorenna's phone number has 8 digits, but Sarah only remembers the first four in the
correct order. Although she remembers the last four digits and knows that none of them
repeats, she has forgotten their order. What's the number of attempts Sarah can make
before she can get Lorenna's phone number right?
Answer:
24. Since she already knows the last 4 numbers, and none of them repeat, we can
easily find the number of possible arrangements using factorial notation. In this case,
we calculate 4! (4 factorial) as 4 × 3 × 2 × 1.
Part 2 - Programming
1 – A palindrome is a word that is symmetric: if we write it backward, the result word is the
same. For example, “HANNAH” is a palindrome, but “GAGA” is not. Write a short program
that
determines
whether
a
word
is
a
palindrome.
Answer:
This can be easily done by making the word case-insensitive and comparing it with its
reversed version. In JavaScript, we can utilize the built-in reverse method for arrays.
2 – A huge phone book containing pairs of the form {phone number, person's name} was
stored as a vector sorted by name in alphabetical order. Write a program that finds the
phone number of a given person in this list, bearing in mind that the list is very large and that
users need the search results to be as fast as possible.
Answer:
This is a classic scenario where a binary search can be used, given that the phonebook is
ordered. It provides an average time complexity of O(log n). In the event that the name is
not found in the phonebook, the binary search will return -1.
3 – Consider the following database schema:
TABLE
COLUMNS
SUPPLIER
PART
CAR
SUPPLY
SUPPLIER_CODE, SUPPLIER_NAME, CITY
CODE_PART, NAME_PART, PRICE
CODE_CAR, NAME_CAR, TYPE
CODE_SUPPLIER, CODE_PIECE, CODE_CAR
Write an SQL command that is able to query the suppliers located in the city named
“VITORIA” that provide the part code “MOTOR” for the car coded “KOMBI”, with their
respective prices.
Example:
SUPPLIER
PRICE
Supplier A
Supplier B
1,000
1,500
Answer:
To obtain the necessary information, we can efficiently achieve this by joining all the
necessary tables and subsequently applying appropriate filters.
4 - Your friend is developing a small image processing program and has asked for your help
in implementing MS-Paint's “paint bucket”-like functionality. Their program represents
images using arrays of characters, with each array value representing a pixel and letters and
symbols representing different colors. For example, the following 4x6 matrix represents the
letter P in color "#", with background color "." (dot)
.###..
.#..#.
.###..
.#....
Your subroutine should take a pixel and a new color and paint the region of that pixel with
the new color, like MS-Paint's “paint bucket” tool.
Examples:
Pixel (0,1) and new color 'O'
Before
.###..
.#..#.
.###..
.#....
After
.OOO..
.O..#.
.OOO..
.O....
Pixel (1,3) and new color 'o'
Before
.###.
.#..#.
.###.
.#....
After
.###..
.#oo#.
.###..
.#....
Pixel (1,3) and new color '#'
Before
.###..
.#..#.
.###..
.#....
After
.###..
.####.
.###..
.#....
Answer:
To address this problem, we will utilize a stack, which outperforms a queue in this
particular scenario, thanks to the JavaScript implementation of arrays using ArrayList.
Download