📜 ⬆️ ⬇️

Quest from EPAM: Five Tasks from .NET Interviews



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?

class Program { static void Main(string[] args) { var numbers = new int[] { 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?

  class Program { private static string GetNumber(int input) { try { throw new Exception(input.ToString()); } catch (Exception e) { throw new Exception((int.Parse(e.Message) + 3).ToString()); } finally { throw new Exception((++input).ToString()); } return (input += 4).ToString(); } static void Main(string[] args) { string result; try { result = GetNumber(1); } catch (Exception e) { result = e.Message; } Console.WriteLine(int.Parse(result) * 100); } } 

Answer
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?

  class MagicValue { public int Left { get; set; } public int Right { get; set; } public MagicValue(int left, int right) { Left = left; Right = right; } public static void Apply(MagicValue magicValue) { magicValue.Left += 3; magicValue.Right += 4; magicValue = new MagicValue(5, 6); } public static void ApplyRef(ref MagicValue magicValue) { magicValue.Left += 7; magicValue.Right += 8; magicValue = new MagicValue(9, 10); } } class Program { static void Main(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.

one. log(log(N))
2 N2/9
3 log(N)
four. N
five. 3n
6 90010,000,000
7 N!
eight. N3
9. Nlog(N)

Answer
1221. Binary representation: 10011000101.
Decision:
6 90010,000,000
one. log(log(N))
3 log(N)
2 N2/9
four. N
9. Nlog(N)
eight. N3
five. 3n
7 N!
6 1 3 - 2 4 9 + 8 5 7 = 1221

Comment
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:
idmodelprice
oneNissan1000
2BMW2000
3Toyota1000
fourRenault2000
fivePeugeot1000
6Opel2000

The result of the SQL query below is 2 values ​​- <1> and <2>.

 ;WITH someTable AS (SELECT 1 val UNION ALL SELECT val + 1 FROM someTable WHERE val BETWEEN 1 AND 3) SELECT carTable.price / SUM(CASE WHEN carTable.price = 1000 THEN 1 ELSE 2 END) / 250 AS result FROM someTable INNER JOIN carTable ON carTable.id = someTable.val GROUP BY carTable.price ORDER BY 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 1000/(1+1)/250=2, 2000/(2+2)/250=2. The sequence is calculated as xn+1=xn2n2where n- the number of items already received.
Those.:
2212=2
2222=6
6232=34
34242=270
270252=$269

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.

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


All Articles