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
Given an array [3, 1, 4, 1, 5, 9, 2, 6], what is the result of rotating it left by 3 positions?
Answer: [1, 5, 9, 2, 6, 3, 1, 4]
Left rotation by 3 moves the first 3 elements [3,1,4] to the end, leaving [1,5,9,2,6,3,1,4].
Which algorithm finds the maximum subarray sum in O(n) time?
Answer: Kadane's Algorithm
Kadane's Algorithm iterates once through the array tracking the current and global maximum subarray sum in O(n) time.
What does the following produce for s = 'abcde': s[1:4]?
Answer: 'bcd'
Python slice s[1:4] extracts characters at indices 1, 2, 3 — giving 'bcd'; the end index is exclusive.
What is the time complexity of checking whether two strings are anagrams by sorting both?
Answer: O(n log n)
Sorting each string takes O(n log n), which dominates the O(n) comparison step.
An array contains integers 1–n with one duplicate and one missing value. Which approach finds both in O(n) time and O(1) space?
Answer: Use XOR and arithmetic sum/sum-of-squares formulas
XOR paired with arithmetic identities (expected sum and sum-of-squares vs actual) isolates both the duplicate and missing value in two passes without extra space.
Given strings s = 'racecar', which single operation verifies it is a palindrome most efficiently?
Answer: Compare s with s[::-1]
s[::-1] reverses the string in O(n) and a direct equality check confirms palindrome status in one line.
When merging two sorted arrays of sizes m and n into a single sorted array, what is the optimal time complexity?
Answer: O(m + n)
A two-pointer merge traverses each array exactly once, producing the sorted result in O(m + n) time.