Implement several OA simulation problems

Read the full interview experience this question came from →

Quick Overview

This set of problems evaluates skills in string processing, memory simulation and allocation logic, and online data-structure maintenance for dynamic contiguous segment counting, testing algorithmic design and attention to stateful invariants.

Implement several OA simulation problems

Company: ByteDance

Role: Data Scientist

Category: Coding & Algorithms

Difficulty: easy

Interview Round: Online Assessment

Reconstruct and solve the following coding problems from an online assessment. 1. **Case-insensitive adjacent differences** Given a string `s`, treat uppercase and lowercase letters as the same. Count how many indices `i` with `0 <= i < len(s) - 1` satisfy `lower(s[i]) != lower(s[i + 1])`. 2. **Memory allocator with 8-aligned starts** You are given an initial binary array `memory[0..n-1]`, where `0` means free and `1` means occupied. Support two operations: - `alloc(x)`: find the leftmost start index `s` such that `s % 8 == 0`, `s + x <= n`, and every value in `memory[s..s+x-1]` is `0`. Allocate that entire block to a newly created allocation ID, and mark all those cells as occupied by the same ID. If no such block exists, report failure. - `erase(id)`: free every cell currently assigned to `id` by setting it back to `0`. If `id` does not exist or has already been erased, report failure. Implement a simulator for these operations. 3. **Online counting of same-color contiguous segments** Points lie on integer positions of a line. Each update assigns or changes the color of one point. After every update, return the current number of contiguous segments, where a segment is a maximal run of adjacent positions with the same color. Only colored positions participate; a missing position breaks continuity. Design an efficient online method to maintain the segment count as points are inserted or recolored.

Overview: This set of problems evaluates skills in string processing, memory simulation and allocation logic, and online data-structure maintenance for dynamic contiguous segment counting, testing algorithmic design and attention to stateful invariants.

Read the full ByteDance Data Scientist interview experience this question came from

ByteDance logo
ByteDance
Mar 5, 2026
easyData ScientistOnline AssessmentCoding & Algorithms
5
0

Reconstruct and solve the following coding problems from an online assessment.

  1. Case-insensitive adjacent differences Given a string s , treat uppercase and lowercase letters as the same. Count how many indices i with 0 <= i < len(s) - 1 satisfy lower(s[i]) != lower(s[i + 1]) .
  2. Memory allocator with 8-aligned starts You are given an initial binary array memory[0..n-1] , where 0 means free and 1 means occupied. Support two operations:
    • alloc(x) : find the leftmost start index s such that s % 8 == 0 , s + x <= n , and every value in memory[s..s+x-1] is 0 . Allocate that entire block to a newly created allocation ID, and mark all those cells as occupied by the same ID. If no such block exists, report failure.
    • erase(id) : free every cell currently assigned to id by setting it back to 0 . If id does not exist or has already been erased, report failure.
    Implement a simulator for these operations.
  3. Online counting of same-color contiguous segments Points lie on integer positions of a line. Each update assigns or changes the color of one point. After every update, return the current number of contiguous segments, where a segment is a maximal run of adjacent positions with the same color. Only colored positions participate; a missing position breaks continuity. Design an efficient online method to maintain the segment count as points are inserted or recolored.