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

Programming Exercises

Implement a Goroutine-based Fibonacci sequence generator that uses channels to produce the first n Fibonacci numbers.

Hard

Problem Statement

Implement a Goroutine-based Fibonacci sequence generator that uses channels to produce the first n Fibonacci numbers.

Sample Input

n = 10

Sample Output

0 1 1 2 3 5 8 13 21 34 

Limits

Time: 2s · Memory: 256 MB

Code Editor
00:00
package main import "fmt" func fibonacci(n int) <-chan int { ch := make(chan int) go func() { // Your code here }() return ch } func main() { n := 10 fibCh := fibonacci(n) for i := 0; i < n; i++ { fmt.Print(<-fibCh, " ") } }
Log in or sign up to run or submit your code.Log inSign up
Input
n = 10
Expected Output
0 1 1 2 3 5 8 13 21 34