950. Reveal Cards In Increasing Order Medium

@problem@discussion
#Array#Queue#Sorting#Simulation



1/**
2 * [950] Reveal Cards In Increasing Order
3 *
4 * You are given an integer array deck. There is a deck of cards where every card has a unique integer. The integer on the i^th card is deck[i].
5 * You can order the deck in any order you want. Initially, all the cards start face down (unrevealed) in one deck.
6 * You will do the following steps repeatedly until all cards are revealed:
7 * <ol>
8 * 	Take the top card of the deck, reveal it, and take it out of the deck.
9 * 	If there are still cards in the deck then put the next top card of the deck at the bottom of the deck.
10 * 	If there are still unrevealed cards, go back to step 1. Otherwise, stop.
11 * </ol>
12 * Return an ordering of the deck that would reveal the cards in increasing order.
13 * Note that the first entry in the answer is considered to be the top of the deck.
14 *  
15 * Example 1:
16 * 
17 * Input: deck = [17,13,11,2,3,5,7]
18 * Output: [2,13,3,11,5,17,7]
19 * Explanation: 
20 * We get the deck in the order [17,13,11,2,3,5,7] (this order does not matter), and reorder it.
21 * After reordering, the deck starts as [2,13,3,11,5,17,7], where 2 is the top of the deck.
22 * We reveal 2, and move 13 to the bottom.  The deck is now [3,11,5,17,7,13].
23 * We reveal 3, and move 11 to the bottom.  The deck is now [5,17,7,13,11].
24 * We reveal 5, and move 17 to the bottom.  The deck is now [7,13,11,17].
25 * We reveal 7, and move 13 to the bottom.  The deck is now [11,17,13].
26 * We reveal 11, and move 17 to the bottom.  The deck is now [13,17].
27 * We reveal 13, and move 17 to the bottom.  The deck is now [17].
28 * We reveal 17.
29 * Since all the cards revealed are in increasing order, the answer is correct.
30 * 
31 * Example 2:
32 * 
33 * Input: deck = [1,1000]
34 * Output: [1,1000]
35 * 
36 *  
37 * Constraints:
38 * 
39 * 	1 <= deck.length <= 1000
40 * 	1 <= deck[i] <= 10^6
41 * 	All the values of deck are unique.
42 * 
43 */
44pub struct Solution {}
45
46// problem: https://leetcode.com/problems/reveal-cards-in-increasing-order/
47// discuss: https://leetcode.com/problems/reveal-cards-in-increasing-order/discuss/?currentPage=1&orderBy=most_votes&query=
48
49// submission codes start here
50
51impl Solution {
52    pub fn deck_revealed_increasing(deck: Vec<i32>) -> Vec<i32> {
53        vec![]
54    }
55}
56
57// submission codes end
58
59#[cfg(test)]
60mod tests {
61    use super::*;
62
63    #[test]
64    fn test_950() {
65    }
66}
67


Back
© 2025 bowen.ge All Rights Reserved.