Skip to content
neoideasblog

neoideasblog

  • Home
    • Privacy Policy
    • About Us
    • Contact Us
    • Terms
  • Trivia
  • Results
  • Admit Cards
  • Sitemaps
  • Toggle search form

[Question] Booking Concert Tickets in Groups solution leetcode

Posted on May 28, 2022May 28, 2022 By Admin No Comments on [Question] Booking Concert Tickets in Groups solution leetcode

A concert hall has n rows numbered from  to n - 1, each with m seats, numbered from  to m - 1. You need to design a ticketing system that can allocate seats in the following cases:

Note that the spectators are very picky. Hence:

Booking Concert Tickets in Groups solution leetcode

  • They will book seats only if each member of their group can get a seat with row number less than or equal to maxRow. maxRow can vary from group to group.
  • In case there are multiple rows to choose from, the row with the smallest number is chosen. If there are multiple seats to choose in the same row, the seat with the smallest number is chosen.
ALSO READ:-   [Question] What was the first James Bond film to star Roger Moore?

Implement the BookMyShow class:

  • BookMyShow(int n, int m) Initializes the object with n as number of rows and m as number of seats per row.
  • int[] gather(int k, int maxRow) Returns an array of length 2 denoting the row and seat number (respectively) of the first seat being allocated to the k members of the group, who must sit together. In other words, it returns the smallest possible r and c such that all [c, c + k - 1] seats are valid and empty in row r, and r <= maxRow. Returns [] in case it is not possible to allocate seats to the group.
  • boolean scatter(int k, int maxRow) Returns true if all k members of the group can be allocated seats in rows  to maxRow, who may or may not sit together. If the seats can be allocated, it allocates k seats to the group with the smallest row numbers, and the smallest possible seat numbers in each row. Otherwise, returns false.

Example 1: [Question] Booking Concert Tickets in Groups solution leetcode

Input
["BookMyShow", "gather", "gather", "scatter", "scatter"]
[[2, 5], [4, 0], [2, 0], [5, 1], [5, 1]]
Output
[null, [0, 0], [], true, false]

Explanation
BookMyShow bms = new BookMyShow(2, 5); // There are 2 rows with 5 seats each 
bms.gather(4, 0); // return [0, 0]
                  // The group books seats [0, 3] of row 0. 
bms.gather(2, 0); // return []
                  // There is only 1 seat left in row 0,
                  // so it is not possible to book 2 consecutive seats. 
bms.scatter(5, 1); // return True
                   // The group books seat 4 of row 0 and seats [0, 3] of row 1. 
bms.scatter(5, 1); // return False
                   // There are only 2 seats left in the hall.

Constraints:

  • 1 <= n <= 5 * 104
  • 1 <= m, k <= 109
  • 0 <= maxRow <= n - 1
  • At most 5 * 104 calls in total will be made to gather and scatter.

SOLUTION

“Click here“

Admin

I am the Founder and the creator of the blog neoideasblog.com where we share latest trivia questions and answers on a daily basis.

ALSO READ:-   [Question] Frank Sinatra owned what record label?
Trivia

Post navigation

Previous Post: [Question] What does UNESCO stand for?
Next Post: [Ques] Wendy Kaufman became famous as what beverage spokesperson?

Related Posts

[Question] The leaves of the coriander plant are better known as what in the U.S.? Trivia
[Question] Which state has the tallest lighthouse in the U.S.? Trivia
[Question] What are the United States’ "Twin Cities"? Trivia
[Answer] 1. Robert Plant, Jimmy Page, John Paul Jones and the late, great John Bonham; the band that gave the world ‘Black Dog’… By what name were they collectively known? Trivia
[Question] What is the name of the submarine featured in Jules Verne’s novel "Twenty Thousand Leagues Under the Sea"? Trivia
[Question] In 1986, What Show Infamously Wrote Off An Entire Season By Turning It Into A Character’s Dream? Trivia

Leave a Reply Cancel reply

Your email address will not be published. Required fields are marked *

Archives

  • July 2022
  • June 2022
  • May 2022
  • April 2022

Categories

  • Admit Cards
  • Results
  • Trivia

Disclaimer

Disclaimer: Our website name Neoideasblog.com. we are just a news portal that covers various updates and stories.

Copyright © 2022 neoideasblog.

Powered by PressBook Grid Blogs theme