Skip to main content
All Questions

Simulate 4 rounds of population movement between Happy and Sad cities.

Unlock detailed company stats for this questionUpgrade

Two cities: Happy and Sad. Initially Sad population = 0 and Happy population = N. Simulate 4 rounds of population movement: 70% of Happy moves to Sad, and 50% of Sad moves to Happy. If the population of any city goes below 0, output "error" instead of a number. Input: the Happy population N (integer). Output: the population of each city after 4 rounds (space-separated), or "error".

Format · TCS NQT coding section: 7 test cases (2 public, 5 hidden), full program written from scratch.

Community answers

No answers contributed by the community yet.

Related courses

Course

Software Engineering Interview Prep

Land your dream software engineering role at Google, Amazon, Microsoft, Meta, Apple, and other top companies. Learn from mock interviews, frameworks, and advice from senior candidates—practice data structures, algorithms, system design, people management, behavioral interviews, and more.

Course

System Design Interviews

Learn how to answer the latest system design questions across product, infrastructure, and AI domains. Features in-depth video examples, written breakdowns, and helpful reference patterns. Watch senior engineers and managers answer these questions in mock interview videos.