Data Structures & AlgorithmsVery hardGATE CS · ICPC regional
How many permutations of 0, 1, 2, 3, 4 are alternating, meaning p[0] < p[1] > p[2] < p[3] > p[4]?
- A. 16
- B. 32
- C. 5
- D. 60
Correct answer: A. 16
This is the Euler zigzag number E₅ = 16 for the pattern starting with an ascent. Counting alternating permutations with a DP over the last element and the direction of the last step gives the same value.
Practise more Arrays, Strings, Linked Lists, Stacks, Queues and Hashing questionsArrays, Strings, Linked Lists, Stacks, Queues and Hashing: notes and key points
More Arrays, Strings, Linked Lists, Stacks, Queues and Hashing questions
- What is the smallest positive integer x such that x! (x factorial) ends with at least 1000 zeros?
- How many substrings of "abcabcb" contain at least one each of the letters a, b and c?
- What is the length of the shortest substring of "aabcbcdbca" that contains every distinct letter appearing in the whole string at least…
- How many contiguous subarrays of [4, 2, 3, 1, 6, 5, 7, 9] satisfy max − min = (length of the subarray) − 1? Count every such subarray…
- What is the length of the longest substring of "bbaacabaacb" that contains EXACTLY two letters 'a'?
- Choose exactly 4 elements of [6, 1, 9, 4, 7, 2, 8, 5] (by position) such that no two chosen positions are adjacent. What is the maximum…