- 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

Suppose we have a list called reviews and a threshold value t. Each item in reviews[i] has [x, y] means product i had x number of 5-star rating and y number of reviews. We have to find the minimum number of additional 5-star reviews we need so that the percentage of 5-star reviews for those items list is at least t percent.

So, if the input is like reviews = [[3, 4],[1, 2],[4, 6]] threshold = 78, then the output will be 7, as in total there were 8 5-star reviews and 12 reviews. To reach 78% 5-star reviews, we need 7 more 5-star reviews.

To solve this, we will follow these steps −

a := 0, b := 0

for each 5-star count c and review count d in reviews, do

a := a + c

b := b + d

if a * 100 >= t * b, then

return 0

delta := t * b - 100 * a

return floor of (delta +(99 - t))/(100 - t)

Let us see the following implementation to get better understanding

def solve(reviews, t): a = 0 b = 0 for c, d in reviews: a += c b += d if a * 100 >= t * b: return 0 delta = t * b - 100 * a return (delta + (99 - t)) // (100 - t) reviews = [ [3, 4], [1, 2], [4, 6] ] t = 78 print(solve(reviews, t))

[[3, 4], [1, 2],[4, 6] ],78

7

- Related Questions & Answers
- Program to find number of given operations required to reach Target in Python
- Program to find minimum number of hops required to reach end position in Python
- Program to find minimum number of buses required to reach final target in python
- Program to count number of swaps required to group all 1s together in Python
- Program to count number of minimum swaps required to make it palindrome in Python
- Program to count number of swaps required to change one list to another in Python?
- Program to count number of operations required to all cells into same color in Python
- Program to count minimum number of operations required to make numbers non coprime in Python?
- Program to count number of operations required to convert all values into same in Python?
- Program to count number of flipping required to make all x before y in Python
- Count number of ways to jump to reach end in C++
- Program to find number of combinations of coins to reach target in Python
- Finding minimum number of required operations to reach n from m in JavaScript
- Program to find Star number in C++
- Program to count number of walls required to partition top-left and bottom-right cells in Python

Advertisements