Implement a MyCalendarTwo class to store your events. A new event can be added if adding the event will not cause a triple booking.

Your class will have one method, book(int start, int end). Formally, this represents a booking on the half open interval [start, end), the range of real numbers x such that start <= x < end.

A triple booking happens when three events have some non-empty intersection (ie., there is some time that is common to all 3 events.)

For each call to the method MyCalendar.book, return true if the event can be added to the calendar successfully without causing a triple booking. Otherwise, return false and do not add the event to the calendar.

Your class will be called like this: MyCalendar cal = new MyCalendar(); MyCalendar.book(start, end)

Example 1:

12345678910111213 MyCalendar();MyCalendar.book(10, 20); // returns trueMyCalendar.book(50, 60); // returns trueMyCalendar.book(10, 40); // returns trueMyCalendar.book(5, 15); // returns falseMyCalendar.book(5, 10); // returns trueMyCalendar.book(25, 55); // returns trueExplanation:The first two events can be booked. The third event can be double booked.The fourth event (5, 15) can't be booked, because it would result in a triple booking.The fifth event (5, 10) can be booked, as it does not use time 10 which is already double booked.The sixth event (25, 55) can be booked, as the time in [25, 40) will be double booked with the third event;the time [40, 50) will be single booked, and the time [50, 55) will be double booked with the second event.

Note:

- The number of calls to MyCalendar.book per test case will be at most 1000.
- In calls to MyCalendar.book(start, end), start and end are integers in the range [0, 10^9].

- Nov 20, 2017...more
## My Calendar I

Nov 19, 2017...moreImplement a MyCalendar class to store your events. A new event can be added if adding the event will not cause a double booking.

Your class will have the method, book(int start, int end). Formally, this represents a booking on the half open interval [start, end), the range of real numbers x such that start <= x < end.

A double booking happens when two events have some non-empty intersection (ie., there is some time that is common to both events.)

For each call to the method MyCalendar.book, return true if the event can be added to the calendar successfully without causing a double booking. Otherwise, return false and do not add the event to the calendar.

Your class will be called like this: MyCalendar cal = new MyCalendar(); MyCalendar.book(start, end)**Example 1:**1234567MyCalendar();MyCalendar.book(10, 20); // returns trueMyCalendar.book(15, 25); // returns falseMyCalendar.book(20, 30); // returns trueExplanation:The first event can be booked. The second can't because time 15 is already booked by another event.The third event can be booked, as the first event takes every time less than 20, but not including 20.**Note:**- The number of calls to MyCalendar.book per test case will be at most 1000.
- In calls to MyCalendar.book(start, end), start and end are integers in the range [0, 10^9].

## Majority Element

Nov 15, 2017...moreGiven an array of size n, find the majority element. The majority element is the element that appears more than ⌊ n/2 ⌋ times.

You may assume that the array is non-empty and the majority element always exist in the array.

## Find K-th Smallest Pair Distance

Nov 14, 2017...moreGiven an integer array, return the k-th smallest distance among all the pairs. The distance of a pair (A, B) is defined as the absolute difference between A and B.

**Example 1:**12345678910Input:nums = [1,3,1]k = 1Output: 0Explanation:Here are all the pairs:(1,3) -> 2(1,1) -> 0(3,1) -> 2Then the 1st smallest distance pair is (1,1), and its distance is 0.**Note:**- 2 <= len(nums) <= 10000.
- 0 <= nums[i] < 1000000.
- 1 <= k <= len(nums) * (len(nums) - 1) / 2.

## Number of Atoms

Nov 13, 2017...moreGiven a chemical formula (given as a string), return the count of each atom.

An atomic element always starts with an uppercase character, then zero or more lowercase letters, representing the name.

1 or more digits representing the count of that element may follow if the count is greater than 1. If the count is 1, no digits will follow. For example, H2O and H2O2 are possible, but H1O2 is impossible.

Two formulas concatenated together produce another formula. For example, H2O2He3Mg4 is also a formula.

A formula placed in parentheses, and a count (optionally added) is also a formula. For example, (H2O2) and (H2O2)3 are formulas.

Given a formula, output the count of all elements as a string in the following form: the first name (in sorted order), followed by its count (if that count is more than 1), followed by the second name (in sorted order), followed by its count (if that count is more than 1), and so on.

**Example 1:**12345Input:formula = "H2O"Output: "H2O"Explanation:The count of elements are {'H': 2, 'O': 1}.**Example 2:**12345Input:formula = "Mg(OH)2"Output: "H2MgO2"Explanation:The count of elements are {'H': 2, 'Mg': 1, 'O': 2}.**Example 3:**12345Input:formula = "K4(ON(SO3)2)2"Output: "K4N2O14S4"Explanation:The count of elements are {'K': 4, 'N': 2, 'O': 14, 'S': 4}.**Note:**- All atom names consist of lowercase letters, except for the first character which is uppercase.
- The length of formula will be in the range [1, 1000].
- formula will only consist of letters, digits, and round parentheses, and is a valid formula as defined in the problem.