Implement several OA simulation problems
ByteDanceData Scientist · Online AssessmentLast updated
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.
Reconstruct and solve the following coding problems from an online assessment.
-
Case-insensitive adjacent differences Given a string
s, treat uppercase and lowercase letters as the same. Count how many indicesiwith0 <= i < len(s) - 1satisfylower(s[i]) != lower(s[i + 1]). -
Memory allocator with 8-aligned starts You are given an initial binary array
memory[0..n-1], where0means free and1means occupied. Support two operations:
alloc(x): find the leftmost start indexssuch thats % 8 == 0,s + x <= n, and every value inmemory[s..s+x-1]is0. 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 toidby setting it back to0. Ifiddoes not exist or has already been erased, report failure.
Implement a simulator for these operations.
- 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.
Solution walkthrough is for members
Get the full walkthrough with reference code and complexity analysis, plus Kitty Coach at 300 messages a day. Hints, the code runner and community answers stay free.