Dataford
Interview QuestionsInterview GuidesExperiencesMock InterviewsPricing
Get started

Ordered Even/Odd With Goroutines

MediumPython00:00
Practice interviewer
In session
5 left
00:00

Your question is Ordered Even/Odd With Goroutines. Start with the requirements on the right.

Run and submit as often as you like. When you're ready, talk me through your approach or go straight to the code.

You need to log in / sign up to run or submit.

Problem

Write a program to print even and odd numbers from a slice using goroutines while preserving the original order.

Implement the equivalent Python function print_even_odd(nums), where nums is a list of integers. Return a two-element list containing the even numbers and odd numbers, respectively, with each group retaining its original relative order. Use concurrent workers to classify values.

Constraints

  • 0 <= len(nums) <= 500
  • -10^9 <= nums[i] <= 10^9
  • Return evens and odds as separate lists
  • Preserve relative input order within each returned list
  • Classification must use concurrent workers

Function Signature

def print_even_odd(nums):
Your solutionPython 3
You need to log in / sign up to run or submit.
Run your code to see test output