Practice Real Company Assessment Patterns • Latest 2025–2026 Mock Tests

Programming Exercises

Write a function to implement the Josephus problem for n people and a step size k.

Hard

Problem Statement

Write a function to implement the Josephus problem for n people and a step size k.

Sample Input

n = 7
k = 3

Sample Output

Survivor: 4

Limits

Time: 2s · Memory: 256 MB

Code Editor
00:00
function josephus(n: number, k: number): number { // Your logic here }
Log in or sign up to run or submit your code.Log inSign up
Input
n = 7
k = 3
Expected Output
Survivor: 4