bowang0911/leetcode huggingface dataset:
Erect the Fence

You are given an array `trees` where `trees[i] = [xi, yi]` represents the location of a tree in the garden.

Fence the entire garden using the minimum length of rope, as it is expensive. The garden is well-fenced only if **all the trees are enclosed**.

Return _the coordinates of trees that are exactly located on the fence perimeter_. You may return the answer in **any order**.

**Example 1:**

**Input:** trees = \[\[1,1\],\[2,2\],\[2,0\],\[2,4\],\[3,3\],\[4,2\]\]
**Output:** \[\[1,1\],\[2,0\],\[4,2\],\[3,3\],\[2,4\]\]
**Explanation:** All the trees will be on the perimeter of the fence except the tree at \[2, 2\], which will be inside the fence.

**Example 2:**

**Input:** trees = \[\[1,2\],\[2,2\],\[4,2\]\]
**Output:** \[\[4,2\],\[2,2\],\[1,2\]\]
**Explanation:** The fence forms a line that passes through all the trees.

**Constraints:**

*   `1 <= trees.length <= 3000`
*   `trees[i].length == 2`
*   `0 <= xi, yi <= 100`
*   All the given positions are **unique**.
Design In-Memory File System

Design a data structure that simulates an in-memory file system.

Implement the FileSystem class:

*   `FileSystem()` Initializes the object of the system.
*   `List ls(String path)`
    
    *   If `path` is a file path, returns a list that only contains this file's name.
    *   If `path` is a directory path, returns the list of file and directory names **in this directory**.
    
    The answer should in **lexicographic order**.
*   `void mkdir(String path)` Makes a new directory according to the given `path`. The given directory path does not exist. If the middle directories in the path do not exist, you should create them as well.
*   `void addContentToFile(String filePath, String content)`
    *   If `filePath` does not exist, creates that file containing given `content`.
    *   If `filePath` already exists, appends the given `content` to original content.
*   `String readContentFromFile(String filePath)` Returns the content in the file at `filePath`.

**Example 1:**

**Input**
\[ "FileSystem ",  "ls ",  "mkdir ",  "addContentToFile ",  "ls ",  "readContentFromFile "\]
\[\[\], \[ "/ "\], \[ "/a/b/c "\], \[ "/a/b/c/d ",  "hello "\], \[ "/ "\], \[ "/a/b/c/d "\]\]
**Output**
\[null, \[\], null, null, \[ "a "\],  "hello "\]

**Explanation**
FileSystem fileSystem = new FileSystem();
fileSystem.ls( "/ ");                         // return \[\]
fileSystem.mkdir( "/a/b/c ");
fileSystem.addContentToFile( "/a/b/c/d ",  "hello ");
fileSystem.ls( "/ ");                         // return \[ "a "\]
fileSystem.readContentFromFile( "/a/b/c/d "); // return  "hello "

**Constraints:**

*   `1 <= path.length, filePath.length <= 100`
*   `path` and `filePath` are absolute paths which begin with `'/'` and do not end with `'/'` except that the path is just `"/ "`.
*   You can assume that all directory names and file names only contain lowercase letters, and the same names will not exist in the same directory.
*   You can assume that all operations will be passed valid parameters, and users will not attempt to retrieve file content or list a directory or file that does not exist.
*   `1 <= content.length <= 50`
*   At most `300` calls will be made to `ls`, `mkdir`, `addContentToFile`, and `readContentFromFile`.
N-ary Tree Preorder Traversal

Given the `root` of an n-ary tree, return _the preorder traversal of its nodes' values_.

Nary-Tree input serialization is represented in their level order traversal. Each group of children is separated by the null value (See examples)

**Example 1:**

**Input:** root = \[1,null,3,2,4,null,5,6\]
**Output:** \[1,3,5,6,2,4\]

**Example 2:**

**Input:** root = \[1,null,2,3,4,5,null,null,6,7,null,8,null,9,10,null,null,11,null,12,null,13,null,null,14\]
**Output:** \[1,2,3,6,7,11,14,4,8,12,5,9,13,10\]

**Constraints:**

*   The number of nodes in the tree is in the range `[0, 104]`.
*   `0 <= Node.val <= 104`
*   The height of the n-ary tree is less than or equal to `1000`.

**Follow up:** Recursive solution is trivial, could you do it iteratively?
N-ary Tree Postorder Traversal

