← All CodeSignal Technical Assessment Flashcard Decks

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
  1. 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].

  2. 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.

  3. 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.

  4. What does ''.join(reversed('hello')) return?

    Answer: 'olleh'

    reversed() yields characters in reverse order, and ''.join() concatenates them into the string 'olleh'.

  5. 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.

  6. 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'.

  7. 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.