diff --git a/README.md b/README.md index 64220e295..06737598c 100644 --- a/README.md +++ b/README.md @@ -182,7 +182,7 @@ If you would like to have collaborator permissions on the repo to merge your own [0024 - Swap Nodes In Pairs](https://leetcode.com/problems/swap-nodes-in-pairs/) |
|
|
|
|
[✔️](go%2F0024-swap-nodes-in-pairs.go)
|
[✔️](java%2F0024-swap-nodes-in-pairs.java)
|
|
|
[✔️](python%2F0024-swap-nodes-in-pairs.py)
|
|
|
|
|
[0148 - Sort List](https://leetcode.com/problems/sort-list/) |
[✔️](c%2F0148-sort-list.c)
|
|
|
|
|
[✔️](java%2F0148-sort-list.java)
|
|
|
[✔️](python%2F0148-sort-list.py)
|
|
|
|
|
[0086 - Partition List](https://leetcode.com/problems/partition-list/) |
|
|
|
|
|
[✔️](java%2F0086-partition-list.java)
|
|
|
[✔️](python%2F0086-partition-list.py)
|
|
|
|
|
-[0061 - Rotate List](https://leetcode.com/problems/rotate-list/) |
|
|
|
|
|
[✔️](java%2F0061-rotate-list.java)
|
|
|
[✔️](python%2F0061-rotate-list.py)
|
|
|
|
|
+[0061 - Rotate List](https://leetcode.com/problems/rotate-list/) |
|
[✔️](cpp%2F0061-rotate-list.cpp)
|
|
|
|
[✔️](java%2F0061-rotate-list.java)
|
|
|
[✔️](python%2F0061-rotate-list.py)
|
|
|
|
|
[0092 - Reverse Linked List II](https://leetcode.com/problems/reverse-linked-list-ii/) |
|
|
|
|
|
|
[✔️](javascript%2F0092-reverse-linked-list-ii.js)
|
|
[✔️](python%2F0092-reverse-linked-list-ii.py)
|
|
|
|
|
[0622 - Design Circular Queue](https://leetcode.com/problems/design-circular-queue/) |
|
|
|
|
[✔️](go%2F0622-design-circular-queue.go)
|
|
|
[✔️](kotlin%2F0622-design-circular-queue.kt)
|
[✔️](python%2F0622-design-circular-queue.py)
|
|
|
|
|
[0147 - Insertion Sort List](https://leetcode.com/problems/insertion-sort-list/) |
|
|
|
|
|
|
|
|
[✔️](python%2F0147-insertion-sort-list.py)
|
|
|
|
|
@@ -364,7 +364,7 @@ If you would like to have collaborator permissions on the repo to merge your own [5782 - Maximum Alternating Subsequence Sum](https://leetcode.com/problems/maximum-alternating-subsequence-sum/) |
|
|
|
|
|
|
|
|
|
|
|
|
|
[0115 - Distinct Subsequences](https://leetcode.com/problems/distinct-subsequences/) |
|
[✔️](cpp%2F0115-distinct-subsequences.cpp)
|
[✔️](csharp%2F0115-distinct-subsequences.cs)
|
|
|
[✔️](java%2F0115-distinct-subsequences.java)
|
[✔️](javascript%2F0115-distinct-subsequences.js)
|
|
[✔️](python%2F0115-distinct-subsequences.py)
|
|
|
|
|
[✔️](typescript%2F0115-distinct-subsequences.ts)
[0072 - Edit Distance](https://leetcode.com/problems/edit-distance/) |
|
[✔️](cpp%2F0072-edit-distance.cpp)
|
[✔️](csharp%2F0072-edit-distance.cs)
|
|
|
[✔️](java%2F0072-edit-distance.java)
|
[✔️](javascript%2F0072-edit-distance.js)
|
[✔️](kotlin%2F0072-edit-distance.kt)
|
[✔️](python%2F0072-edit-distance.py)
|
|
|
[✔️](scala%2F0072-edit-distance.scala)
|
[✔️](swift%2F0072-edit-distance.swift)
|
-[1220 - Count Vowels Permutation](https://leetcode.com/problems/count-vowels-permutation/) |
|
|
|
|
[✔️](go%2F1220-count-vowels-permutation.go)
|
[✔️](java%2F1220-Count-Vowels-Permutation.java)
|
|
|
[✔️](python%2F1220-count-vowels-permutation.py)
|
|
|
|
|
+[1220 - Count Vowels Permutation](https://leetcode.com/problems/count-vowels-permutation/) |
|
[✔️](cpp%2F1220-count-vowels-permutation.cpp)
|
|
|
[✔️](go%2F1220-count-vowels-permutation.go)
|
[✔️](java%2F1220-Count-Vowels-Permutation.java)
|
|
|
[✔️](python%2F1220-count-vowels-permutation.py)
|
|
|
|
|
[0312 - Burst Balloons](https://leetcode.com/problems/burst-balloons/) |
|
[✔️](cpp%2F0312-burst-balloons.cpp)
|
[✔️](csharp%2F0312-burst-balloons.cs)
|
|
|
[✔️](java%2F0312-burst-balloons.java)
|
[✔️](javascript%2F0312-burst-balloons.js)
|
[✔️](kotlin%2F0312-burst-balloons.kt)
|
[✔️](python%2F0312-burst-balloons.py)
|
|
|
|
|
[✔️](typescript%2F0312-burst-balloons.ts)
[1866 - Number of Ways to Rearrange Sticks With K Sticks Visible](https://leetcode.com/problems/number-of-ways-to-rearrange-sticks-with-k-sticks-visible/) |
|
|
|
|
|
|
|
|
|
|
|
|
|
[0010 - Regular Expression Matching](https://leetcode.com/problems/regular-expression-matching/) |
|
[✔️](cpp%2F0010-regular-expression-matching.cpp)
|
[✔️](csharp%2F0010-regular-expression-matching.cs)
|
|
[✔️](go%2F0010-regular-expression-matching.go)
|
[✔️](java%2F0010-regular-expression-matching.java)
|
[✔️](javascript%2F0010-regular-expression-matching.js)
|
|
[✔️](python%2F0010-regular-expression-matching.py)
|
|
|
|
|
[✔️](typescript%2F0010-regular-expression-matching.ts)
diff --git a/cpp/1220-count-vowels-permutation.cpp b/cpp/1220-count-vowels-permutation.cpp new file mode 100644 index 000000000..45d35ed76 --- /dev/null +++ b/cpp/1220-count-vowels-permutation.cpp @@ -0,0 +1,42 @@ +/* +Given an integer n, our task is to count how many strings of length n can be formed under the following rules: + +Each character is a lower case vowel ('a', 'e', 'i', 'o', 'u') +Each vowel 'a' may only be followed by an 'e'. +Each vowel 'e' may only be followed by an 'a' or an 'i'. +Each vowel 'i' may not be followed by another 'i'. +Each vowel 'o' may only be followed by an 'i' or a 'u'. +Each vowel 'u' may only be followed by an 'a'. +Since the answer may be too large, we have to return it modulo 10^9 + 7. + +Example. For n = 2, Output = 10 + + Explanation: All possible strings of length 2 that can be formed as per the given rules are: "ae", "ea", "ei", "ia", "ie", "io", "iu", + "oi", "ou" and "ua". + So we return 10 as our answer. + + +Time: O(n) +Space: O(1) + +*/ + + +class Solution { +const unsigned int mod = 1e9+7; +public: + int countVowelPermutation(int n) { + vector prev(5,1), curr(5, 0); + for(int i=1; i nums[largest]) + largest = left + if(right < n && nums[right] > nums[largest]) + largest = right + + if(largest != i) { + nums.swap(i, largest) + heapify(nums, n, largest) + } + } + + fun IntArray.swap(i: Int, j: Int) { + this[i] = this[j].also{ this[j] = this[i] } + } +}