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 result of 'CodeSignal'.lower().replace('signal', 'test')?
Answer: 'codetest'
lower() converts to 'codesignal', then replace('signal','test') substitutes 'signal' with 'test' → 'codetest'.
Given a 2D matrix represented as a flat array with row-major order, what is the index of element at row r, column c in an n-column matrix?
Answer: r * n + c
Row-major layout stores row r starting at index r*n, so element (r, c) is at r*n + c.
What is the minimum number of operations to convert 'kitten' to 'sitting' using edit distance (Levenshtein)?
Answer: 3
kitten→sitten (substitute k→s), sitten→sittin (substitute e→i), sittin→sitting (insert g) = 3 operations.
An array of 0s and 1s must be partitioned so all 0s come before all 1s. Which algorithm does this in O(n) with O(1) space?
Answer: Dutch National Flag (two-pointer partition)
Two pointers (left and right) swap misplaced elements until they meet, achieving O(n) time and O(1) extra space.
What does 'abcabc'.count('abc') return?
Answer: 2
Python's str.count() finds non-overlapping occurrences: 'abc' appears at index 0 and index 3 → returns 2.
Which technique solves the 'sliding window maximum' problem in O(n) time?
Answer: Monotonic deque (double-ended queue)
A monotonic deque keeps indices of candidate maximum elements in decreasing order, allowing O(1) amortized queries and updates per element.
Given sorted array [1, 2, 3, 4, 5, 6, 7] and a target sum of 9, what is the pair found using the two-pointer approach?
Answer: (3, 6)
Two pointers start at 1 and 7 (sum=8, too low→advance left); at 2 and 7 (sum=9, found) — but (3,6) also sums to 9 and pointers would find it depending on implementation; the first found is (2,7). Actually pointers find 2+7=9 first.