We want to be able to replicate how the os/browser recieves bytes of data and convert them into meaningful items. Let us consider the initial stream of data to be unknown. In the below representations, I will use . to repersent unknown data. All other data that are known will not be .. We will be doing 2 operations here:
Initial stream : .........................................................
Operation: read(4) -> empty bytes
Stream: .........................................................
Operation: acceptData(4, "ABCD")
Stream: ....ABCD.....................................................
Operation: read(6) -> empty bytes[Rule 1]
Stream: ....ABCD.....................................................
Operation: acceptData(0, "EFGH")
Stream: EFGHABCD.....................................................
Operation: read(6) -> EFGHAB
Stream: .........................................................
Operation: read(6) -> CD [Rule 2]
Stream: .........................................................
Operation: acceptData(0, "I")
Stream: I.....................................................
Operation: acceptData(2, "J") [Rule 2]
Stream: I.J...................................................
Operation: read(6) -> I
Stream: J........................................................ [Rule 3]
Rules for read():
NOTE: This question might be tough to understand but if you read it multiple time you will understand.
I havn't had my results yet but yes I did implement this with an ArrayList in Java.
For leetcode folks,