Answered step by step
Verified Expert Solution
Link Copied!

Question

1 Approved Answer

Java 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

Java

image text in transcribed

image text in transcribed

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 Ek Write a function: class Solution public int solution(intl] s, int 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 S1,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 time 1 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 (S[K]E[K] for every K within the range [1..N]). In your solution, focus on correctness. The performance of your solution will not be the focus of the assessment. Solution Java SE 8 Java 1 II you can also use imports, for example: 2 11 import java.util.*; 3 4 II you can write to stdout for debugging purposes, e.g 5 II System.out.println("this is a debug message) 7class Solution { 8 public int solution(int[] S, int[l E) { /I write your code in Java SE 8 10 12

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_2

Step: 3

blur-text-image_3

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

More Books

Students also viewed these Databases questions