1. Cookie Problem | JavaScript | Coding Interview | Challenge

Pubblicato il: 01 gennaio 2020
sul canale di: askFaran
665
27

#Challenge

You are given an `array` representing how many cookies each person in a group has. You don't want anyone to start arguing over who has more cookies. You want each person to have the same amount of cookies, but you can't take away any cookies from anyone, instead you need to give each person extra cookies until they all have the same amount.

You have to find out how many cookies each person has, and give them each additional cookies until they have as many cookies as the person with the most cookies.
Return the total amount of additional cookies you needed give out.

Example:

cookieProblem ( [ 4, 5, 6 ] ) // it should returns 3

6 is the most highest amount of cookies.
So each person should have 6 cookies

Person 1 has 4 cookies, so he needs 6-4 i.e. 2 additional cookies

Person 2 has 5 cookies, so he needs 6-5 i.e. 1 additional cookie

Therefore, 2 + 1 = 3 total additional cookies should be given out

#javascript #interview #coding #Interviewquestion #codingchallenge #cookieproblem #askFaran


In questa pagina del sito puoi guardare il video online 1. Cookie Problem | JavaScript | Coding Interview | Challenge della durata di ore minuti seconda in buona qualità , che l'utente ha caricato askFaran 01 gennaio 2020, condividi il link con amici e conoscenti, su youtube questo video è già stato visto 665 volte e gli è piaciuto 27 spettatori. Buona visione!