You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
Copy file name to clipboardexpand all lines: solution/2800-2899/2869.Minimum Operations to Collect Elements/README_EN.md
+66-7
Original file line number
Diff line number
Diff line change
@@ -47,12 +47,29 @@
47
47
48
48
## Solutions
49
49
50
+
**Solution 1: Traverse in Reverse Order**
51
+
52
+
We can traverse the array in reverse order. For each element encountered during the traversal that is less than or equal to $k$ and has not been added to the set yet, we add it to the set until the set contains elements from $1$ to $k$.
53
+
54
+
The time complexity is $O(n)$, where $n$ is the length of the array $nums$. The space complexity is $O(k)$.
0 commit comments