Array and String Manipulation Flashcards
7 cards from real CodeSignal Technical Assessment practice questions. Tap to flip, then mark Knew It or Still Learning — missed cards come back until you master them.
Read the first 7 Array and String Manipulation flashcards as text
What is the output of [x**2 for x in range(5) if x % 2 == 0]?
Answer: [0, 4, 16]
Even values in range(5) are 0, 2, 4; squaring them yields [0, 4, 16].
Which data structure most efficiently supports O(1) duplicate detection while building a result array from an input array?
Answer: Hash set
A hash set provides O(1) average-case membership checks, making it ideal for tracking seen elements during a single pass.
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)?
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.
What does ''.join(reversed('hello')) return?
Answer: 'olleh'
reversed() yields characters in reverse order, and ''.join() concatenates them into the string 'olleh'.
What is the space complexity of an in-place array reversal algorithm?
Answer: O(1)
In-place reversal swaps elements using a constant number of temporary variables regardless of array size.
For the string 'aabcccdddd', what is the run-length encoding?
Answer: 'a2b1c3d4'
Run-length encoding records each character followed by its count: 'a'×2, 'b'×1, 'c'×3, 'd'×4 → 'a2b1c3d4'.
Which approach finds all pairs in an array that sum to a target value in O(n) time?
Answer: Store seen values in a hash map and check target − current element
A hash map lookup for target − arr[i] achieves O(1) per element, giving O(n) overall for one pass.
Written and edited by Nathan Beja, founder of Practice Test Geeks, with AI assistance. Exam facts are checked against the official sources linked below. 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 — Time limit, eligibility, retake policy, score validity, exam format, passing score, score release · verified Nov 2026
- codesignal.com — Test delivery · verified Nov 2026