Issue # 38: IT training - current issues and challenges from leading companies

Hello! New week - new release of brandisers. This time, with interviews at IT company Accolite.

By the way, the answers to the problems from the previous issue have already been published , check yourself and your wit.

Well, let's go!

Questions


1. Rich or Poor
A place has two kinds of residents, Poor, who always tell the truth, and their opposites, Rich, who always lie. You encounter two people A and B. What are A and B if A says “B is a Poor” and B says “The two of us are opposite types”?

Transfer
: , , , . A B. A B, A «B — », B : « — »?

2. Boy with Marbles
A boy goes to 20 of his friend's houses with 'n' number of newly purchased marbles in his hands. At every house he visits, he gives away half of marbles he have and take one of his friend's marble's and adds it with the one's he is left with, he never had a problem of dividing an odd number of marbles left and finally after leaving the his 20th friends house, he is left with 2 marbles, can you guess the 'n' value?

Transfer
20 «n» . , , , , , . , , , 20 , 2 . «n»?

Tasks


1. Swap two nibbles in a byte
Given a byte, swap the two nibbles in it. For example 100 is be represented as 01100100 in a byte (or 8 bits). The two nibbles are (0110) and (0100). If we swap the two nibbles, we get 01000110 which is 70 in decimal.

Input:
The first line contains 'T' denoting the number of testcases. Each testcase contains a single positive integer X.

Output:
In each separate line print the result after swapping the nibbles.

Constraints: Example: Input: Output:
1 ≤ T ≤ 70
1 ≤ X ≤ 255




2
100
129



70
24

Transfer
, . , 100 01100100 ( 8 ). — (0110) (0100). , 01000110, 70 .

:
«», . X.

:
.

:
1 ≤ T ≤ 70
1 ≤ X ≤ 255


:
:

2
100
129


:
70
24

2. Count pairs with given sum
Given an array of integers, and an integer 'K', find the count of pairs of elements in the array whose sum is equal to 'K'.

Input:
First line of the input contains an integer T, denoting the number of test cases. Then T test cases follow. Each test case consists of two lines. First line of each test case contains 2 space separated integers N and K denoting the size of array and the sum respectively. Second line of each test case contains N space separated integers denoting the elements of the array.

Output:
Print the count of pairs of elements in the array whose sum is equal to the K.

Constraints: Example: Input Output
1<=T<=50
1<=N<=50
1<=K<=50
1<=A[i]<=100




2
4 6
1 5 7 1
4 2
1 1 1 1


2
6

Transfer
«K», , «K».

:
T, . T . . 2 N K, , . N , , .

:
, .

:
1< = T< = 50
1< = N< = 50
1< = K< = 50
1<=A[i]< = 100


:

2
4 6
1 5 7 1
4 2
1 1 1 1


2
6

3. Trie | (Insert and Search)
Trie is an efficient information retrieval data structure. Use this data structure to store Strings and search strings. Your task is to use TRIE data structure and search the given string A. If found print 1 else 0.

Input:
The first line of input contains a single integer T denoting the number of test cases. Then T test cases follow. Each test case consists of three lines.
First line of each test case consist of a integer N, denoting the number of element in a Trie to be stored.
Second line of each test case consists of N space separated strings denoting the elements to be stored in the trie.
Third line of each test case consists of a String A to be searched in the stored elements.

Output:
Print the respective output in the respective line.

Constraints: Example: Input: Output:
1<=T<=20
1<=N<=20




1
8
the a there answer any by bye their
the


1

Transfer
Trie — . . , TRIE A. , 1, — 0.

:
T, . T . .
N, TRIE, .
N , , , TRIE.
A, .

:
1 0 .

:
1< = T< = 20
1< = N< = 20


:
:

1
8
the a there answer any by bye their
the

:
1

Answers to the tasks will be given during the next week - have time to solve it. Good luck

All Articles