Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- public class PeopleCircle {
- public String order(int numMales, int numFemales, int K) {
- int totalPersons = numMales + numFemales;
- char[] circle = new char[totalPersons];
- int i = -1;
- while(numFemales > 0) {
- int tmpK = K;
- while(tmpK > 0) {
- if(i != (totalPersons - 1)) {
- i ++;
- } else {
- i = 0;
- }
- if(circle[i] != 'F') {
- tmpK --;
- }
- }
- circle[i] = 'F';
- numFemales --;
- }
- for(int j = 0; j < totalPersons; j ++) {
- if(circle[j] != 'F') {
- circle[j] = 'M';
- }
- }
- return new String(circle);
- }
- }
Add Comment
Please, Sign In to add comment