Skip to content
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
26 changes: 26 additions & 0 deletions 950. Reveal Cards In Increasing Order
Original file line number Diff line number Diff line change
@@ -0,0 +1,26 @@
class Solution {
public:
vector<int> deckRevealedIncreasing(vector<int>& deck) {
sort(deck.begin(), deck.end()); // Sort the deck in increasing order

int n = deck.size();
vector<int> result(n);
deque<int> indices;

for (int i = 0; i < n; i++) {
indices.push_back(i); // Initialize deque with indices 0, 1, 2, ..., n-1
}

for (int card : deck) {
int idx = indices.front(); // Get the next available index
indices.pop_front(); // Remove the index from the front
result[idx] = card; // Place the card in the result array
if (!indices.empty()) {
indices.push_back(indices.front()); // Move the used index to the end of deque
indices.pop_front(); // Remove the index from the front
}
}

return result;
}
};