Answered step by step
Verified Expert Solution
Question
1 Approved Answer
C++ There are N guests who are invited to a party. The K-th guest will attend the party at time Sk and leave the party
C++
There are N guests who are invited to a party. The K-th guest will attend the party at time Sk and leave the party at time E. Write a function: int solution(vectorint> &s, vectorcint> &E) that, given an integer array S and an integer array E, both of length N, returns an integer denoting the minimum number of chairs you need such that everyone attending the party can sit down. For example, given S [1,2,6,5,3] E-[5,5,7,6,8] There are five guests attending the party. The first guest will arrive at time 1. We need one chair at time1 The second guest will arrive at time 2. There are now two guests at the party, so we need two chairs at time 2. The fifth guest will arrive at time 3. There are now three guests at the party, so we need three chairs at time 3. . The fourth guest will arrive at time 5 and, at the same moment, the first and second guests will leave the party. There are now The third guest will arrive at time 6, and the fourth guest will leave the party at the same time. There are now two (the third and fifth) guests at the party, so we need two chairs at time 6 So we need at least three chairs; your function should return 3. Assume that: .N is an integer within the range [1..500] each element of array S is an integer within the range1..999]; each element of array E is an integer within the range [2..1,000]; . every person leaves after he/she arrives (SK Ek for every K within the range [1-NI). In your solution, focus on correctness. The performance of your solution will not be the focus of the assessment
Step by Step Solution
There are 3 Steps involved in it
Step: 1
Get Instant Access to Expert-Tailored Solutions
See step-by-step solutions with expert insights and AI powered tools for academic success
Step: 2
Step: 3
Ace Your Homework with AI
Get the answers you need in no time with our AI-driven, step-by-step assistance
Get Started