Click here to Skip to main content
15,878,048 members
Please Sign up or sign in to vote.
1.20/5 (6 votes)
See more:
You are given an integer array games where games[i]-[champion i, loser i] indicates that the player champion, defeated player loser, in a match.

Return a list Result of size 2 where:

Result [0] is a list of all players that have not lost any matches.
Result [1] is a list of all players that have lost exactly one match.

The values in the two lists should be returned in increasing order.

Note:
You should only consider the players that have played at least one match.
The testcases will be generated such that no two matches will have the same outcome.

Input :
10
1 3
2 3
3 6
5 6
5 7
4 5
4 8
4 9
10 4
10 9

Output :
[ [1,2,10], [4,5,7,8] ]

What I have tried:

This is a question asked in a coding round of an assessment, could anyone kindly help me solve this question using python language or c language.
Posted
Updated 8-Dec-22 19:26pm
Comments
Dave Kreskowiak 3-Dec-22 11:49am    
If you are asking this question as part of a job interview or assessment, you do not deserve the job. The job is about writing code in Python or C and you obviously cannot do it.

What are you going to do when you are given a real assignment and can't solve that problem either?

While we are more than willing to help those that are stuck, that doesn't mean that we are here to do it all for you! We can't do all the work, you are either getting paid for this, or it's part of your grades and it wouldn't be at all fair for us to do it all for you.

So we need you to do the work, and we will help you when you get stuck. That doesn't mean we will give you a step by step solution you can hand in!
Start by explaining where you are at the moment, and what the next step in the process is. Then tell us what you have tried to get that next step working, and what happened when you did.

If you are having problems getting started at all, then this may help: How to Write Code to Solve a Problem, A Beginner's Guide[^]
 
Share this answer
 
42 - the answer to life and everything.

Honestly, if I was interviewing for a job and they asked me this I would puke.
But it is a good test of "do you know python?"

Years ago, 2 other managers and I had to staff a team of developers. An argument ensued about coding tests. One manager was adamant, I was skeptical, the other just sat and watched :). I conceded to very, very simple tests. We worked mainly in C and a little in C++, so pointers were very important. I was shocked at the number of candidates that had "years of C and C++" and could not explain pointers, understand the difference between byte, word and long word, etc.

As to you test question - you have two issues. First, do you know python? You have to get past the mechanics. If not, this job is not for you, or you have more work to do. Second, the other is a simple algorithm. Get past #1 first.

Software development is not easy.
 
Share this answer
 

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)



CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900