Answered step by step
Verified Expert Solution
Link Copied!

Question

1 Approved Answer

There are a lot of people at the cinema box office standing in a huge line. Each of them has a single 100, 50 or

There are a lot of people at the cinema box office standing in a huge line. Each of them has a single 100, 50 or 25 dollars bill. A ticket costs 25 dollars.

Working as a clerk, He wants to sell a ticket to every single person in this line.

Can they sell a ticket to each person and give the change if he initially has no money and sells the tickets strictly in the order people follow in the line?

Return YES, if Vasya can sell a ticket to each person and give the change. Otherwise return NO.

tickets([25, 25, 50]) // => YES tickets([25, 100]) // => NO. Not have enough money to give change to 100 dollars

My attempt. What did I do wrong:

function tickets(peopleInLine){

var prev=0;

var change=0;

var sum=0;

for(var i=0; i

change=peopleInLine[i]-25;

if(change==0){

sum=sum+25;

return 'YES';}

else{

if(sum

return 'NO';

else

return 'YES';}

}

}

Step by Step Solution

There are 3 Steps involved in it

Step: 1

blur-text-image

Get Instant Access to Expert-Tailored Solutions

See step-by-step solutions with expert insights and AI powered tools for academic success

Step: 2

blur-text-image

Step: 3

blur-text-image

Ace Your Homework with AI

Get the answers you need in no time with our AI-driven, step-by-step assistance

Get Started

Recommended Textbook for

Excel As Your Database

Authors: Paul Cornell

1st Edition

1590597516, 978-1590597514

More Books

Students also viewed these Databases questions