100 people standing in a circle in order 1 to 100. No. 1 has a sword. He kills the next person (i.e., No. 2) and gives the sword to the next (i.e., No. 3). All people do the same until only 1 survives. Which number survives at the last?

Check if you were right - full answer with solution below.
Solution:Â
Method 1: Logical / Intuitive Approach
- If the number of people n is a power of 2, the first person will survive.
- After each round, half the people are eliminated, and the person who started the game survives.
- When n is not a power of 2:
- Let 2m be the largest power of 2 less than n (100).
- The formula for the survivor is : Survivor = 2 x (n - 2m) + 1
Apply for n = 100:
Largest power of 2 less than 100 is 64 (26).
Remaining people beyond 64 : 100−64 = 36.
Survivor: 2 × (36) +1 = 73
Answer: 73
Method 2: Step-by-Step
- People numbered from 1 to 100.
- Eliminate every second person in each round until only one remains.
Round-wise elimination:
- Round 1: Remove all even numbers → remaining:
Round 1: 1, 3, 5, 7, 9, 11, 13, 15, 17, 19, 21, 23, 25, 27, 29, 31, 33, 35, 37, 39, 41, 43, 45, 47, 49, 51, 53, 55, 57, 59, 61, 63, 65, 67, 69, 71, 73, 75, 77, 79, 81, 83, 85, 87, 89, 91, 93, 95, 97, 99 - Round 2: Remove every second → remaining:
Round 2: 1, 5, 9, 13, 17, 21, 25, 29, 33, 37, 41, 45, 49, 53, 57, 61, 65, 69, 73, 77, 81, 85, 89, 93, 97 - Round 3: Remove every second → remaining:
Round 3: 1, 9, 17, 25, 33, 41, 49, 57, 65, 73, 81, 89, 97Â - Round 4: Since they are in a circle, 97 killed 1, and in the last move, 89 killed 97, leaving us with these survivors.
Round 4: 9, 25, 41, 57, 73, 89Â - Round 5: Now, 9 eliminates 25, 41 eliminates 57, and 73 eliminates 89, leaving us with these survivors.
Round 5: 9, 41, 73 - Round 6: Now, 9 eliminates 41, leaving 9 and 73. The next turn will be 73’s.
Round 6: 9, 73Â - Round 7: Now 73 eliminated 9 , And 73 is the Last Survivor.
Round 7: 73Â
Answer: 73
Method 3:Â Â
Here, we can define an array with 100 elements with values from 1 to 100.Â
- Start with people numbered 1 to N in a circle; each person kills the next and passes the sword forward.
- This eliminates every alternate person, leaving only odd-positioned people after each round.
- The process repeats until only one person (the survivor) remains.
Step 1 : For a given value of N, find the "Power of 2" immediately smaller than N. Let’s call it PÂ
Step 2 : Subtract N from (P-1). Lets call it M, i.e, M = (P-1)- NÂ
Step 3 : Multiply M by 2. i.e M*2Â
Step 4 : Subtract M*2 from P-1. Let's call it ans, i.e, ans = (P-1) - (M*2)Â
So, the person with number "ans" will survive till last.Â
Code:
#include <bits/stdc++.h>
using namespace std;
int main()
{
int person = 100;
// Placeholder array for person
vector<int> a(person);
// Assign placeholders from 1 to N (total person)
for (int i = 0; i < person; i++) {
a[i] = i + 1;
}
// Will start the game from 1st person (Which is at
// placeholder 0)
int pos = 0;
// Game will be continued till we end up with only one
// person left
while (a.size() > 1) {
// Current person will shoot the person next to
// him/her. So incrementing the position.
pos++;
// As person are standing in circular manner, for
// person at last place has right neighbour at
// placeholder 0. So we are taking modulo to make it
// circular
pos %= a.size();
// Killing the person at placeholder 'pos'
// To do that we simply remove that element
a.erase(a.begin() + pos);
// There is no need to increment the pos again to
// pass the gun Because by erasing the element at
// 'pos', now next person will be at 'pos'.
}
// Print Person that survive the game
cout << a[0];
return 0;
}
// Java program for the 3rd approach
import java.io.*;
import java.util.Arrays;
import java.util.LinkedList;
class GFG {
// Driver code
public static void main (String[] args) {
LinkedList<Integer> ll = new LinkedList<>(); //treat this list as a circular linked list using modulo operator
int n = 100;
for(int i=1; i<=n; i++){
ll.add(i);
}
int i=0;
while(ll.size()>1){
i = (i+1)%n; // iterate to got to the next in a cicrular fashion so use modulo
int next = ll.remove(i); //kill the next person and remove them from linkedlist
n--; //reduce the size
//System.out.println("Killed: "+next); // print the person tp see who got killed
}
System.out.println(ll.get(0)); //winner remains
}
}
// This Code is contributed by Aishwarya Sharma
person = 100
# Placeholder array for person
a = [0] * person
# Assign placeholders from 1 to N (total person)
for i in range(person):
a[i] = i + 1
# Will start the game from 1st person (Which
# is at placeholder 0)
pos = 0
# Game will be continued till we end up with
# only one person left
while (len(a) > 1):
# Current person will shoot the person next
# to him/her. So incrementing the position.
pos += 1
# As person are standing in circular manner,
# for person at last place has right neighbour
# at placeholder 0. So we are taking modulo
# to make it circular
pos %= len(a)
# Killing the person at placeholder 'pos'
# To do that we simply remove that element
del a[pos]
# There is no need to increment the pos again to
# pass the gun Because by erasing the element at
# 'pos', now next person will be at 'pos'.
# Driver code
# PrPerson that survive the game
print(a[0])
# This code is contributed by ShubhamSingh10
// C# program for the above approach
using System;
using System.Linq;
public static class GFG
{
// Driver code
static public void Main ()
{
int person = 100;
// Placeholder array for person
int[] a = new int[person];
// Assign placeholders from 1 to N (total person)
for (int i = 0; i < person; i++) {
a[i] = i + 1;
}
// Will start the game from 1st person (Which is at
// placeholder 0)
int pos = 0;
// Game will be continued till we end up with only one
// person left
while (a.Length > 1)
{
// Current person will shoot the person next to
// him/her. So incrementing the position.
pos++;
// As person are standing in circular manner, for
// person at last place has right neighbour at
// placeholder 0. So we are taking modulo to make it
// circular
pos %= a.Length;
// Killing the person at placeholder 'pos'
// To do that we simply remove that element
a = a.Where((source, index) =>index != pos).ToArray();
// There is no need to increment the pos again to
// pass the gun Because by erasing the element at
// 'pos', now next person will be at 'pos'.
}
// Print Person that survive the game
Console.Write(a[0]);
}
}
// This Code is contributed by ShubhamSingh10
<script>
var person = 100;
// Placeholder array for person
var a = new Array(person);
// Assign placeholders from 1 to N (total person)
for (var i = 0; i < person; i++) {
a[i] = i + 1;
}
// Will start the game from 1st person (Which is at
// placeholder 0)
var pos = 0;
// Game will be continued till we end up with only one
// person left
while (a.length > 1) {
// Current person will shoot the person next to
// him/her. So incrementing the position.
pos++;
// As person are standing in circular manner, for
// person at last place has right neighbour at
// placeholder 0. So we are taking modulo to make it
// circular
pos = pos% (a.length);
// Killing the person at placeholder 'pos'
// To do that we simply remove that element
a.splice(pos,1)
// There is no need to increment the pos again to
// pass the gun Because by erasing the element at
// 'pos', now next person will be at 'pos'.
}
// Print Person that survive the game
document.write(a[0]);
// This code is contributed by ShubhamSingh10
</script>
Output
73