Given the `root` of an n-ary tree, return _the postorder traversal of its nodes' values_.

Nary-Tree input serialization is represented in their level order traversal. Each group of children is separated by the null value (See examples)

**Example 1:**

**Input:** root = \[1,null,3,2,4,null,5,6\]
**Output:** \[5,6,3,2,4,1\]

**Example 2:**

**Input:** root = \[1,null,2,3,4,5,null,null,6,7,null,8,null,9,10,null,null,11,null,12,null,13,null,null,14\]
**Output:** \[2,6,14,11,7,3,12,8,4,13,9,10,5,1\]

**Constraints:**

*   The number of nodes in the tree is in the range `[0, 104]`.
*   `0 <= Node.val <= 104`
*   The height of the n-ary tree is less than or equal to `1000`.

**Follow up:** Recursive solution is trivial, could you do it iteratively?
Tag Validator

Given a string representing a code snippet, implement a tag validator to parse the code and return whether it is valid.

A code snippet is valid if all the following rules hold:

1.  The code must be wrapped in a **valid closed tag**. Otherwise, the code is invalid.
2.  A **closed tag** (not necessarily valid) has exactly the following format : `TAG_CONTENT`. Among them, is the start tag, and is the end tag. The TAG\_NAME in start and end tags should be the same. A closed tag is **valid** if and only if the TAG\_NAME and TAG\_CONTENT are valid.
3.  A **valid** `TAG_NAME` only contain **upper-case letters**, and has length in range \[1,9\]. Otherwise, the `TAG_NAME` is **invalid**.
4.  A **valid** `TAG_CONTENT` may contain other **valid closed tags**, **cdata** and any characters (see note1) **EXCEPT** unmatched `<`, unmatched start and end tag, and unmatched or closed tags with invalid TAG\_NAME. Otherwise, the `TAG_CONTENT` is **invalid**.
5.  A start tag is unmatched if no end tag exists with the same TAG\_NAME, and vice versa. However, you also need to consider the issue of unbalanced when tags are nested.
6.  A `<` is unmatched if you cannot find a subsequent `>`. And when you find a `<` or ``, all the subsequent characters until the next `>` should be parsed as TAG_NAME (not necessarily valid).``
``` *   The cdata has the following format : . The range of `CDATA_CONTENT` is defined as the characters between ``and the **first subsequent** `]]>`.`` ``*   `CDATA_CONTENT` may contain **any characters**. The function of cdata is to forbid the validator to parse `CDATA_CONTENT`, so even it has some characters that can be parsed as tag (no matter valid or invalid), you should treat it as **regular characters**.`` ```

``` ``  **Example 1:**  **Input:** code =  "  This is the first line ]]>   " **Output:** true **Explanation:**  The code is wrapped in a closed tag :    and   .  The TAG_NAME is valid, the TAG_CONTENT consists of some characters and cdata.  Although CDATA_CONTENT has an unmatched start tag with invalid TAG_NAME, it should be considered as plain text, not parsed as a tag. So TAG_CONTENT is valid, and then the code is valid. Thus return true.  **Example 2:**  **Input:** code =  "  >>  ![cdata[]] ]>]]>]]>>]   " **Output:** true **Explanation:** We first separate the code into : start_tag|tag_content|end_tag. start_tag -> ** "**   **"** end_tag -> ** "**   **"** tag_content could also be separated into : text1|cdata|text2. text1 -> ** ">>  ![cdata[]]  "** cdata -> ** "]>]]> "**, where the CDATA_CONTENT is ** "**  **]> "** text2 -> ** "]]>>] "** The reason why start_tag is NOT ** "**  **>> "** is because of the rule 6. The reason why cdata is NOT ** "]>]]>]]> "** is because of the rule 7.  **Example 3:**  **Input:** code =  "    " **Output:** false **Explanation:** Unbalanced. If  " " is closed, then  " **" must be unmatched, and vice versa.**  **  **Constraints:**  *   `1 <= code.length <= 500` *   `code` consists of English letters, digits, `'<'`, `'>'`, `'/'`, `'!'`, `'['`, `']'`, `'.'`, and `' '`.  **`` ```
Fraction Addition and Subtraction

Given a string `expression` representing an expression of fraction addition and subtraction, return the calculation result in string format.

