From bdf34037196881ae1bcb7d078825d3b5b4294079 Mon Sep 17 00:00:00 2001 From: chayan das Date: Mon, 4 Aug 2025 23:28:06 +0530 Subject: [PATCH] Create 904. Fruit Into Baskets --- 904. Fruit Into Baskets | 27 +++++++++++++++++++++++++++ 1 file changed, 27 insertions(+) create mode 100644 904. Fruit Into Baskets 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; + } + +};