- Trending Categories
- Data Structure
- Networking
- RDBMS
- Operating System
- Java
- 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

Given N questions in a test and K students in the class. Out of the batch of K students, N students memorized exactly one question each. A mail can contain about a maximum of X questions.

Find the minimum number of mails required so that the entire class gets to know about all the questions

If N = 3, K = 3, X = 1 then one has to send 6 mails −

- Student 1 sends his question to student 2 and student 3 (2 mails),
- So does student 2 and student 3 so total mails = 2 * 3 = 6

The final answer can be calculated using the below formula −

ceil(N/X) * (K-N) + (( ceil((N-1)/X)) * (N-1)) + (N-1)

#include <iostream> #include <cmath> using namespace std; int minMailsToBeSent(int n, int k, int x){ int m = (n - 1) + ceil((n - 1) * 1.0 / x) * (n - 1) + ceil(n * 1.0 / x) * (k- n); return m; } int main(){ int questions = 3; int students = 3; int X = 1; cout << "No of mails to be sent: " << minMailsToBeSent(questions, students, X) << endl; return 0; }

When you compile and execute the above program. It generates the following output −

No of mails to be sent: 6

- Related Questions & Answers
- Minimum number of operations required to delete all elements of the array using C++.
- Program to find minimum number of pins required to hang all banners in C++
- Minimum Number of Platforms Required for a Railway Station using C++.
- Minimum number of operations required to sum to binary string S using C++.
- Minimum number of given operations required to make two strings equal using C++.
- Minimum number of palindromes required to express N as a sum using C++.
- How to find the minimum number of jumps required to reach the end of the array using C#?
- Minimum number of given moves required to make N divisible by 25 using C++.
- Minimum number of bottles required to fill K glasses in C++
- Minimum number of swaps required to sort an array in C++
- Minimum number of moves to make all elements equal using C++.
- Minimum operations required to set all elements of binary matrix in C++
- Minimum operations required to make all the array elements equal in C++
- Program to find minimum number of steps required to catch the opponent in C++
- Program to find minimum number of movie theatres required to show all movies in python

Advertisements