Untitled

 avatar
unknown
plain_text
10 months ago
5.3 kB
48
Indexable
encode and decode. basically it provides over two hundred lines of C++ code with incomplete implementation. It needs you to complete missing part and make it pass build. are you able to list those C++ code so I can review and prepare how to approach?”
then I asked
“# Run-Length Encoding (RLE) : Encoding scheme where integers that have the same value can be represented as a single value with a count, e.g. 1, 1, 1, 1, 1 can be written as 1 (5).
# Bit-Packing (BP) : Encoding scheme where smaller integer values can be represented without using the full 4 bytes of data. For example, all numbers in 2, 3, 4, 5 fit within 3 bits, so we can encode ("pack") them into 12 bits or at most 2 bytes thus reducing data 8x.
# Run is a sequence of values that are encoded using RLE or BP. All values in a run have the same encoding but runs themselves can interleave, e.g. [RLE, BP, RLE, RLE, BP, ...].
#  1. All values have to be placed into runs, and value order cannot change.
#  2. A Run-Length encoded run has at least 8 values (only the last run can have
#     fewer values).
#  3. Once started, a Run-Length encoded run should extend as far as possible
#     (it should continue as long as the input values are repeating).
#  4. A Bit-Packing encoded run has exactly 8 values, i.e. once it is started,
#     it is required to fill all 8 values (only the last run can have fewer values).
#  5. Run-Length encoding is our default scheme.  We only use Bit-Packing encoding
#     when we cannot apply Run-Length (because there is not enough repeated values).
# [1, 1, 1] will be encoded as RLE[1, 3].
# [1, 1, 1, 1, 2, 3, 4, 5] will be encoded as BP[1, 1, 1, 1, 2, 3, 4, 5].
# [1, 1, 1, 1, 1, 1, 1, 1, 2, 3, 4, 5] will be encoded as RLE[1, 8], BP[2, 3, 4, 5].
# [1, 1, 1, 1, 1, 1, 1, 1, 1, 2, 3, 4, 5] will be encoded as RLE[1, 9], BP[2, 3, 4, 5].
# This file contains all of the necessary code for the exercise.
#
# Your goal is to implement Encoder and Decoder specification by combining
# RLE and BP encodings.
#
# You should implement all methods containing # TODO comment.
# You may use the API helper methods and classes provided below.”
In the last I asked streaming, which is translated from Chinese discussion board.
“The C++ code started out at over 200 lines: several dozen lines of description + over 100 lines of class definition/input and output, for a total of five classes (some constructors were incomplete and needed to be filled in).
The encoder is similar to a streaming input, appending one number at a time. From the beginning, there's a follow-up question: what if there are a lot of identical numbers in the streaming input? (Store the number and the number of consecutive occurrences).
Then, the encoder is written: two methods handle the problem, similar to a large simulation, with few algorithms but a lot of details. Both methods have limitations and can affect each other.
The BP definition is vague and unclear. After some discussion, I chose a simple definition (straightforwardly storing eight numbers).
Over 20 minutes were spent understanding the problem and class structure, and clarifying the details. I also had to refer back to the requirements and class definitions while writing the code.”



The Revenue System mentioned in the article needs to implement add, addByReferral, and getTopKCustomer(minRevenue).
First, you need a Customer class with an id and totalRevenue.
Write heavy: When adding two items, simply place them directly into a Hashmap. When getting items, use a minHeap traversal. Add is O(1), and get is O(nlogk).
Read-heavy/Read-Write Balance: Maintain a SortedSet (I use Java), and when adding, place items into a Map and a Set. When addingByReferral, first add the new customer, then remove the referrer from the set, add the revenue, and put it back. When getting items, use a set iterator or a for-each loop to find the first k items that meet the criteria. Add is O(logn), and get is O(k).
Follow-up: Given a customer ID, find all the IDs linked to it, sorting them by referrer level. For example,
a refers to b, a refers to c
b refers to d, c refers to f
f refers to h
Then getRelation(a) should return {{b, c}, {d, f}, {h}}
Use a map to store an ID and a list of its referral IDs, abstract the referral relationship into a directed graph, and then perform a BFS (background-for-background-scaling) exercise starting from the root ID. This is somewhat similar to the questions in the LeetCode course schedule.





Array of covers. Given a ref string, source string, and array of covers, each cover is disjoint. The range from the covers corresponds to the indices whos characters in the ref string form the source string. Also given an index corresponding to a character in the source string, determine the new set of covers after splitting the corresponding cover that includes that character.

For example:
Given the array: [(4, 7), (10, 11), (13, 15)], the list it covers is: [4, 5, 6, 7, 10, 11, 13, 14, 15]. If the index is 2, delete 6 from the covered list, and the output is [(4, 5), (7,7), (10, 11), (13, 15)].

Follow-up: assume the covers provided is a maximal list. That is, the number of covers is also minimal as possible. Preserve this logic after making the split.






Tic Tac Fucking Toe
Editor is loading...
Leave a Comment