DDL (Data Definition Language) DDL or Data Definition Language actually consists of the SQL commands that can be used to define the database schema. It simply deals with descriptions of the database schema and is used to create and modify the structure of database objects in the database. DDL is a set of SQL commands used to create, modify, and delete database structures but not data. These commands are normally not used by a general user, who should be accessing the database via an application. List of DDL commands: CREATE : This command is used to create the database or its objects (like table, index, function, views, store procedure, and triggers). DROP : This command is used to delete objects from the database. ALTER : This is used to alter the structure of the database. TRUNCATE : This is used to remove all records from a table, including all spaces allocated for the records are removed. COMMENT : This is used to add comments to the data dictionary. RENAME :...
#include
ReplyDeleteusing namespace std;
int main()
{
string s;
cin>>s;
int n=s.size();
int ans=0;
vector last(256,-1);
int i=0;
for(int j=0;j<n;j++)
{
i=max(i,last[s[j]]+1);
ans=max(ans,j-i+1);
last[s[j]]=j;
}
cout<<ans<<endl;
return 0;
}
This the function code of longest substring which return size.
Deletebool isPalindrome(string s) {
ReplyDeleteint n = s.length();
for(int i = 0; i < n/2; i++) {
if(s[i] != s[n-i-1]) {
return false;
}
}
return true;
}
Count of non-empty substrings is n*(n+1)/2
ReplyDeleteIf we include empty string also as substring, the count becomes n*(n+1)/2 + 1
How does above formula work?
Number of substrings of length one is n (We can choose any of the n characters)
Number of substrings of length two is n-1 (We can choose any of the n-1 pairs formed by adjacent)
Number of substrings of length three is n-2
(We can choose any of the n-2 triplets formed by adjacent)
In general, number of substrings of length k is n-k+1 where 1 <= k <= n
Total number of substrings of all lengths from 1 to n =
n + (n-1) + (n-2) + (n-3) + … 2 + 1
= n * (n + 1)/2
maximum Sub array
ReplyDelete#include
using namespace std;
int main()
{
int n,csum=0;
cin>>n;
int ar[n];
int maxSum=INT_MIN;
for(int i=0;i>ar[i];
}
int sum=0;
for (int i = 0; i < n; i++)
{
sum +=ar[i];
if(sum<0)
sum=0;
maxSum=max(maxSum,sum);
}
cout<<maxSum;
return 0;
}