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!
Select
Add answer anonymously...

Texas Instruments Software Developer Intern interview questions & answers

A Software Developer Intern was asked Q. Meeting Rooms Allocation Problem Statement Stark Industry is planning to organiz...read more
A Software Developer Intern was asked Q. Maximum Sum Rectangle Problem Given an M x N matrix of integers ARR, your task i...read more
A Software Developer Intern was asked Q. Josephus Problem Statement Consider 'N' individuals standing in a circle, number...read more

Popular interview questions of Software Developer Intern

A Software Developer Intern was asked Q1. Meeting Rooms Allocation Problem Statement Stark Industry is planning to organiz...read more
A Software Developer Intern was asked Q2. Maximum Sum Rectangle Problem Given an M x N matrix of integers ARR, your task i...read more
A Software Developer Intern was asked Q3. Josephus Problem Statement Consider 'N' individuals standing in a circle, number...read more
Texas Instruments Software Developer Intern Interview Questions
Stay ahead in your career. Get AmbitionBox app
play-icon
play-icon
qr-code
Trusted by over 1.5 Crore job seekers to find their right fit company
80 L+

Reviews

10L+

Interviews

4 Cr+

Salaries

1.5 Cr+

Users

Contribute to help millions

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

Follow Us
  • Youtube
  • Instagram
  • LinkedIn
  • Facebook
  • Twitter
Profile Image
Hello, Guest
AmbitionBox Employee Choice Awards 2025
Winners announced!
awards-icon
Contribute to help millions!
Write a review
Write a review
Share interview
Share interview
Contribute salary
Contribute salary
Add office photos
Add office photos
Add office benefits
Add office benefits