Question: I'm building an app with a calendar element to it. I'm considering building this piece of my app with the Google Calendar APIs. The APIs are everything I could dream of for interacting between calendars owned by different Google accounts. However, the same flexibility isn't as apparent between calendars owned by the same Google account.

I want to be able to use only 1 Google account to hold all of the app's calendars. Within this account, I want to create 1 calendar per user of my site. I'd like for my users to be able to create personal events and to also be able to share them with each other.

**Is there a way to share events across multiple Google calendars that are owned by the same Google account?**

Undesirable alternatives:

1. Create and manage duplicate entries. I would prefer to not have to use a hack like creating duplicate entries -- that's just asking for problems when the owner changes attributes of the event. Plus, I'd need additional logic to keep the non-owner from being able to edit the event since they'd technically be the owner for their copy.

	* Another alternative is to have everyone have an actual Google account. There are at least 2 problems with this:
	* If they use their own account, I couldn't directly manage their calendar unless they give me their login cred.s. This is a terrible practice on so many levels.
	* I could have them sign up to my site with the info needed for a real Google acct, complete with serving up the CAPTCHA and create a new Google Account for each user behind the scenes which my site would manage, but I just read Google Accounts TOS and that might violate sections 5.3 and 10.2 depending on how they are interpretted.

Answer: 
1. Start at the point nearest the midpoint
2. select all values within half the range of it
3. Use your existing solution going out in both directions.
4. Repeat from step 2 using every other point in the original selection.
5. select the best result.

---

Worst case this is an `O(n``2``)` problem as you can replace step 4 with "repeat with all points".
If I understand the problem right, then the greedy algorithm is in fact optimal. Let G be the greedy solution and let S be any solution. Consider the first group where G differs from S. Since G is a greedy solution, G's group is larger than S's. For example,

```
G : [1, 2, 3][4, 5, 6, 7][8, 9, 10][11, 12]...
S : [1, 2, 3][4, 5, 6][7, 8, 9][10, 11, 12]...

```

We can derive a new solution S' from S that agrees with G on a longer prefix without introducing a new group. Just steal some items from the next group. The resulting groups are valid because one is already in G and the other is a subgroup of a valid group.

```
S': [1, 2, 3][4, 5, 6, 7][8, 9][10, 11, 12]...

```

By induction, it follows that G is in fact optimal.