a few solutions
LeetCode Daily: June 12th 2022\n\nUse a sliding window i..j inclusive tracking total t sum of uniquely seen values of the input array A to find and return the b
**LeetCode Daily: June 12<sup>th</sup> 2022**\n\nUse a sliding window `i..j` inclusive tracking total `t` sum of uniquely `seen` values of the input array `A` to find and return the `best` total `t` sum.\n\n*Kotlin*\n```\nclass Solution {\n    fun maximumUniqueSubarray(A: IntArray): Int {\n        var best = 0\n        var (N, i, j) = Triple(A.size, 0, 0)\n        var (t, seen) = Pair(0, mutableSetOf<Int>())\n        while (j < N) {\n            while (seen.contains(A[j])) {\n                t -= A[i]; seen.remove(A[i]); ++i\n            }\n            t += A[j]; seen.add(A[j]); ++j\n            best = Math.max(best, t)\n        }\n        return best\n    }\n}\n```\n\n*Javascript*\n```\nlet maximumUniqueSubarray = (A, best = 0) => {\n    let [N, i, j] = [A.length, 0, 0];\n    let [t, seen] = [0, new Set()];\n    while (j < N) {\n        while (seen.has(A[j]))\n            t -= A[i], seen.delete(A[i]), ++i;\n        t += A[j], seen.add(A[j]), ++j;\n        best = Math.max(best, t);\n    }\n    return best;\n};\n```\n\n*Python3*\n```\nclass Solution:\n    def maximumUniqueSubarray(self, A: List[int], best = 0) -> int:\n        N, i, j = len(A), 0, 0\n        t, seen = 0, set()\n        while j < N:\n            while A[j] in seen:\n                t -= A[i]; seen.remove(A[i]); i += 1\n            t += A[j]; seen.add(A[j]); j += 1\n            best = max(best, t)\n        return best\n```\n\n*Rust*\n```\nuse std::cmp::max;\nuse std::collections::HashSet;\nimpl Solution {\n    pub fn maximum_unique_subarray(A: Vec<i32>) -> i32 {\n        let mut best = 0;\n        let (N, mut i, mut j) = (A.len(), 0, 0);\n        let (mut t, mut seen) = (0, HashSet::new());\n        while j < N {\n            while seen.contains(&A[j]) {\n                t -= A[i]; seen.remove(&A[i]); i += 1;\n            }\n            t += A[j]; seen.insert(&A[j]); j += 1;\n            best = max(best, t);\n        }\n        return best;\n    }\n}\n```\n\n*C++*\n```\nclass Solution {\npublic:\n    using VI = vector<int>;\n    using Set = unordered_set<int>;\n    int maximumUniqueSubarray(VI& A, int best = 0) {\n        auto [N, i, j] = make_tuple(A.size(), 0, 0);\n        auto [t, seen] = make_pair(0, Set{});\n        while (j < N) {\n            while (seen.find(A[j]) != seen.end())\n                t -= A[i], seen.erase(A[i]), ++i;\n            t += A[j], seen.insert(A[j]), ++j;\n            best = max(best, t);\n        }\n        return best;\n    }\n};\n```\n\n---\n\n**Legacy Solutions from May 28, 2021:**\n\nUse a sliding window `i..j` to track the `best` total sum of unique adjacent values of the input array `A`.\n* We shrink the window to exclude each `i`<sup>th</sup> value of `A` to maintain the loop invarant, ie. the `total` sum for each window from `i..j` inclusive is comprised of  uniquely `seen` values.\n* We expand the window to include each `j`<sup>th</sup> value of `A`.\n\n\n*Kotlin*\n```\nclass Solution {\n    fun maximumUniqueSubarray(A: IntArray): Int {\n        var best = 0\n        var total = 0\n        var seen = mutableSetOf<Int>()\n        var N = A.size\n        var i = 0\n        var j = 0\n        while (j < N) {\n            if (seen.contains(A[j])) {    // \uD83D\uDC49 shrink window to maintain loop invariant A[i..j] \uD83D\uDC40 uniquely seen\n                total -= A[i]\n                seen.remove(A[i++])\n            } else {                      // \uD83D\uDC49 expand window\n                total += A[j]\n                seen.add(A[j++])\n            }\n            best = Math.max(best, total)  // \uD83C\uDFAF best total A[i..j]\n        }\n        return best\n    }\n}\n```\n\n*Javascript*\n```\nlet maximumUniqueSubarray = (A, seen = new Set(), total = 0, best = 0) => {\n    let N = A.length,\n        i = 0,\n        j = 0;\n    while (j < N) {\n        if (seen.has(A[j]))            // \uD83D\uDC49 shrink window to maintain loop invariant A[i..j] \uD83D\uDC40 uniquely seen\n            total -= A[i],\n            seen.delete(A[i++]);\n        else                           // \uD83D\uDC49 expand window\n            total += A[j],  \n            seen.add(A[j++]);\n        best = Math.max(best, total);  // \uD83C\uDFAF best total A[i..j]\n    }\n    return best;\n};\n```\n\n*Python3*\n```\nclass Solution:\n    def maximumUniqueSubarray(self, A: List[int], total = 0, best = 0) -> int:\n        seen = set()\n        N = len(A)\n        i = 0\n        j = 0\n        while j < N:\n            if A[j] in seen:         # \uD83D\uDC49 shrink window to maintain loop invariant A[i..j] \uD83D\uDC40 uniquely seen\n                total -= A[i]\n                seen.remove(A[i])\n                i += 1\n            else:                    # \uD83D\uDC49 expand window\n                total += A[j]\n                seen.add(A[j])\n                j += 1\n            best = max(best, total)  # \uD83C\uDFAF best total A[i..j]\n        return best\n```\n\n*C++*\n```\nclass Solution {\npublic:\n    using VI = vector<int>;\n    using Set = unordered_set<int>;\n    int maximumUniqueSubarray(VI& A, Set seen = {}, int total = 0, int best = 0) {\n        int N = A.size(),\n            i = 0,\n            j = 0;\n        while (j < N) {\n            if (seen.find(A[j]) != seen.end())  // \uD83D\uDC49 shrink window to maintain loop invariant A[i..j] \uD83D\uDC40 uniquely seen\n                total -= A[i],\n                seen.erase(A[i++]);\n            else                                // \uD83D\uDC49 expand window\n                total += A[j],\n                seen.insert(A[j++]);\n            best = max(best, total);            // \uD83C\uDFAF best total A[i..j]\n        }\n        return best;\n    }\n};\n```
[]