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
, whereH1 >= H2 > 1
, decreaseH
toH1
; here,H1
is the larger factor ofH
.
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!
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


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
AmbitionBox Awards
Get AmbitionBox app

