Skip to main content
All Questions

Simulate Happy and Sad people over four iterations.

Unlock detailed company stats for this questionUpgrade

Starting with N Happy people and 0 Sad people, on every iteration 70% of Happy people become Sad and 50% of Sad people become Happy. Given N, print "Error!" if it is negative; otherwise print the number of happy and sad people separated by whitespace after the 4th iteration. Example: (1000,0) -> (300,700) after iteration 1 -> (90+350, 350+210) = (440,560) after iteration 2.

Format · TCS NQT advanced coding, medium question.

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.