Practice Real Company Assessment Patterns • Latest 2025–2026 Mock Tests

Programming Exercises

Create a Go program to implement a producer-consumer problem using channels.

Medium

Problem Statement

Create a Go program to implement a producer-consumer problem using channels.

Sample Input

A producer sends tasks (e.g., Task 1, Task 2), and a consumer processes them.

Sample Output

Produced: Task 1
Consumed: Task 1
Consumed: Task 2
Produced: Task 2
Produced: Task 3
Consumed: Task 3

Limits

Time: 2s · Memory: 256 MB

Code Editor
00:00
package main import "fmt" func producer(ch chan string) { // Send tasks to the channel } func consumer(ch chan string) { // Process tasks from the channel } func main() { // Set up producer and consumer }
Log in or sign up to run or submit your code.Log inSign up
Input
A producer sends tasks (e.g., Task 1, Task 2), and a consumer processes them.
Expected Output
Produced: Task 1
Consumed: Task 1
Consumed: Task 2
Produced: Task 2
Produced: Task 3
Consumed: Task 3