Before I came to EPAM, I visited about 20 interviews at St. Petersburg IT companies, and many were given tasks. I synthesized my experience and came up with five tasks that are similar to those that are given on online testing and face-to-face interviews.
On May 19-20, a DotNext conference was held in St. Petersburg, where we invited participants to complete a quest, which consisted of these tasks. Responding correctly to the task, the participant received the following. ')
Juniors can cope with the first three, they are often asked similar questions at interviews. The fourth one can be set to anyone, but I would count on middle-level specialists: not all juniors understand the increasing complexity of algorithms.
The fifth task handled units. Its complexity is not to calculate what will be in the select (many have coped with it), but to find the next number in the sequence, and this requires good mathematical knowledge. It seems to me that the mathematical base is very important for a programmer.
The conference participants approached and asked how to solve problems and where to see their complete list, and I promised that I would post them here. The correct answers and comments are hidden so that those who see the tasks for the first time can solve them without prompts.
So, let's begin. 1) What result will this program display on the console?
classProgram { staticvoidMain(string[] args) { var numbers = newint[] { 7, 2, 5, 5, 7, 6, 7 }; var result = numbers.Sum() + numbers.Skip(2).Take(3).Sum(); var y = numbers.GroupBy(x => x).Select(x => { result += x.Key; return x.Key; }); Console.WriteLine(result); } }
Answer
56. Consider the features of LINQ.Binary representation: 111,000.
Comment
Such tasks are often given at interviews. If we talk about the quest, then the correct answer was given by about 80% of the participants. The most common mistake - people did not notice that there is a pending query execution. You can read more about it here .
2) What result will this program display on the console?
200. We take into account the specifics of finally.Binary representation: 11001000.
Comment
Himself faced with a similar question at the interview. If we talk about the participants of the quest, about 70% were able to answer correctly. They left feedback and suggestions, among which - to reduce the amount of excess code. We discussed this and came to the conclusion that it is still better to reduce the readability of the code for artificially misleading.
3) What result will this program display on the console?
classMagicValue { publicint Left { get; set; } publicint Right { get; set; } publicMagicValue(int left, int right) { Left = left; Right = right; } publicstaticvoidApply(MagicValue magicValue) { magicValue.Left += 3; magicValue.Right += 4; magicValue = new MagicValue(5, 6); } publicstaticvoidApplyRef(ref MagicValue magicValue) { magicValue.Left += 7; magicValue.Right += 8; magicValue = new MagicValue(9, 10); } } classProgram { staticvoidMain(string[] args) { var magicValue = new MagicValue(1, 2); MagicValue.ApplyRef(ref magicValue); MagicValue.Apply(magicValue); Console.WriteLine(magicValue.Left * magicValue.Right); } }
Answer
168. We take into account the features of ref.Binary representation: 10,101,000.
Comment
This is a very popular question at the interviews. I myself solved a similar problem, probably, on every second. On this topic you can read here . By the way, only 45% of the quest participants were able to find the right solution. Often mistakes were not in understanding the principle of ref, but in mathematics.
4) Given 9 functions. Each function corresponds to a number from 1 to 9. Arrange the functions in order of increasing complexity, then substitute 9 numbers of sorted functions sequentially in the _ _ _ _ _ _ _ + _ _ = = formula? Write what "?" Equals.
Such a task is less common at interviews, but this is a good start for those who study the complexity of algorithms. There are many resources with formulas, and finding them is easy. In addition, the problem can be solved by “substitution” on paper. At the interview may ask a question related to the complexity of some algorithms, and it's great when the answer is supported by general knowledge. If we talk about the quest, only 30% of the participants coped with the task.
5) Let the carTable table contain the following values:
id
model
price
one
Nissan
1000
2
BMW
2000
3
Toyota
1000
four
Renault
2000
five
Peugeot
1000
6
Opel
2000
The result of the SQL query below is 2 values - <1> and <2>.
;WITH someTable AS (SELECT1 val UNION ALL SELECT val + 1FROM someTable WHERE val BETWEEN1AND3) SELECT carTable.price / SUM(CASEWHEN carTable.price = 1000THEN1ELSE2END) / 250ASresultFROM someTable INNERJOIN carTable ON carTable.id = someTable.val GROUPBY carTable.price ORDERBY carTable.price ASC
<1> and <2> are the first numbers of the sequence <1>, <2>, 6, 34, 270, <?>. Find the next sequence number.
Answer
2698. Binary representation: 101010001010. Decision: The result of the query will be numbers 2 and 2 (BETWEEN will give a sample of 1,2,3,4. Join will work for the first 4 records, GROUP BY will group them, SELECT will be calculated as , . The sequence is calculated as where - the number of items already received. Those.:
Comment
This is by far the most difficult task. Only 15% of the quest participants coped with it.
Conclusion
Thanks to everyone who solved problems, and especially to those who could reach the end! It was interesting to read your reviews and comments. And those who carefully read the conditions and gave answers in binary form - doubly well done!
Photo taken from the archives of the conference DotNext.