CodeSignal General Coding Assessment (GCA) — Questions and Answers
Question 1: Why can't a greedy ratio (value/weight) approach always find the optimal solution for 0/1 knapsack?
- It runs too slowly for large inputs
- Items must be sorted by weight instead
- It is always optimal for 0/1 knapsack
- Items cannot be fractionally selected, so the highest-ratio item may waste capacity (Correct answer)
Correct answer: Items cannot be fractionally selected, so the highest-ratio item may waste capacity
In 0/1 knapsack, items are taken whole, so a high-ratio item might leave unusable capacity that smaller items could fill better.
Question 2: Given an array of numbers from 1 to 5, but one number is missing. Which function call will find the missing number from [1, 2, 4, 5]?
- missingNumber([1, 2, 4, 5]) → 0
- missingNumber([1, 2, 4, 5]) → 6
- missingNumber([1, 2, 4, 5]) → 3 (Correct answer)
- missingNumber([1, 2, 4, 5]) → 1
Correct answer: missingNumber([1, 2, 4, 5]) → 3
The problem states that the array should contain numbers from 1 to 5, but one is missing. By inspecting the given array [1, 2, 4, 5], we can see that the number 3 is absent from the sequence. A function designed to find the missing number in such a sequence would correctly identify 3 as the output.
Question 3: How many set bits does the number 12 (binary 1100) have?
- 2 (Correct answer)
- 4
- 1
- 3
Correct answer: 2
12 in binary is 1100, which has exactly two 1-bits.
Question 4: In a scenario where you need to check if a string is a palindrome (reads the same forwards and backwards), which algorithm offers the best time complexity?
- Create a reversed copy of the string and compare it to the original.
- Use a stack: push the first half of the string onto the stack, then pop and compare with the second half.
- Sort the characters of the string and compare it with the original sorted string.
- Use two pointers, one at the beginning and one at the end, moving towards the center and comparing characters. (Correct answer)
Correct answer: Use two pointers, one at the beginning and one at the end, moving towards the center and comparing characters.
The two-pointer technique is the most efficient method. One pointer starts at the beginning of the string and the other at the end. The characters at these pointers are compared. If they are the same, the pointers move towards each other. This process continues until the pointers meet or cross. This approach has a time complexity of O(n/2), which simplifies to O(n), and a space complexity of O(1) as it doesn't require creating a new copy of the string or a separate data structure.
Question 5: What is 5 XOR 3 in decimal?
- 8
- 6 (Correct answer)
- 2
- 7
Correct answer: 6
5 is 101 and 3 is 011 in binary; XOR gives 110, which equals 6 in decimal.
Question 6: What is the time complexity of solving the 0/1 knapsack problem with n items and capacity W using dynamic programming?
- O(nW) (Correct answer)
- O(2^n)
- O(n + W)
- O(n²)
Correct answer: O(nW)
The 0/1 knapsack DP fills a table of size n × W, giving O(nW) time complexity.
Question 7: Which data structure would you use to find the k-th largest element in a stream of numbers efficiently?
- Min-heap of size k (Correct answer)
- Sorted array
- Max-heap
- Doubly linked list
Correct answer: Min-heap of size k
A min-heap of size k keeps the k largest seen elements; its root is always the k-th largest.
Question 8: What is the time complexity of inserting a key-value pair into a hash map with a good hash function (average case)?
- O(n²)
- O(1) (Correct answer)
- O(log n)
- O(n)
Correct answer: O(1)
With a good hash function and low load factor, insertion computes the bucket index in constant time.
Question 9: Given arrays A = [1, 3, 5] and B = [2, 4, 6], what is the median of the combined sorted array?
- 4
- 3.5 (Correct answer)
- 3
- 3.0
Correct answer: 3.5
Combined sorted array is [1,2,3,4,5,6]; median of 6 elements is average of 3rd and 4th: (3+4)/2 = 3.5.
Question 10: What is the lower bound for comparison-based sorting algorithms, and why?
- O(n) because you must read all elements
- O(n log n) because the decision tree has n! leaves requiring height ≥ log₂(n!) (Correct answer)
- O(n²) because swaps dominate
- O(log n) because divide-and-conquer halves the problem
Correct answer: O(n log n) because the decision tree has n! leaves requiring height ≥ log₂(n!)
Any comparison-based sort must distinguish n! permutations; a binary decision tree needs at least log₂(n!) ≈ n log n comparisons.
Question 11: In React, what triggers a component to re-render?
- DOM mutations triggered by the browser
- Any variable assignment inside the component function
- Only explicit calls to ReactDOM.render()
- Changes to state or props, or a parent re-render (Correct answer)
Correct answer: Changes to state or props, or a parent re-render
React schedules re-renders when setState is called, when received props change, or when the parent component re-renders (unless memoized).
Question 12: What is the GCD of 48 and 18?
- 9
- 12
- 6 (Correct answer)
- 3
Correct answer: 6
Applying the Euclidean algorithm: gcd(48,18)=gcd(18,12)=gcd(12,6)=gcd(6,0)=6.
Question 13: What is the main advantage of using a deque (double-ended queue) over a standard queue?
- Automatic sorting of elements
- Efficient insertion and deletion at both ends (Correct answer)
- O(1) search by value
- Faster random access by index
Correct answer: Efficient insertion and deletion at both ends
A deque supports O(1) push and pop at both the front and back, unlike a queue which only allows one end per operation.
Question 14: What is the space complexity of an in-place array reversal algorithm?
- O(1) (Correct answer)
- O(n²)
- O(log n)
- O(n)
Correct answer: O(1)
In-place reversal swaps elements using a constant number of temporary variables regardless of array size.
Question 15: In a stable sort, what is preserved?
- Only unique elements are kept
- The sorted order is achieved in fewer swaps
- The absolute positions of all elements
- The relative order of equal elements (Correct answer)
Correct answer: The relative order of equal elements
A stable sort guarantees that elements with equal keys appear in the output in the same relative order as the input.
Question 16: A graph has a cycle if and only if DFS produces a back edge. What does a 'back edge' connect?
- A node to a node in a different DFS component
- Two unvisited nodes
- Two nodes at the same DFS depth
- A node to an ancestor in the DFS tree (Correct answer)
Correct answer: A node to an ancestor in the DFS tree
A back edge connects a vertex to one of its ancestors in the DFS recursion stack, forming a cycle.
Question 17: In a 3-way QuickSort (Dutch National Flag partition), what problem does it solve compared to standard 2-way QuickSort?
- It eliminates the need for a pivot
- It handles arrays with many duplicate keys efficiently (Correct answer)
- It guarantees O(n log n) worst case
- It is faster on random data
Correct answer: It handles arrays with many duplicate keys efficiently
3-way partitioning groups equal elements together, so arrays with many duplicates achieve O(n) or near-linear performance instead of O(n²).
Question 18: What is the worst-case time complexity of removing an element from the middle of a dynamic array (list)?
- O(n log n)
- O(1)
- O(log n)
- O(n) (Correct answer)
Correct answer: O(n)
Removing from the middle requires shifting all subsequent elements left by one, which is O(n) in the worst case.
Question 19: In the 'house robber' problem, what does dp[i] typically represent?
- The maximum money robbed from the first i houses without robbing two adjacent (Correct answer)
- The index of the house to rob at step i
- The number of houses skipped up to position i
- The total money in all houses up to i
Correct answer: The maximum money robbed from the first i houses without robbing two adjacent
dp[i] holds the maximum loot achievable from the first i houses while respecting the no-adjacent constraint.
Question 20: Which data structure makes Heap Sort possible, and what is its defining property?
- Binary Heap: parent >= children (max-heap) (Correct answer)
- Hash Table: O(1) lookup
- BST: left child < root < right child
- Trie: prefix-based ordering
Correct answer: Binary Heap: parent >= children (max-heap)
Heap Sort uses a binary max-heap where every parent is ≥ its children, enabling O(1) access to the maximum element.
Question 21: What is the greedy algorithm approach?
- Random selection at each step
- Making the locally optimal choice at each step hoping to find the global optimum (Correct answer)
- Exhaustive search of all possibilities
- Always choosing the worst option
Correct answer: Making the locally optimal choice at each step hoping to find the global optimum
Greedy algorithms build solutions incrementally by always choosing the best available option at each step.
Question 22: What is the result of `n ^ n` for any integer n?
- 0 (Correct answer)
- n
- 1
- 2n
Correct answer: 0
XORing any value with itself cancels every bit, producing 0.
Question 23: Which sorting algorithm is stable and has O(n log n) worst-case time?
- Heapsort
- Quicksort
- Shell sort
- Merge sort (Correct answer)
Correct answer: Merge sort
Merge sort is stable (preserves relative order of equal elements) and guarantees O(n log n) in all cases.
Question 24: Which sorting algorithm is most efficient for sorting a nearly-sorted array with only a few elements out of place?
- Shell Sort
- Insertion Sort (Correct answer)
- Heap Sort
- Merge Sort
Correct answer: Insertion Sort
Insertion sort runs in O(n + k) time where k is the number of inversions, making it optimal for nearly-sorted data.
Question 25: What is the worst-case time complexity of the Quick Sort algorithm, and under what condition does it typically occur?
- O(n^2), when the input array is already sorted and the pivot is chosen as the first or last element. (Correct answer)
- O(n), when the input array is completely random.
- O(n log n), when the pivot elements consistently divide the array into two halves of nearly equal size.
- O(log n), when the input array contains many duplicate elements.
Correct answer: O(n^2), when the input array is already sorted and the pivot is chosen as the first or last element.
The worst-case time complexity of Quick Sort is O(n^2). This scenario happens when the pivot selection consistently results in highly unbalanced partitions, for example, when one partition has n-1 elements and the other has 0. This commonly occurs if the first or last element is chosen as the pivot and the array is already sorted or reverse-sorted.
Question 26: When merging two sorted arrays of sizes m and n into a single sorted array, what is the optimal time complexity?
- O(m · n)
- O(max(m, n))
- O((m + n) log(m + n))
- O(m + n) (Correct answer)
Correct answer: O(m + n)
A two-pointer merge traverses each array exactly once, producing the sorted result in O(m + n) time.
Question 27: A utility company is planning to connect several towns with a new power grid. The goal is to ensure every town is connected to the grid while minimizing the total length of power lines used. This problem is a classic application of finding what structure in a graph?
- A Shortest Path
- A Minimum Spanning Tree (MST) (Correct answer)
- A Hamiltonian Cycle
- An Eulerian Path
Correct answer: A Minimum Spanning Tree (MST)
A Minimum Spanning Tree (MST) is a subgraph that connects all vertices in a weighted, undirected graph with the minimum possible total edge weight, without forming any cycles. This directly corresponds to the problem of connecting all towns with the least amount of cable.
Question 28: What is a hash table collision?
- When the hash function fails
- When two different keys hash to the same index (Correct answer)
- When a hash table is full
- When a key cannot be found
Correct answer: When two different keys hash to the same index
Collisions occur when the hash function maps different keys to the same bucket, requiring resolution strategies like chaining or open addressing.
Question 29: In a directed graph, what does Kosaraju's algorithm compute?
- Strongly Connected Components (SCCs) (Correct answer)
- Shortest paths from a single source
- Minimum Spanning Tree
- Topological sort
Correct answer: Strongly Connected Components (SCCs)
Kosaraju's runs DFS twice—once on the original and once on the transposed graph—to identify all SCCs.
Question 30: What defines a static method in OOP?
- A method that takes no parameters and returns no value
- A method that belongs to the class itself rather than to any specific instance (Correct answer)
- A method that cannot be overridden by any subclass
- A method whose return value never changes regardless of input
Correct answer: A method that belongs to the class itself rather than to any specific instance
Static methods are associated with the class, not with individual objects; they can be called using the class name without creating an instance.
Question 31: A developer is implementing a function `rotateArray(nums, k)` that rotates an array `nums` to the right by `k` steps, where `k` is non-negative. If `nums = [1, 2, 3, 4, 5, 6, 7]` and `k = 3`, the result should be `[5, 6, 7, 1, 2, 3, 4]`. What is a potential issue with the expression `k = k % nums.length;` if it's used at the beginning of the function?
- It fails to account for negative values of k.
- There is no issue; this is a standard and necessary optimization. (Correct answer)
- It will cause an error if k is larger than the array length.
- It doesn't correctly handle the case where k is 0.
Correct answer: There is no issue; this is a standard and necessary optimization.
This expression is a crucial optimization. If k is larger than the length of the array, rotating by k is equivalent to rotating by `k % nums.length`. For example, rotating a 7-element array by 10 positions is the same as rotating it by 3 positions. This modulo operation prevents unnecessary full rotations of the array, making the algorithm more efficient without introducing any errors for non-negative k.
Question 32: What does 'overlapping subproblems' mean in dynamic programming?
- Every subproblem is solved exactly once by design
- The same subproblems recur multiple times during the recursive computation (Correct answer)
- Each subproblem has a unique solution
- Subproblems are mutually exclusive
Correct answer: The same subproblems recur multiple times during the recursive computation
Overlapping subproblems occur when naïve recursion solves the same subproblem repeatedly, which DP avoids by caching.
Question 33: Which of the following graph problems is most effectively solved using Depth-First Search (DFS) by identifying a 'back edge'—an edge that connects a node to one of its ancestors in the traversal tree?
- Finding the shortest path in a weighted graph.
- Finding the shortest path in an unweighted graph.
- Detecting the presence of a cycle. (Correct answer)
- Finding the minimum spanning tree.
Correct answer: Detecting the presence of a cycle.
Depth-First Search (DFS) explores as far as possible along each branch before backtracking. If during this traversal, it encounters a neighbor that has already been visited and is currently in the recursion stack (an ancestor), it has found a back edge, which indicates a cycle in the graph.
Question 34: What algorithm solves the Longest Increasing Subsequence in O(n log n) time?
- Binary search with patience sorting (Correct answer)
- Floyd-Warshall
- Merge sort decomposition
- Two-pointer sliding window
Correct answer: Binary search with patience sorting
Using binary search to maintain a sorted 'pile' structure (patience sorting) achieves O(n log n) for LIS.
Question 35: What is the output of [x**2 for x in range(5) if x % 2 == 0]?
- [1, 9, 25]
- [0, 1, 4, 9, 16]
- [0, 4, 16] (Correct answer)
- [4, 16]
Correct answer: [0, 4, 16]
Even values in range(5) are 0, 2, 4; squaring them yields [0, 4, 16].
Question 36: Which DP approach builds the solution iteratively starting from the smallest subproblems?
- Tabulation (Correct answer)
- Memoization
- Recursion
- Branch and bound
Correct answer: Tabulation
Tabulation (bottom-up DP) fills a table from the base cases up, avoiding recursion entirely.
Question 37: What is the difference between BFS and DFS?
- They produce identical results
- BFS is always faster
- BFS explores level by level using a queue; DFS explores as deep as possible using a stack (Correct answer)
- DFS uses more memory
Correct answer: BFS explores level by level using a queue; DFS explores as deep as possible using a stack
BFS uses a queue to visit neighbors first, while DFS uses a stack to go deep before backtracking.
Question 38: What does the 'k' represent in the time complexity O(n + k) of Counting Sort?
- Number of swaps
- Range of input values (Correct answer)
- Stack depth
- Number of comparisons
Correct answer: Range of input values
k is the range (max - min + 1) of the input values, which determines the size of the counting array.
Question 39: What does left-shifting an integer n by 1 position (`n << 1`) effectively compute?
- n - 1
- n * 2 (Correct answer)
- n / 2
- n + 1
Correct answer: n * 2
Left-shifting by 1 appends a zero bit on the right, which doubles the value in base-2 representation.
Question 40: Given array [5, 3, 8, 1, 9, 2, 7], how many comparisons does binary search make to find 7 (assuming the array is first sorted)?
- 7
- 4
- 3 (Correct answer)
- 2
Correct answer: 3
Sorted array is [1,2,3,5,7,8,9]; binary search checks index 3 (5), then index 5 (8), then index 4 (7) — 3 comparisons.
Question 41: Which of the following is the correct time complexity of a simple recursive Fibonacci solution without memoization?
- O(2^n) (Correct answer)
- O(n²)
- O(n)
- O(n log n)
Correct answer: O(2^n)
Without memoization, each call branches into two recursive calls, resulting in an exponential O(2^n) call tree.
Question 42: What is the worst-case time complexity of quicksort?
- O(n log n)
- O(n)
- O(log n)
- O(n²) (Correct answer)
Correct answer: O(n²)
Quicksort degrades to O(n²) when the pivot is always the smallest or largest element (e.g., sorted input with naive pivot).
Question 43: A GPS navigation system models a road network as a graph where cities are vertices and roads are edges with weights representing travel time. To find the quickest route from a starting city to a destination, which algorithm is the most appropriate choice, assuming all travel times are positive?
- Topological Sort
- Prim's Algorithm
- Breadth-First Search (BFS)
- Dijkstra's Algorithm (Correct answer)
Correct answer: Dijkstra's Algorithm
Dijkstra's algorithm is specifically designed to find the shortest path from a single source to all other nodes in a weighted graph with non-negative edge weights. This makes it the ideal choice for finding the quickest route in a road network where edge weights represent travel time.
Question 44: Which algorithm finds the Minimum Spanning Tree by always adding the globally smallest edge that does not form a cycle?
- Prim's
- Borůvka's
- Dijkstra's
- Kruskal's (Correct answer)
Correct answer: Kruskal's
Kruskal's algorithm sorts all edges and greedily adds the smallest edge that connects two different components.
Question 45: You are given a non-empty Binary Search Tree (BST). Which of the following traversal methods will visit the nodes in ascending sorted order of their values?
- Level-order Traversal
- Pre-order Traversal
- In-order Traversal (Correct answer)
- Post-order Traversal
Correct answer: In-order Traversal
In-order traversal visits the left subtree, then the root node, and finally the right subtree. Due to the inherent property of a BST (left children are smaller, right children are larger), this 'Left-Root-Right' pattern naturally processes the nodes in ascending order of their values.
Question 46: Given a sorted rotated array (e.g., [4,5,6,1,2,3]), how do you apply binary search to find a target?
- Linear scan is required since the array is not fully sorted
- Determine which half is sorted, check if target is in that half, then recurse (Correct answer)
- Sort the array first, then apply binary search
- Use a hash map for O(1) lookup
Correct answer: Determine which half is sorted, check if target is in that half, then recurse
At each step, at least one half of a rotated sorted array is fully sorted; check if the target falls in that half to decide which side to recurse on.
Question 47: In a CodeSignal challenge, you need to find all pairs in an array that sum to a target value. Which data structure gives the most efficient average-case solution?
- Nested loops with early exit
- Hash set for complement lookup (Correct answer)
- Priority queue
- Sorted array with binary search
Correct answer: Hash set for complement lookup
A hash set allows O(1) average-case lookup of each element's complement, giving O(n) overall time complexity.
Question 48: What is the result of sorted([3,1,4,1,5,9], key=lambda x: -x)?
- [1, 1, 3, 4, 5, 9]
- [9, 5, 4, 1, 3, 1]
- [9, 5, 4, 3, 1, 1] (Correct answer)
- [3, 1, 4, 1, 5, 9]
Correct answer: [9, 5, 4, 3, 1, 1]
Negating each value as the sort key sorts in descending order, yielding [9, 5, 4, 3, 1, 1].
Question 49: Kadane's algorithm solves which classic dynamic programming problem in O(n) time?
- Edit Distance
- 0/1 Knapsack
- Longest Common Subsequence
- Maximum Subarray Sum (Correct answer)
Correct answer: Maximum Subarray Sum
Kadane's algorithm finds the contiguous subarray with the largest sum by tracking the current and global maximum in a single pass.
Question 50: A project manager needs to schedule a series of tasks where some tasks have dependencies on others. This can be modeled as a directed graph. What fundamental property must this graph have for a valid task schedule (a topological sort) to be possible?
- The graph must have weights on its edges.
- The graph must be undirected.
- The graph must be strongly connected.
- The graph must be a Directed Acyclic Graph (DAG). (Correct answer)
Correct answer: The graph must be a Directed Acyclic Graph (DAG).
A topological sort, which provides a linear ordering of tasks based on dependencies, is only possible if the graph has no directed cycles. A cycle would represent a logical impossibility, such as Task A depending on Task B, and Task B depending on Task A.
Question 51: What is the time complexity of checking whether two strings are anagrams by sorting both?
- O(n)
- O(n²)
- O(n log n) (Correct answer)
- O(1)
Correct answer: O(n log n)
Sorting each string takes O(n log n), which dominates the O(n) comparison step.
Question 52: What is a linked list advantage over an array?
- Faster random access
- Efficient insertion and deletion without shifting elements (Correct answer)
- Less memory usage
- Built-in sorting
Correct answer: Efficient insertion and deletion without shifting elements
Linked lists can insert and delete elements in O(1) time once the position is found, without moving other elements.
CodeSignal General Coding Assessment (GCA)
The CodeSignal GCA is a 70-minute technical assessment with 4 coding tasks of increasing difficulty, evaluating problem-solving, data structures, algorithms, and code quality. Scored 200–600.
Exam Rules
- You can skip questions and return to them later
- Flag questions for review before submitting
- No feedback shown until you submit the entire exam
- Unanswered questions count as wrong — answer everything
- 10 pretest questions are mixed in and don't affect your score
- Timer auto-submits when time runs out
- Your progress is auto-saved every 30 seconds
These practice questions were written with AI tools. They are not real exam questions. Exam facts are checked against the official sources listed below. Not reviewed by a subject-matter expert. Editorial policy
Sources & references
Exam facts on this page (fees, format, dates, passing scores) are checked against these official sources; the date is our last check. Editorial policy
- support.codesignal.com — Eligibility, retake policy, score validity, exam format, time limit, score release · verified Oct 2026