📜 ⬆️ ⬇️

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

We selected the questions and tasks encountered by candidates for interviews with leading IT companies in the world.

KDPV

The selection includes tasks assigned to the position of engineer-developer at the interviews. Tasks of various levels of complexity, ranging from simple. We suggest you try your hand and try to solve the problems yourself - then the questions at the interview are unlikely to take you by surprise.

Questions


  1. 2 kind of pills
    You need to take care of your health care. Dissolving them in water.
    ')
    The man has a jar of pills and a jar of b pills. One day, he takes a pill from a jar of water. Then he accidentally takes out the water from the water. There are two pills, one pill and one pill. Unfortunately, the pills are thrown out of the question. How was the quantity of A and B?

    Transfer
    According to medical indications, one patient needs to take two medicines, A and B, and you need to take exactly 1 tablet A and 1 tablet B daily. Tablets are taken in dissolved form.

    The patient has a flask with A and a flask with B. Once, having dissolved tablet A in a glass, he threw 2 tablets from a flask with B there and got a glass with a solution of 1 A and 2 B. Unfortunately, the medicines are expensive, so he discarded the thought Pour this solution and prepare a new one. How can this patient continue taking the prescribed medication without losing any pills?

  2. Avg salary
    Three Employees want to know the average of their salaries. Individual salaries. How can they calcalate average salary?

    Transfer
    Three employees want to know the average salary (among them three), despite the fact that they are forbidden to voice individual wages. How do they calculate the average s / n?


Tasks


  1. Possible compositions of a natural number

    The number of natural numbers can be expressed. Two sequences are different.

    Examples:

    Input: 4
    Output: 8
    Explanation
    All 8 position composition are:
    4, 1 + 3, 3 + 1, 2 + 2, 1 + 1 + 2, 1 + 2 + 1, 2 + 1 + 1 and 1 + 1 + 1 + 1

    Input: 8
    Output: 128

    Transfer
    Given a natural number n, write a program to search for the number of combinations of numbers, the sum of which gives the result n, taking into account the order. Two sequences that differ in order are considered different combinations.

    Examples:

    Login: 4
    Output: 8
    Explanation: 4, 1 + 3, 3 + 1, 2 + 2, 1 + 1 + 2, 1 + 2 + 1, 2 + 1 + 1 and 1 + 1 + 1 + 1

  2. Count numbers that don't contain 3
    The number of numbers in the decimal representation.

    Examples:

    Input: n = 10
    Output: 9

    Input: n = 45
    Output: 31
    // Numbers 3, 13, 23, 30, 31, 32, 33, 34,
    // 35, 36, 37, 38, 39, 43 contain digit 3.

    Input: n = 578
    Oupt: 385


    Transfer
    Given the number n. Write a program that will count the number of numbers that do not contain 3 in decimal notation from 1 to n.

    Examples:

    Input: n = 10
    Output: 9

    Input: n = 45
    Output: 31
    // Numbers 3, 13, 23, 30, 31, 32, 33, 34,
    // 35, 36, 37, 38, 39, 43 contain 3.

    Input: n = 578
    Output: 385

  3. Boolean Array Puzzle
    Write a program according to the following specifications:

    Input: A array arr [] of two elements having value 0 and 1
    Output: Make both elements 0.

    Requirements: Following are specifications to follow.

    1) It’s guaranteed that you’re not aware of its position.
    2) We can't say about another element.
    3) We can only complete the elements of, multi, division,…. etc.
    4) We can't use if, else and loop constructs.
    5) Obviously, can't get directly from 0 to array elements.

    Transfer
    Write a program that meets the following requirements:

    Input: arr [] array of 2 elements with possible values ​​of 1 or 0
    Output: Make both elements equal to 0

    Requirements:
    1) It is known that one element is equal to 0, but its position is unknown.
    2) About the second element, we can not say, it can be 0 or 1.
    3) We can only complement the elements of the array; no other operations such as or, and, multiplication, division, etc. are allowed.
    4) You can not use conditional constructions, cycles.
    5) You cannot explicitly write 0 to the elements of an array.


Answers will be given within the next week - have time to decide. Good luck!

Solutions


  1. Question 1
    The correct answer was given in the comments:
    You need to add another pill A to the glass, mix and drink half a glass, leaving half the next day.


  2. Question 2
    Many solutions have been proposed, one, for example, in this comment .

  3. Task 1
    The right solution was also found in the comments.
    By a small analysis, you can find out and prove that the number of combinations is 2 n-1 .

    #include<iostream> using namespace std; #define ull unsigned long long ull countCompositions(ull n) { // Return 2 raised to power (n-1) return (1L) << (n-1); } // Driver Code int main() { ull n = 4; cout << countCompositions(n) << "\n"; return 0; } 


  4. Task 2
    Recursive solution:
     #include <stdio.h> /* returns count of numbers which are in range from 1 to n and don't contain 3 as a digit */ int count(int n) { // Base cases (Assuming n is not negative) if (n < 3) return n; if (n >= 3 && n < 10) return n-1; // Calculate 10^(d-1) (10 raise to the power d-1) where d is // number of digits in n. po will be 100 for n = 578 int po = 1; while (n/po > 9) po = po*10; // find the most significant digit (msd is 5 for 578) int msd = n/po; if (msd != 3) // For 578, total will be 4*count(10^2 - 1) + 4 + count(78) return count(msd)*count(po - 1) + count(msd) + count(n%po); else // For 35, total will be equal to count(29) return count(msd*po - 1); } // Driver program to test above function int main() { printf ("%d ", count(578)); return 0; } 


  5. Task 3
    The correct answer is suggested in the comments.

Source: https://habr.com/ru/post/350300/


All Articles