The final result should be an [irreducible fraction](https://en.wikipedia.org/wiki/Irreducible_fraction). If your final result is an integer, change it to the format of a fraction that has a denominator `1`. So in this case, `2` should be converted to `2/1`.

**Example 1:**

**Input:** expression =  "-1/2+1/2 "
**Output:**  "0/1 "

**Example 2:**

**Input:** expression =  "-1/2+1/2+1/3 "
**Output:**  "1/3 "

**Example 3:**

**Input:** expression =  "1/3-1/2 "
**Output:**  "-1/6 "

**Constraints:**

*   The input string only contains `'0'` to `'9'`, `'/'`, `'+'` and `'-'`. So does the output.
*   Each fraction (input and output) has the format `±numerator/denominator`. If the first input fraction or the output is positive, then `'+'` will be omitted.
*   The input only contains valid **irreducible fractions**, where the **numerator** and **denominator** of each fraction will always be in the range `[1, 10]`. If the denominator is `1`, it means this fraction is actually an integer in a fraction format defined above.
*   The number of given fractions will be in the range `[1, 10]`.
*   The numerator and denominator of the **final result** are guaranteed to be valid and in the range of **32-bit** int.
Valid Square

Given the coordinates of four points in 2D space `p1`, `p2`, `p3` and `p4`, return `true` _if the four points construct a square_.

The coordinate of a point `pi` is represented as `[xi, yi]`. The input is **not** given in any order.

A **valid square** has four equal sides with positive length and four equal angles (90-degree angles).

**Example 1:**

**Input:** p1 = \[0,0\], p2 = \[1,1\], p3 = \[1,0\], p4 = \[0,1\]
**Output:** true

**Example 2:**

**Input:** p1 = \[0,0\], p2 = \[1,1\], p3 = \[1,0\], p4 = \[0,12\]
**Output:** false

**Example 3:**

**Input:** p1 = \[1,0\], p2 = \[-1,0\], p3 = \[0,1\], p4 = \[0,-1\]
**Output:** true

**Constraints:**

*   `p1.length == p2.length == p3.length == p4.length == 2`
*   `-104 <= xi, yi <= 104`
Longest Harmonious Subsequence

We define a harmonious array as an array where the difference between its maximum value and its minimum value is **exactly** `1`.

Given an integer array `nums`, return _the length of its longest harmonious subsequence among all its possible subsequences_.

A **subsequence** of array is a sequence that can be derived from the array by deleting some or no elements without changing the order of the remaining elements.

**Example 1:**

**Input:** nums = \[1,3,2,2,5,2,3,7\]
**Output:** 5
**Explanation:** The longest harmonious subsequence is \[3,2,2,2,3\].

**Example 2:**

**Input:** nums = \[1,2,3,4\]
**Output:** 2

**Example 3:**

**Input:** nums = \[1,1,1,1\]
**Output:** 0

**Constraints:**

*   `1 <= nums.length <= 2 * 104`
*   `-109 <= nums[i] <= 109`
Range Addition II

You are given an `m x n` matrix `M` initialized with all `0`'s and an array of operations `ops`, where `ops[i] = [ai, bi]` means `M[x][y]` should be incremented by one for all `0 <= x < ai` and `0 <= y < bi`.

Count and return _the number of maximum integers in the matrix after performing all the operations_.

**Example 1:**

**Input:** m = 3, n = 3, ops = \[\[2,2\],\[3,3\]\]
**Output:** 4
**Explanation:** The maximum integer in M is 2, and there are four of it in M. So return 4.

**Example 2:**

**Input:** m = 3, n = 3, ops = \[\[2,2\],\[3,3\],\[3,3\],\[3,3\],\[2,2\],\[3,3\],\[3,3\],\[3,3\],\[2,2\],\[3,3\],\[3,3\],\[3,3\]\]
**Output:** 4

**Example 3:**

**Input:** m = 3, n = 3, ops = \[\]
**Output:** 9

**Constraints:**

*   `1 <= m, n <= 4 * 104`
*   `0 <= ops.length <= 104`
*   `ops[i].length == 2`
*   `1 <= ai <= m`
*   `1 <= bi <= n`
Minimum Index Sum of Two Lists

Given two arrays of strings `list1` and `list2`, find the **common strings with the least index sum**.

A **common string** is a string that appeared in both `list1` and `list2`.

A **common string with the least index sum** is a common string such that if it appeared at `list1[i]` and `list2[j]` then `i + j` should be the minimum value among all the other **common strings**.

Return _all the **common strings with the least index sum**_. Return the answer in **any order**.

**Example 1:**

**Input:** list1 = \[ "Shogun ", "Tapioca Express ", "Burger King ", "KFC "\], list2 = \[ "Piatti ", "The Grill at Torrey Pines ", "Hungry Hunter Steakhouse ", "Shogun "\]
**Output:** \[ "Shogun "\]
**Explanation:** The only common string is  "Shogun ".

**Example 2:**

**Input:** list1 = \[ "Shogun ", "Tapioca Express ", "Burger King ", "KFC "\], list2 = \[ "KFC ", "Shogun ", "Burger King "\]
**Output:** \[ "Shogun "\]
**Explanation:** The common string with the least index sum is  "Shogun " with index sum = (0 + 1) = 1.

**Example 3:**

**Input:** list1 = \[ "happy ", "sad ", "good "\], list2 = \[ "sad ", "happy ", "good "\]
**Output:** \[ "sad ", "happy "\]
**Explanation:** There are three common strings:
 "happy " with index sum = (0 + 1) = 1.
 "sad " with index sum = (1 + 0) = 1.
 "good " with index sum = (2 + 2) = 4.
The strings with the least index sum are  "sad " and  "happy ".

**Constraints:**

*   `1 <= list1.length, list2.length <= 1000`
*   `1 <= list1[i].length, list2[i].length <= 30`
*   `list1[i]` and `list2[i]` consist of spaces `' '` and English letters.
*   All the strings of `list1` are **unique**.
*   All the strings of `list2` are **unique**.
*   There is at least a common string between `list1` and `list2`.
Non-negative Integers without Consecutive Ones

Given a positive integer `n`, return the number of the integers in the range `[0, n]` whose binary representations **do not** contain consecutive ones.

**Example 1:**

**Input:** n = 5
**Output:** 5
**Explanation:**
Here are the non-negative integers <= 5 with their corresponding binary representations:
0 : 0
1 : 1
2 : 10
3 : 11
4 : 100
5 : 101
Among them, only integer 3 disobeys the rule (two consecutive ones) and the other 5 satisfy the rule. 

**Example 2:**

**Input:** n = 1
**Output:** 2

**Example 3:**

**Input:** n = 2
**Output:** 3

**Constraints:**

*   `1 <= n <= 109`
Design Compressed String Iterator

Design and implement a data structure for a compressed string iterator. The given compressed string will be in the form of each letter followed by a positive integer representing the number of this letter existing in the original uncompressed string.

Implement the StringIterator class:

*   `next()` Returns **the next character** if the original string still has uncompressed characters, otherwise returns a **white space**.
*   `hasNext()` Returns true if there is any letter needs to be uncompressed in the original string, otherwise returns `false`.

**Example 1:**

**Input**
\[ "StringIterator ",  "next ",  "next ",  "next ",  "next ",  "next ",  "next ",  "hasNext ",  "next ",  "hasNext "\]
\[\[ "L1e2t1C1o1d1e1 "\], \[\], \[\], \[\], \[\], \[\], \[\], \[\], \[\], \[\]\]
**Output**
\[null,  "L ",  "e ",  "e ",  "t ",  "C ",  "o ", true,  "d ", true\]

**Explanation**
StringIterator stringIterator = new StringIterator( "L1e2t1C1o1d1e1 ");
stringIterator.next(); // return  "L "
stringIterator.next(); // return  "e "
stringIterator.next(); // return  "e "
stringIterator.next(); // return  "t "
stringIterator.next(); // return  "C "
stringIterator.next(); // return  "o "
stringIterator.hasNext(); // return True
stringIterator.next(); // return  "d "
stringIterator.hasNext(); // return True

**Constraints:**

*   `1 <= compressedString.length <= 1000`
*   `compressedString` consists of lower-case an upper-case English letters and digits.
*   The number of a single character repetitions in `compressedString` is in the range `[1, 10^9]`
*   At most `100` calls will be made to `next` and `hasNext`.
Can Place Flowers

You have a long flowerbed in which some of the plots are planted, and some are not. However, flowers cannot be planted in **adjacent** plots.

Given an integer array `flowerbed` containing `0`'s and `1`'s, where `0` means empty and `1` means not empty, and an integer `n`, return `true` _if_ `n` _new flowers can be planted in the_ `flowerbed` _without violating the no-adjacent-flowers rule and_ `false` _otherwise_.

**Example 1:**

**Input:** flowerbed = \[1,0,0,0,1\], n = 1
**Output:** true

**Example 2:**

**Input:** flowerbed = \[1,0,0,0,1\], n = 2
**Output:** false

**Constraints:**

*   `1 <= flowerbed.length <= 2 * 104`
*   `flowerbed[i]` is `0` or `1`.
*   There are no two adjacent flowers in `flowerbed`.
*   `0 <= n <= flowerbed.length`
Construct String from Binary Tree

Given the `root` of a binary tree, construct a string consisting of parenthesis and integers from a binary tree with the preorder traversal way, and return it.

Omit all the empty parenthesis pairs that do not affect the one-to-one mapping relationship between the string and the original binary tree.

**Example 1:**

**Input:** root = \[1,2,3,4\]
**Output:**  "1(2(4))(3) "
**Explanation:** Originally, it needs to be  "1(2(4)())(3()()) ", but you need to omit all the unnecessary empty parenthesis pairs. And it will be  "1(2(4))(3) "

**Example 2:**

**Input:** root = \[1,2,3,null,4\]
**Output:**  "1(2()(4))(3) "
**Explanation:** Almost the same as the first example, except we cannot omit the first parenthesis pair to break the one-to-one mapping relationship between the input and the output.

**Constraints:**

*   The number of nodes in the tree is in the range `[1, 104]`.
*   `-1000 <= Node.val <= 1000`
Find Duplicate File in System

Given a list `paths` of directory info, including the directory path, and all the files with contents in this directory, return _all the duplicate files in the file system in terms of their paths_. You may return the answer in **any order**.

A group of duplicate files consists of at least two files that have the same content.

A single directory info string in the input list has the following format:

*   `"root/d1/d2/.../dm f1.txt(f1_content) f2.txt(f2_content) ... fn.txt(fn_content) "`

It means there are `n` files `(f1.txt, f2.txt ... fn.txt)` with content `(f1_content, f2_content ... fn_content)` respectively in the directory "`root/d1/d2/.../dm "`. Note that `n >= 1` and `m >= 0`. If `m = 0`, it means the directory is just the root directory.

The output is a list of groups of duplicate file paths. For each group, it contains all the file paths of the files that have the same content. A file path is a string that has the following format:

*   `"directory_path/file_name.txt "`

**Example 1:**

**Input:** paths = \["root/a 1.txt(abcd) 2.txt(efgh)","root/c 3.txt(abcd)","root/c/d 4.txt(efgh)","root 4.txt(efgh)"\]
**Output:** \[\["root/a/2.txt","root/c/d/4.txt","root/4.txt"\],\["root/a/1.txt","root/c/3.txt"\]\]

**Example 2:**

**Input:** paths = \["root/a 1.txt(abcd) 2.txt(efgh)","root/c 3.txt(abcd)","root/c/d 4.txt(efgh)"\]
**Output:** \[\["root/a/2.txt","root/c/d/4.txt"\],\["root/a/1.txt","root/c/3.txt"\]\]

**Constraints:**

*   `1 <= paths.length <= 2 * 104`
*   `1 <= paths[i].length <= 3000`
*   `1 <= sum(paths[i].length) <= 5 * 105`
*   `paths[i]` consist of English letters, digits, `'/'`, `'.'`, `'('`, `')'`, and `' '`.
*   You may assume no files or directories share the same name in the same directory.
*   You may assume each given directory info represents a unique directory. A single blank space separates the directory path and file info.

**Follow up:**

*   Imagine you are given a real file system, how will you search files? DFS or BFS?
*   If the file content is very large (GB level), how will you modify your solution?
*   If you can only read the file by 1kb each time, how will you modify your solution?
*   What is the time complexity of your modified solution? What is the most time-consuming part and memory-consuming part of it? How to optimize?
*   How to make sure the duplicated files you find are not false positive?
Valid Triangle Number

Given an integer array `nums`, return _the number of triplets chosen from the array that can make triangles if we take them as side lengths of a triangle_.

**Example 1:**

**Input:** nums = \[2,2,3,4\]
**Output:** 3
**Explanation:** Valid combinations are: 
2,3,4 (using the first 2)
2,3,4 (using the second 2)
2,2,3

**Example 2:**

**Input:** nums = \[4,2,3,4\]
**Output:** 4

**Constraints:**

*   `1 <= nums.length <= 1000`
*   `0 <= nums[i] <= 1000`
Add Bold Tag in String

You are given a string `s` and an array of strings `words`.

You should add a closed pair of bold tag **and** to wrap the substrings in `s` that exist in `words`.

*   If two such substrings overlap, you should wrap them together with only one pair of closed bold-tag.
*   If two substrings wrapped by bold tags are consecutive, you should combine them.

Return `s` _after adding the bold tags_.

**Example 1:**

**Input:** s =  "abcxyz123 ", words = \[ "abc ", "123 "\]
**Output:**  "**abc**xyz**123** "
**Explanation:** The two strings of words are substrings of s as following:  "abcxyz123 ".
We add ** before each substring and ** after each substring.

**Example 2:**

**Input:** s =  "aaabbb ", words = \[ "aa ", "b "\]
**Output:**  "**aaabbb** "
**Explanation:** 
 "aa " appears as a substring two times:  "aaabbb " and  "aaabbb ".
 "b " appears as a substring three times:  "aaabbb ",  "aaabbb ", and  "aaabbb ".
We add ** before each substring and ** after each substring:  "**a**a**a****b****b****b** ".
Since the first two **'s overlap, we merge them:  "**aaa****b****b****b** ".
Since now the four **'s are consecuutive, we merge them:  "**aaabbb** ".****

****

**Constraints:**

*   `1 <= s.length <= 1000`
*   `0 <= words.length <= 100`
*   `1 <= words[i].length <= 1000`
*   `s` and `words[i]` consist of English letters and digits.
*   All the values of `words` are **unique**.

**Note:** This question is the same as 758: [https://leetcode.com/problems/bold-words-in-string/](https://leetcode.com/problems/bold-words-in-string/)

****
Merge Two Binary Trees

You are given two binary trees `root1` and `root2`.

Imagine that when you put one of them to cover the other, some nodes of the two trees are overlapped while the others are not. You need to merge the two trees into a new binary tree. The merge rule is that if two nodes overlap, then sum node values up as the new value of the merged node. Otherwise, the NOT null node will be used as the node of the new tree.

Return _the merged tree_.

**Note:** The merging process must start from the root nodes of both trees.

**Example 1:**

**Input:** root1 = \[1,3,2,5\], root2 = \[2,1,3,null,4,null,7\]
**Output:** \[3,4,5,5,4,null,7\]

**Example 2:**

**Input:** root1 = \[1\], root2 = \[1,2\]
**Output:** \[2,2\]

**Constraints:**

*   The number of nodes in both trees is in the range `[0, 2000]`.
*   `-104 <= Node.val <= 104`
Task Scheduler

Given a characters array `tasks`, representing the tasks a CPU needs to do, where each letter represents a different task. Tasks could be done in any order. Each task is done in one unit of time. For each unit of time, the CPU could complete either one task or just be idle.

However, there is a non-negative integer `n` that represents the cooldown period between two **same tasks** (the same letter in the array), that is that there must be at least `n` units of time between any two same tasks.

Return _the least number of units of times that the CPU will take to finish all the given tasks_.

**Example 1:**

**Input:** tasks = \[ "A ", "A ", "A ", "B ", "B ", "B "\], n = 2
**Output:** 8
**Explanation:** 
A -> B -> idle -> A -> B -> idle -> A -> B
There is at least 2 units of time between any two same tasks.

**Example 2:**

**Input:** tasks = \[ "A ", "A ", "A ", "B ", "B ", "B "\], n = 0
**Output:** 6
**Explanation:** On this case any permutation of size 6 would work since n = 0.
\[ "A ", "A ", "A ", "B ", "B ", "B "\]
\[ "A ", "B ", "A ", "B ", "A ", "B "\]
\[ "B ", "B ", "B ", "A ", "A ", "A "\]
...
And so on.

**Example 3:**

**Input:** tasks = \[ "A ", "A ", "A ", "A ", "A ", "A ", "B ", "C ", "D ", "E ", "F ", "G "\], n = 2
**Output:** 16
**Explanation:** 
One possible solution is
A -> B -> C -> A -> D -> E -> A -> F -> G -> A -> idle -> idle -> A -> idle -> idle -> A

**Constraints:**

*   `1 <= task.length <= 104`
*   `tasks[i]` is upper-case English letter.
*   The integer `n` is in the range `[0, 100]`.