diff --git a/904. Fruit Into Baskets b/904. Fruit Into Baskets new file mode 100644 index 0000000..713fa2b --- /dev/null +++ b/904. Fruit Into Baskets @@ -0,0 +1,27 @@ +class Solution { +public: + int totalFruit(vector& fruits) { + int windowstart = 0 ; + int maxfruits = 0 ; + unordered_mapfruitfrequency; + + for(int windowend = 0 ; windowend2){ + fruitfrequency[fruits[windowstart]]--; + + if( fruitfrequency[fruits[windowstart]]==0 ){ + fruitfrequency.erase(fruits[windowstart]); + + } + + windowstart++; + } + maxfruits = max(maxfruits , windowend - windowstart +1 ); + } + return maxfruits; + } + +};