
Asked in RUBRIK INDIA
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...
Top Software Developer Intern Interview Questions Asked at RUBRIK INDIA
Q. Minimum Removals Problem Statement Given an integer array ARR of size N and an i...read more
Q. Scramble String Problem Statement You are given an integer 'N' and two strings S...read more
Q. XOR Query Problem Statement Assume you initially have an empty array called ARR....read more
Interview Questions Asked to Software Developer Intern at Other Companies
Top Skill-Based Questions for RUBRIK INDIA Software Developer Intern
C++ Interview Questions and Answers
300 Questions
Algorithms Interview Questions and Answers
250 Questions
Data Structures Interview Questions and Answers
250 Questions
Web Development Interview Questions and Answers
250 Questions
Operating Systems Interview Questions and Answers
250 Questions
System Design Interview Questions and Answers
250 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

