Skip to content

Navigation Menu

Sign in
Appearance settings

Search code, repositories, users, issues, pull requests...

Provide feedback

We read every piece of feedback, and take your input very seriously.

Saved searches

Use saved searches to filter your results more quickly

Sign up
Appearance settings

Commit ed198ed

Browse files
implementing a new logic
1 parent 18c3d1a commit ed198ed

File tree

2 files changed

+46
-6
lines changed

2 files changed

+46
-6
lines changed

‎Dynamic Programming/LongestRepeatedSubstring.cpp

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -18,14 +18,14 @@ string LongestRepeatedSubstr(string s)
1818
sub = s.substr(i,j);
1919

2020
//if substring found again, simply increase the count;
21-
if(m.find(sub)!=m.end())
21+
if(m.find(sub)==m.end())
2222
{
23-
m[sub]++;
23+
m[sub] = 1;
2424
}
2525

2626

2727
//otherwise,if not found insert it in map with count as 1
28-
else m[sub] = 1;
28+
else m[sub]++;
2929
}
3030

3131
}
@@ -50,7 +50,7 @@ string LongestRepeatedSubstr(string s)
5050

5151
int main()
5252
{
53-
string str = "geeksforgeeks";
53+
string str = "abcpqrabpqpq";
5454

5555
cout<<LongestRepeatedSubstr(str);
5656
return 0;

‎Dynamic Programming/SpecialSubsequence.cpp

Lines changed: 42 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,5 @@
11
#include<iostream>
22
#include<vector>
3-
#include<cctype>
43
#include<algorithm>
54
#include <string>
65

@@ -80,10 +79,51 @@ void SpecialSubMain(string s)
8079

8180
}
8281

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+
83121
int main()
84122
{
85123

86124
SpecialSubMain("ab");
87-
// cout<<Uppercase("a",0,1);
125+
126+
127+
cout<<num;
88128

89129
}

0 commit comments

Comments
(0)

AltStyle によって変換されたページ (->オリジナル) /