Java Engineer Interview Questions

30,830 java engineer interview questions shared by candidates

There is a group of n people. A serial killer comes and kills every kth person from the group and keeps on repeating this until there is only one person left and he spares the life of that person. Write an equation/algorithm which takes n and k as input and give the position of the guy who will be alive after the complete process. For eg: Let us assume there is a group of 13 (n) people and the serial killer kills every 3rd (k) person. The positions on which they are standing are marked 1 to 13. The order in which he kills will be: 3, 6, 9, 12, 2, 7, 11, 4, 10, 5, 1, 8. This way the guy on 13th positon will be saved.
avatar

Java Consultant

Interviewed at Xebia

3.8
Mar 5, 2016

There is a group of n people. A serial killer comes and kills every kth person from the group and keeps on repeating this until there is only one person left and he spares the life of that person. Write an equation/algorithm which takes n and k as input and give the position of the guy who will be alive after the complete process. For eg: Let us assume there is a group of 13 (n) people and the serial killer kills every 3rd (k) person. The positions on which they are standing are marked 1 to 13. The order in which he kills will be: 3, 6, 9, 12, 2, 7, 11, 4, 10, 5, 1, 8. This way the guy on 13th positon will be saved.

Viewing 321 - 330 interview questions

Glassdoor has 30,830 interview questions and reports from Java engineer interviews. Prepare for your interview. Get hired. Love your job.