From d42b19f40757dbbac64e69f102fd10b3a6c71f83 Mon Sep 17 00:00:00 2001
From: JAYNISH MEHTA <112923627+jaynishmehta@users.noreply.github.com>
Date: Sun, 19 May 2024 23:20:00 +0530
Subject: [PATCH 1/3] Create README - LeetHub
---
0904-fruit-into-baskets/README.md | 44 +++++++++++++++++++++++++++++++
1 file changed, 44 insertions(+)
create mode 100644 0904-fruit-into-baskets/README.md
diff --git a/0904-fruit-into-baskets/README.md b/0904-fruit-into-baskets/README.md
new file mode 100644
index 0000000..d8e708d
--- /dev/null
+++ b/0904-fruit-into-baskets/README.md
@@ -0,0 +1,44 @@
+
You are visiting a farm that has a single row of fruit trees arranged from left to right. The trees are represented by an integer array fruits
where fruits[i]
is the type of fruit the ith
tree produces.
+
+
You want to collect as much fruit as possible. However, the owner has some strict rules that you must follow:
+
+
+ - You only have two baskets, and each basket can only hold a single type of fruit. There is no limit on the amount of fruit each basket can hold.
+ - Starting from any tree of your choice, you must pick exactly one fruit from every tree (including the start tree) while moving to the right. The picked fruits must fit in one of your baskets.
+ - Once you reach a tree with fruit that cannot fit in your baskets, you must stop.
+
+
+
Given the integer array fruits
, return the maximum number of fruits you can pick.
+
+
+
Example 1:
+
+
Input: fruits = [1,2,1]
+Output: 3
+Explanation: We can pick from all 3 trees.
+
+
+
Example 2:
+
+
Input: fruits = [0,1,2,2]
+Output: 3
+Explanation: We can pick from trees [1,2,2].
+If we had started at the first tree, we would only pick from trees [0,1].
+
+
+
Example 3:
+
+
Input: fruits = [1,2,3,2,2]
+Output: 4
+Explanation: We can pick from trees [2,3,2,2].
+If we had started at the first tree, we would only pick from trees [1,2].
+
+
+
+
Constraints:
+
+
+ 1 <= fruits.length <= 105
+ 0 <= fruits[i] < fruits.length
+
+
\ No newline at end of file
From 1a4ff5e2737ed920fbbf9039b85e26173d4fd102 Mon Sep 17 00:00:00 2001
From: JAYNISH MEHTA <112923627+jaynishmehta@users.noreply.github.com>
Date: Sun, 19 May 2024 23:20:01 +0530
Subject: [PATCH 2/3] Attach NOTES - LeetHub
---
0904-fruit-into-baskets/NOTES.md | 1 +
1 file changed, 1 insertion(+)
create mode 100644 0904-fruit-into-baskets/NOTES.md
diff --git a/0904-fruit-into-baskets/NOTES.md b/0904-fruit-into-baskets/NOTES.md
new file mode 100644
index 0000000..38c1374
--- /dev/null
+++ b/0904-fruit-into-baskets/NOTES.md
@@ -0,0 +1 @@
+
\ No newline at end of file
From c273bcab62c1efed51aa51e7f379ecb4e024ab3c Mon Sep 17 00:00:00 2001
From: JAYNISH MEHTA <112923627+jaynishmehta@users.noreply.github.com>
Date: Sun, 19 May 2024 23:20:02 +0530
Subject: [PATCH 3/3] Time: 128 ms (39.50%), Space: 77.7 MB (8.94%) - LeetHub
---
.../0904-fruit-into-baskets.cpp | 22 +++++++++++++++++++
1 file changed, 22 insertions(+)
create mode 100644 0904-fruit-into-baskets/0904-fruit-into-baskets.cpp
diff --git a/0904-fruit-into-baskets/0904-fruit-into-baskets.cpp b/0904-fruit-into-baskets/0904-fruit-into-baskets.cpp
new file mode 100644
index 0000000..1f89d63
--- /dev/null
+++ b/0904-fruit-into-baskets/0904-fruit-into-baskets.cpp
@@ -0,0 +1,22 @@
+class Solution {
+public:
+ int totalFruit(vector