
Data Structure
Networking
RDBMS
Operating System
Java
MS Excel
iOS
HTML
CSS
Android
Python
C Programming
C++
C#
MongoDB
MySQL
Javascript
PHP
- Selected Reading
- UPSC IAS Exams Notes
- Developer's Best Practices
- Questions and Answers
- Effective Resume Writing
- HR Interview Questions
- Computer Glossary
- Who is Who
Minimum Number of Letters Needed to Make a Total of N in C++
Problem statement
Given an integer n and let a = 1, b = 2, c= 3, ….., z = 26. The task is to find the minimum number of letters needed to make a total of n
If n = 23 then output is 1 If n = 72 then output is 3(26 + 26 + 20)
Algorithm
1. If n is divisible by 26 then answer is (n/26) 2. If n is not divisible by 26 then answer is (n/26) + 1
Example
#include <iostream> using namespace std; int minRequiredSets(int n){ if (n % 26 == 0) { return (n / 26); } else { return (n / 26) + 1; } } int main(){ int n = 72; cout << "Minimum required sets: " << minRequiredSets(n) << endl; return 0; }
Output
When you compile and execute the above program. It generates the following output −
Minimum required sets: 3
Advertisements