
Задачи отобраны различного уровня сложности, начиная от очень простых. Но не все из них имеют очевидное, на первый взгляд решение, поиск которого поможет Вам держать мозг в тонусе, а кому-то, возможно, поможет не растеряться на собеседовании.
Вопросы
You have 20 white and 13 black balls in a bag. You pull out 2 balls one after another. If the balls are of same color, then you replace them with a white ball – but if they are of different color, you replace them with a black ball. Once you take out the balls, you do not put them back in the bag – so the balls keep reducing. What would be the color of the last ball remaining in the bag?
The man who delivers eggs to my home everyday, did not turn up one day. So when he came the next morning I demanded an explanation from him. He told me the following story:
The previous morning when he just came out of the house carrying a basket full of eggs on his head to start his daily rounds and stepped on to the street, a car going full speed brushed against him and knocked down his basket destroying all the eggs. The driver, however, a thorough gentleman admitted his responsibility and offered to compensate him for damages. But peddler could not remember the exact number of eggs he had, but he estimated the number at between 50 and 100. He was also able to tell the gentleman that if the eggs were counted by 2’s and 3’s at a time, none would be left, but if counted by 5’s at a time, 3 would remain, and that he sold the eggs at 10 cent a piece. The gentleman made some quick calculations and paid peddler adequately.
How much did the gentleman pay for eggs?
The previous morning when he just came out of the house carrying a basket full of eggs on his head to start his daily rounds and stepped on to the street, a car going full speed brushed against him and knocked down his basket destroying all the eggs. The driver, however, a thorough gentleman admitted his responsibility and offered to compensate him for damages. But peddler could not remember the exact number of eggs he had, but he estimated the number at between 50 and 100. He was also able to tell the gentleman that if the eggs were counted by 2’s and 3’s at a time, none would be left, but if counted by 5’s at a time, 3 would remain, and that he sold the eggs at 10 cent a piece. The gentleman made some quick calculations and paid peddler adequately.
How much did the gentleman pay for eggs?
Задачи
We are given a row wise sorted matrix of size r*c, we need to find the median of the matrix given. It is assumed that r*c is always odd.
Examples:
Input:
1 3 5
2 6 9
3 6 9
Output: Median is 5
If we put all the values in a sorted array A[] = 1 2 3 3 5 6 6 9 9
Input:
1 3 4
2 5 6
7 8 9
Output: Median is 5
Examples:
Input:
1 3 5
2 6 9
3 6 9
Output: Median is 5
If we put all the values in a sorted array A[] = 1 2 3 3 5 6 6 9 9
Input:
1 3 4
2 5 6
7 8 9
Output: Median is 5
Given a number N and a digit D, we have to form an expression or equation that contains only D and that expression evaluates to N. Allowed operators in expression are +, -, *, and /. Find the minimum length expression that satisfy the condition above and D can only appear in the expression at most 10(limit) times.
Examples:
Input: N = 7, D = 3
Output: 3/3+ 3 + 3
Explanation: 3/3 = 1, and 1+3+3 = 7
This is the minimum expression.
Input: N = 7, D = 4
Output: (4+4+4)/4 + 4
Explanation: (4+4+4) = 12, and 12/4 = 3 and 3+4 = 7
Also this is the minimum expression. Although
you may find another expression but that
expression can have only five 4's
Input: N = 200, D = 9
Output: Expression not found!
Explanation: Not possible within 10 digits.
Examples:
Input: N = 7, D = 3
Output: 3/3+ 3 + 3
Explanation: 3/3 = 1, and 1+3+3 = 7
This is the minimum expression.
Input: N = 7, D = 4
Output: (4+4+4)/4 + 4
Explanation: (4+4+4) = 12, and 12/4 = 3 and 3+4 = 7
Also this is the minimum expression. Although
you may find another expression but that
expression can have only five 4's
Input: N = 200, D = 9
Output: Expression not found!
Explanation: Not possible within 10 digits.
Given an array of n positive integers and a number k. Find the minimum number of swaps required to bring all the numbers less than or equal to k together.
Input: arr[] = {2, 1, 5, 6, 3}, k = 3
Output: 1
Explanation:
To bring elements 2, 1, 3 together, swap element '5' with '3' such that final array will be:
arr[] = {2, 1, 3, 6, 5}
Input: arr[] = {2, 7, 9, 5, 8, 7, 4}, k = 5
Output: 2
Input: arr[] = {2, 1, 5, 6, 3}, k = 3
Output: 1
Explanation:
To bring elements 2, 1, 3 together, swap element '5' with '3' such that final array will be:
arr[] = {2, 1, 3, 6, 5}
Input: arr[] = {2, 7, 9, 5, 8, 7, 4}, k = 5
Output: 2
Ответы будут даны в течение следующей недели — успейте решить. Удачи!
Источник: Хабрахабр