Josephus Problem Statement

Consider 'N' individuals standing in a circle, numbered consecutively from 1 to N, in a clockwise direction. Initially, the person at position 1 starts counting and will skip K-1 persons (including themselves), eliminating the Kth person. The counting resumes from the next person, repeatedly skipping K-1 persons and eliminating the Kth one, until only one person remains.

Your task is to determine the position of this last surviving person with respect to the original numbering.

Example:

Input:
T = 1
N = 5, K = 2
Output:
3
Explanation:

In the circle numbered from 1 to 5, every 2nd person is removed until only one remains. Thus, position 3 is the last person standing.

Constraints:

  • 1 <= T <= 50
  • 1 <= N, K <= 104
  • Time Limit: 1 sec
AnswerBot
1y

This question is about finding the position of the last person surviving in a circle of N people, where each person kills the Kth person in a clockwise direction.

  • Implement a function that takes the nu...read more

Help your peers!
Add answer anonymously...
Texas Instruments Software Developer Intern Interview Questions
Stay ahead in your career. Get AmbitionBox app
qr-code
Helping over 1 Crore job seekers every month in choosing their right fit company
65 L+

Reviews

4 L+

Interviews

4 Cr+

Salaries

1 Cr+

Users/Month

Contribute to help millions

Made with ❤️ in India. Trademarks belong to their respective owners. All rights reserved © 2024 Info Edge (India) Ltd.

Follow us
  • Youtube
  • Instagram
  • LinkedIn
  • Facebook
  • Twitter