Problem Statement | |||||||||||||
Your mailbox is a mess: it contains e-mails from weeks ago and you want to archive them. You know which folder you want to move each e-mail to. The names of the destination folders are given in a String[] destFolders and consist of letters (both upper- and lowercase) and spaces. The names are case sensitive. The i-th element of destFolders corresponds to the i-th element of your inbox.
To archive the e-mails you can just select the first one and move it to the appropriate folder, then select the second one, etc. Using this method, you need to make exactly the same number of selections as the number of e-mails you have. By selecting contiguous ranges of e-mails (that have to be moved to the same folder) and moving them at once, you can often do better. After moving one or more e-mails, they disappear from your inbox, so other e-mails may become adjacent. Return the minimal number of selections you need to make to archive all your e-mails. | |||||||||||||
Definition | |||||||||||||
| |||||||||||||
Constraints | |||||||||||||
- | destFolders contains between 1 and 50 elements, inclusive. | ||||||||||||
- | Each element of destFolders has length between 1 and 50, inclusive. | ||||||||||||
- | Each element of destFolders consists of letters and spaces. | ||||||||||||
Examples | |||||||||||||
0) | |||||||||||||
| |||||||||||||
1) | |||||||||||||
| |||||||||||||
2) | |||||||||||||
| |||||||||||||
3) | |||||||||||||
| |||||||||||||
4) | |||||||||||||
|