CodeSignal Technical Assessment Coding Fundamentals 2 — Questions and Answers
Question 1: What is the time complexity of accessing an element by index in a dynamic array (like Python's list)?
- O(1) (Correct answer)
- O(log n)
- O(n)
- O(n²)
Correct answer: O(1)
Dynamic arrays store elements in contiguous memory, so index-based access is O(1) constant time.
Question 2: Which of the following correctly describes a stack data structure?
- First-In, First-Out (FIFO)
- Last-In, First-Out (LIFO) (Correct answer)
- Random access by index
- Sorted order by value
Correct answer: Last-In, First-Out (LIFO)
A stack follows LIFO: the last element pushed onto the stack is the first one popped off.
Question 3: Given the code snippet `x = [1, 2, 3]; y = x; y.append(4)`, what is the value of `x`?
- [1, 2, 3]
- [1, 2, 3, 4] (Correct answer)
- [4, 1, 2, 3]
- Error
Correct answer: [1, 2, 3, 4]
In Python, `y = x` creates a reference to the same list object, so mutating `y` also mutates `x`.
Question 4: What does a hash function guarantee when used in a hash table?
- Sorted output
- Unique keys only
- O(1) average-case lookup (Correct answer)
- No collisions
Correct answer: O(1) average-case lookup
Hash tables use a hash function to map keys to indices, providing O(1) average-case lookup time.
Question 5: In Python, what is the result of `bool([])` and `bool([0])`?
- False, False
- False, True (Correct answer)
- True, False
- True, True
Correct answer: False, True
An empty list is falsy in Python, but a list containing any element (even 0) is truthy.
Question 6: Which sorting algorithm has the best worst-case time complexity?
- Quick Sort
- Bubble Sort
- Merge Sort (Correct answer)
- Insertion Sort
Correct answer: Merge Sort
Merge Sort guarantees O(n log n) in all cases, whereas Quick Sort degrades to O(n²) in the worst case.
Question 7: What is the output of `print(3 // 2)` in Python 3?
- 1.5
- 2
- 1 (Correct answer)
- 0
Correct answer: 1
The `//` operator performs floor division, rounding down to the nearest integer, so 3 // 2 equals 1.
What is the time complexity of accessing an element by index in a dynamic array (like Python's list)?