File tree 2 files changed +46
-6
lines changed
2 files changed +46
-6
lines changed Original file line number Diff line number Diff line change @@ -18,14 +18,14 @@ string LongestRepeatedSubstr(string s)
18
18
sub = s.substr (i,j);
19
19
20
20
// if substring found again, simply increase the count;
21
- if (m.find (sub)! =m.end ())
21
+ if (m.find (sub)= =m.end ())
22
22
{
23
- m[sub]++ ;
23
+ m[sub] = 1 ;
24
24
}
25
25
26
26
27
27
// otherwise,if not found insert it in map with count as 1
28
- else m[sub] = 1 ;
28
+ else m[sub]++ ;
29
29
}
30
30
31
31
}
@@ -50,7 +50,7 @@ string LongestRepeatedSubstr(string s)
50
50
51
51
int main ()
52
52
{
53
- string str = " geeksforgeeks " ;
53
+ string str = " abcpqrabpqpq " ;
54
54
55
55
cout<<LongestRepeatedSubstr (str);
56
56
return 0 ;
Original file line number Diff line number Diff line change 1
1
#include < iostream>
2
2
#include < vector>
3
- #include < cctype>
4
3
#include < algorithm>
5
4
#include < string>
6
5
@@ -80,10 +79,51 @@ void SpecialSubMain(string s)
80
79
81
80
}
82
81
82
+
83
+ int binomEfficient (int n,int k)
84
+ {
85
+ int res = 1 ;
86
+
87
+ if (n==k)
88
+ return 1 ;
89
+ if (k==1 )
90
+ return n;
91
+
92
+ // if k > n-k then k = n-k as // Since C(n, k) = C(n, n-k)
93
+ if ( k > n-k)
94
+ k = n-k;
95
+
96
+ // calculating C(n,k) = n!/ (n-k)! * k!
97
+ for (int i = 0 ; i < k ; i++)
98
+ {
99
+ res *= (n-i);
100
+
101
+ res /= (i+1 );
102
+ }
103
+
104
+ return res;
105
+
106
+ } // Time complexity = O(k) and aux space = O(1)
107
+
108
+
109
+ // void Special(string s)
110
+ // {
111
+ // int i=0;
112
+ // int j=1;
113
+ // cout << s.substr(i,j);
114
+ // j++;
115
+ // Special(s.substr)
116
+ // }
117
+
118
+
119
+
120
+
83
121
int main ()
84
122
{
85
123
86
124
SpecialSubMain (" ab" );
87
- // cout<<Uppercase("a",0,1);
125
+
126
+
127
+ cout<<num;
88
128
89
129
}
You can’t perform that action at this time.
0 commit comments