Minimum Number of Stabs to Kill the King

You are given the initial health of a king represented by an integer N. Your task is to determine the minimum number of stabs required to reduce the king's health to zero, thereby killing the king.

Explanation:

To decrease the king's health, you can perform either of the two types of operations:

  • First Type of Stab: Decrease the king's health H by 1, i.e., H = H - 1.
  • Second Type of Stab: If H = H1 * H2, where H1 >= H2 > 1, decrease H to H1; here, H1 is the larger factor of H.

Input:

The initial input line contains an integer 'T', representing the number of test cases.
Each test case consists of one line containing a single integer 'N', the king's initial health.

Output:

For each test case, output a single line containing an integer representing the minimum number of stabs required.

Example:

Input:
2
10
15
Output:
4
5

Constraints:

  • 1 <= T <= 10^2
  • 1 <= N <= 10^3
  • Time Limit: 1 sec

Note:

You are not required to print anything; just implement the given function to compute the answer.

AnswerBot
4mo

Calculate the minimum number of stabs required to kill the king by reducing his health to zero.

  • Iterate through each test case and calculate the minimum number of stabs required based on the given oper...read more

Help your peers!
Select
Add answer anonymously...

RUBRIK INDIA Software Developer Intern interview questions & answers

A Software Developer Intern was asked Q. Minimum Removals Problem Statement Given an integer array ARR of size N and an i...read more
A Software Developer Intern was asked Q. Minimum Number of Stabs to Kill the King You are given the initial health of a k...read more
A Software Developer Intern was asked Q. Scramble String Problem Statement You are given an integer 'N' and two strings S...read more

Popular interview questions of Software Developer Intern

A Software Developer Intern was asked Q1. Minimum Removals Problem Statement Given an integer array ARR of size N and an i...read more
A Software Developer Intern was asked Q2. Minimum Number of Stabs to Kill the King You are given the initial health of a k...read more
A Software Developer Intern was asked Q3. Scramble String Problem Statement You are given an integer 'N' and two strings S...read more
RUBRIK INDIA 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