diff --git a/java/1220-count-vowels-permutation.java b/java/1220-count-vowels-permutation.java index a82106165..88a8779c7 100644 --- a/java/1220-count-vowels-permutation.java +++ b/java/1220-count-vowels-permutation.java @@ -1,3 +1,9 @@ +/* Bottom-Up Approach +----------------------------------------- + Time Complexity : O(n) + Space Complexity : O(n) +----------------------------------------*/ + class Solution { int MOD = (int) 1e9+7; @@ -39,19 +45,42 @@ class Solution { int MOD = (int) 1e9+7; public int countVowelPermutation(int n) { - long[] counts = getBaseCounts(); - if(n == 1) { - return getSum(counts); - } + long ans = 0; + ans = (ans + dfs('a', n, 1)) % MOD; + ans = (ans + dfs('e', n, 1)) % MOD; + ans = (ans + dfs('i', n, 1)) % MOD; + ans = (ans + dfs('o', n, 1)) % MOD; + ans = (ans + dfs('u', n, 1)) % MOD; + return (int)ans; + } + + private int dfs(char c, int n, int l){ + if(l == n) + return 1; - Map> mapNextCounting; - mapNextCounting = getNextCountMapping(); - - for(int i=1; i List[str]: + result = [] + n = len(nums) + if n == 0: + return result + + # Pointer to the start of the current range + start = 0 + + for i in range(1, n + 1): # Iterate until the end of the array + # If we're at the end of the array or the range breaks + if i == n or nums[i] != nums[i - 1] + 1: + # Single number range + if start == i - 1: + result.append(str(nums[start])) + # Continuous range + else: + result.append(f"{nums[start]}->{nums[i - 1]}") + # Update start for the next range + start = i + + return result \ No newline at end of file