Untitled
unknown
c_cpp
a year ago
656 B
6
Indexable
#include <vector> #include <algorithm> using namespace std; int removeBoxes(vector<int> boxes, int capacity) { sort(boxes.begin(), boxes.end()); int left = 0, right = boxes.size() - 1; int min_boxes_to_remove = boxes.size(); while (right >= 0) { // Adjust left pointer to the smallest valid box in the remaining subset while (left <= right && boxes[right] > capacity * boxes[left]) { left++; } // Calculate the number of boxes to remove min_boxes_to_remove = min(min_boxes_to_remove, left + (boxes.size() - 1 - right)); right--; } return min_boxes_to_remove; }
Editor is loading...
Leave a Comment