Josephus Simulation

Hard Circular Linked List PRO
🔒 Login to Unlock

Problem Statement

Write a C program using a circular linked list to simulate the Josephus problem and find the surviving person’s position.

Input Format

Two space-separated integers: n (number of people) and k (step count).

Output Format

Print the surviving person's 1-indexed position.

Constraints

1 <= n <= 30, 1 <= k <= 10

Sample Input

5 2

Sample Output

3

Explanation

Create a circular linked list of size n, eliminate every k-th node iteratively until only one node remains, and print its value.

Starter Code

#include <stdio.h>
#include <stdlib.h>

struct Node {
    int data;
    struct Node *next;
};

int main() {
    int n, k;
    if (scanf("%d %d", &n, &k) == 2) {
        // Write your code here to simulate Josephus problem using circular linked list
    }
    return 0;
}

Limits

  • Time Limit: 1s
  • Memory Limit: 256MB

Embedded C Programming

Updated: March 15, 2026
Intermediate

Embedded systems rely on efficient low-level programming to interact directly with hardware. In this course, you will learn how to write practical Embedded C programs used in real microcontroller-based systems. Rather than focusing only on theory, this course follows a practice-driven approach. Each lesson includes hands-on coding exercises that simulate real firmware development tasks used