You are implementing a calendar application where you can add events. Each event has a start time and end time represented by a half-open interval [start, end). An event can only be added if it does not overlap with existing events in the calendar. Return true if the event can be booked successfully, and false if it causes a conflict.
You are implementing a calendar system where you can add events. Each event is represented by a start time and an end time, defined as a half-open interval [startTime, endTime). You need to ensure that no more than two events overlap at any given time, or else return false. Your task is to implement a class, MyCalendarTwo, that will book events while preventing triple bookings.
You are tasked with simulating an exam room where students will choose seats based on a strategy that maximizes their distance from the closest person already seated. If multiple seats have the same distance, the student will choose the seat with the smallest index. Additionally, students can leave the room, freeing up their seats.
We are given a run-length encoded array where every even-indexed element specifies how many times the following odd-indexed element (a number) is repeated in the original sequence. Your task is to implement an iterator that can return the next ’n’ elements from the decoded sequence when requested.
Design a system that processes daily stock price quotes and computes the price span for the current day. The price span for a day is defined as the maximum number of consecutive days (including today) where the price of the stock was less than or equal to today’s price.
You are given two integer arrays: persons and times. The i-th vote was cast for persons[i] at time times[i]. For each query at a given time t, you need to return the person who was leading the election at time t. If there is a tie between candidates, the most recent vote wins.