950. Reveal Cards In Increasing Order
T: O(nlogn)
S: O(n)
```java
class Solution {
public int[] deckRevealedIncreasing(int[] deck) {
int n = deck.length;
Arrays.sort(deck); // now become decresing
Queue<Integer> queue = new LinkedList<>();
for (int i = n - 1; i >= 0; i--) {
if (!queue.isEmpty()) {
queue.offer(queue.poll());
}
queue.offer(deck[i]);
}
int[] result = new int[n];
for (int i = n - 1; i >= 0; i--) {
result[i] = queue.poll();
}
return result;
}
}
/*
move top from deck to result top
move next deck to deck buttom
result is increasing
make result(input, deck) is descreasing (do a sort -> incresing to decresing)
deck(res) buttom to deck top (so poll and offer)
result top(input top) to deck top (desck last one , and offer to queue)
at last, add queue result to int[]
so from queue start map to end -> int[], use poll to add in int[] last index to index 0
T: O(nlogn)
S: O(n)
*/
```
Last updated