Learn proven strategies for increasing diversity on your engineering team 31 Aug

# Example CodeSignal questions for software engineering interviews Curious about the types of questions we design at CodeSignal? In this blog post, we’ll walk through a few examples. Ranging from simple to very challenging, they represent the kinds of questions that we design as part of our General Coding Framework for evaluating the core programming skills of early-career talent. We’ll explain what these questions assess for and describe a sample good solution for each.

## Question 1: Array Manipulation

Taking a look at this question, you can see that it covers a basic array traversal and manipulation. The candidate simply needs to return the sum of each value in a, plus its right and left neighbors.

At the same time, the question asks candidates to take into account corner cases with their implementation, which is an important fundamental skill. They need to correctly handle the first and last elements of the array.

### Question 1: Solution

Above is a simple 10-line implementation in Python. First, the solution gets the length of `a` and then creates a zeroed-out array `b` of the same length. Next, it uses a for loop to traverse through `b` and complete the operations as specified. Note that this solution handles the edge cases by checking if the `a` index is in range before adding the value to `b`.

## Question 2: String Pattern Matching

This is a pattern-matching question where instances of a pattern need to be found inside of a larger array. It has the advantage of testing several fundamental programming skills at once: traversing multiple arrays with nested loops, working with subarrays, and performing basic collections/string operations.

Note that the guaranteed constraints in this question indicate that the candidate shouldn’t worry about optimizing their solution.

### Question 2: Solution

In this solution, the candidate first defines the vowels. Then, they define a helper function, `check_for_pattern`, that their solution will call for every possible substring in `source`. For each character in the pattern string, the helper function checks if the character in the substring matches the pattern (`0` for vowel, `1` for consonant).

## Question 3: Two-Dimensional Array Traversal

This Tetris-inspired question is challenging. Candidates will have to traverse and manipulate two-dimensional arrays in a non-conventional way. As it’s an advanced question, it tests how well an engineer can understand a complex set of constraints and proceed with a non-trivial implementation.

## Question 3: Solution

This solution starts by defining some dimensions that will be important for the problem. Then, for every valid dropping position—that is, columns in `range(width - figure_size + 1)`—the code goes row by row, seeing how far the figure will go until it will “stop.”

To do this, it peeks at the next row and asks: can the figure fit there? If not, it stops at the previous row. The figure doesn’t fit if there is a 1 in the same place in both the figure and the field (offset by the row). The loop can stop when `row == height - figure_size + 1`, because then the bottom of the figure will have hit the bottom of the field.

Once the code figures out the last row the figure can drop to before it can’t fit anymore, it’s time to see if there’s a fully-filled row created anywhere. From where the figure “stopped,” the code iterates through the field and figure arrays row by row, checking to see if together, they’ve created a filled row. Cleverly, the code sets `row_filled = True` and then marks it `False` if one or both of these conditions are met:

• Any of the field cells in the row are empty (not `1`)
• Any of the figure cells in the row are empty (not `1`)

## Question 4: Lookup Table

This problem could be solved in a straightforward way by having two nested loops to choose each pair and check whether their sum is a power of two. But since the `numbers` array could be quite large, quadratic time complexity would be too much for this question. (To get more precise, it is O(`n2` * log(`MAX_NUMBER`)) where `MAX_NUMBER` is the largest number seen in the array.)

Therefore, this question tests whether candidates have the problem-solving and data structures skills to use a lookup table (hash set/dictionary) in their programming language of choice. It also involves a bit of tricky logic to avoid double-counting pairs. Finally, this question asks candidates to pay close attention to constraints, testing a key skill for real-world development.

### Question 4: Solution

This Python solution uses `collections.defaultdict` to create a dictionary of integers. For each element in the array, the element is first counted in the dictionary. Then, the loop checks for sums of all of the powers of two that are less than `221`. Why stop there? The constraint says that no element of the array can be greater than `106`, or 1,000,000. `221` is 2,097,152, which is greater than 1 million when divided by two, so there is no way that two elements could sum to `221`

To calculate the powers of two, the code uses a left shift bitwise operator: `1 << two_power` in Python is the same as `2two_power`. It defines `second_element` as the amount needed for the current element to sum to the power of two. Then it looks up the count for `second_element` in the dictionary. The number of `second_element`s already found in the array gets added to the answer, because this is the number of pairs (so far) that sum to that power of two. By the time it reaches the end of the array, this algorithm will have found all the pairs—in linear time.

In conclusion, we hope this has given you some insight into the kinds of technical interview questions we ask at CodeSignal. If you’re a hiring manager wanting to learn more about our skills evaluation frameworks and how we approach question design, schedule a discovery call with us today

Dmitry Filippov is the Technical Assessment Lead at CodeSignal, where he manages content development for all of CodeSignal’s technical assessments. He received his Master’s degree in Computer Science from ITMO University, and has been an active member of the International Collegiate Programming Contest community for over 10 years.