Skip to content

Golang

Prepare for interviews with a database of questions from real interviews.

Showing 481–500 of 4,873

/* We need to transfer data from a certain source to a consumer. The source provides data in small batches (~tens of records), while the consumer works more efficiently with larger batches (~thousands of records). A real-world example is transferring data from Kafka queues to a Clickhouse database. Source: - Conditionally infinite. - The source never returns more than MaxItems records per call to Next. - During a single "session" (one call to the Pipe function), the source returns new data on each Next call. - However, after a restart, the source resumes from the last "confirmed" position, set by a cookie. Therefore, *each* cookie value returned by Next, after data is saved in the receiver, must be fixed with a Commit call, strictly in the same order they were returned by Next. Receiver: - Cannot process more than MaxItems at once. The task is to implement the function func Pipe(p Producer, c Consumer) error which reads data from the source, groups it into a buffer of size not more than MaxItems, and saves it to the receiver, then commits the progress in the source. */ const MaxItems = 9999 // Producer interface // Next returns: // - batch of items to be processed // - cookie to be committed when processing is done // - error // Commit is used to mark data batch as processed // type Producer interface { Next() (items []any, cookie int, err error) Commit(cookie int) error } type Consumer interface { Process(items []any) error } func Pipe(p Producer, c Consumer) error { // TODO }

Asked at 2 companiesViews: 1,055
Asked at 7 companiesViews: 1,049
Asked at 2 companiesViews: 1,029
Golang code review tasks

Python

6,887 questions · 584 tasks

Frontend

6,861 questions · 681 tasks

Java

6,575 questions · 265 tasks

QA / QA Automation

4,588 questions · 54 tasks