We read every piece of feedback, and take your input very seriously.
To see all available qualifiers, see our documentation.
There was an error while loading. Please reload this page.
2 parents 9b5e882 + e9f240d commit 85c784fCopy full SHA for 85c784f
1079. Letter Tile Possibilities
@@ -0,0 +1,28 @@
1
+class Solution {
2
+public:
3
+ void count(vector<int> &arr, int n, int &ans){
4
+ //checks if every place is filled.
5
+ if(n <= 0) return;
6
+ //checking for letters which can be filled at nth index.
7
+ for(int i = 0; i < 26; i++){
8
+ if(arr[i] > 0){
9
+ // Reducing its occurence.
10
+ arr[i]--;
11
+ ans++;
12
+ count(arr, n - 1, ans);
13
+ //Restoring its occurence for furthur combination./Backtracking.
14
+ arr[i]++;
15
+ }
16
17
18
+ int numTilePossibilities(string tiles) {
19
+ vector<int> arr(26, 0);
20
+ //Occurence count array.
21
+ for(int i = 0; i < tiles.size(); i++){
22
+ arr[int(tiles[i]) - 65]++;
23
24
+ int ans = 0;
25
+ count(arr, tiles.size(), ans);
26
+ return ans;
27
28
+};
0 commit comments