- Related Questions & Answers
- Minimum number of operations required to delete all elements of the array using 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++.
- 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++
- Find out the minimum number of coins required to pay total amount in C++
- Minimum Players required to win the game in C++
- Minimum Swaps required to group all 1’s together in C++
- Minimum number of operations on an array to make all elements 0 using C++.

- 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

Advertisements