Current streak:
0 days
Longest streak:
10 days
Less
More
College monthly badge
1 Time topper
Shri Shankaracharya Institute Of Professional Management And Technology, Raipur
int longestSuccessiveElements(vector<int>&a) {
sort(a.begin(),a.end());
int count=0,maxi = 0;
for(int i=1;i<a.size();i++){
while(a[i]-a[i-1]==1||a[i]-a[i-1]==0){
(a[i]-a[i-1]!=0)?count++:1;
i++;
}
maxi = max(maxi,count);
count=0;
}
return maxi+1;
}
#include <bits/stdc++.h>
bool splitString(string &str){
int n = str.size();
int count=0;
// char arr[]={'A','E','I','O','U','a','e','i','o','u'};
for(int i=0;i<n/2;i++){
if(str[i]=='A'||str[i]=='E'||str[i]=='I'||str[i]=='O'||str[i]=='U'||str[i]=='a'||str[i]=='e'||str[i]=='i'||str[i]=='o'||str[i]=='u'){
count++;
}
int j=n-i-1;
if(str[j]=='A'||str[j]=='E'||str[j]=='I'||str[j]=='O'||str[j]=='U'||str[j]=='a'||str[j]=='e'||str[j]=='i'||str[j]=='o'||str[j]=='u'){
count--;
}
}
return count==0?true:false;
}
#include <bits/stdc++.h>
bool splitString(string &str){
int n = str.size();
int count=0;
// char arr[]={'A','E','I','O','U','a','e','i','o','u'};
for(int i=0;i<n/2;i++){
if(str[i]=='A'||str[i]=='E'||str[i]=='I'||str[i]=='O'||str[i]=='U'||str[i]=='a'||str[i]=='e'||str[i]=='i'||str[i]=='o'||str[i]=='u'){
count++;
}
int j=n-i-1;
if(str[j]=='A'||str[j]=='E'||str[j]=='I'||str[j]=='O'||str[j]=='U'||str[j]=='a'||str[j]=='e'||str[j]=='i'||str[j]=='o'||str[j]=='u'){
count--;
}
}
return count==0?true:false;
}
/****************************************************************
Following is the class structure of the Node class:
class Node
{
public:
int data;
Node *next;
Node()
{
this->data = 0;
next = NULL;
}
Node(int data)
{
this->data = data;
this->next = NULL;
}
Node(int data, Node* next)
{
this->data = data;
this->next = next;
}
};
*****************************************************************/
Node *firstNode(Node *head)
{
Node *slow =head;
Node * fast = head;
while(fast&&fast->next){
slow=slow->next;
fast=fast->next->next;
if(slow==fast){
goto found;
}
}
return NULL;
found:
slow=head;
if(slow==fast){
return slow;
}
while(slow->next!=fast->next){
slow=slow->next;
fast=fast->next;
}
return slow->next;
}
/****************************************************************
Following is the class structure of the Node class:
class Node
{
public:
int data;
Node *next;
Node()
{
this->data = 0;
next = NULL;
}
Node(int data)
{
this->data = data;
this->next = NULL;
}
Node(int data, Node* next)
{
this->data = data;
this->next = next;
}
};
*****************************************************************/
Node *firstNode(Node *head)
{
Node *slow =head;
Node * fast = head;
while(fast&&fast->next){
slow=slow->next;
fast=fast->next->next;
if(slow==fast){
goto found;
}
}
return NULL;
found:
slow=head;
if(slow==fast){
return slow;
}
while(slow->next!=fast->next){
slow=slow->next;
fast=fast->next;
}
return slow->next;
}
int minimumDifference(int n, vector<int> arr)
{
int sum=0;
for(int i=0;i<n;i++){
sum+=arr[i];
}
int s=0,min=INT_MAX,diff;
for(int i=0;i<n;i++){
s+=arr[i];
sum-=arr[i];
diff=abs(sum-s);
if(diff<min){
min=diff;
}
}
return min;
}
int minimumDifference(int n, vector<int> arr)
{
int sum=0;
for(int i=0;i<n;i++){
sum+=arr[i];
}
int s=0,min=INT_MAX,diff;
for(int i=0;i<n;i++){
s+=arr[i];
sum-=arr[i];
diff=abs(sum-s);
if(diff<min){
min=diff;
}
}
return min;
}
void insert(Node * ( & head), int n, int pos, int val) {
Node* temp = head;
Node * node = new Node(val);
if(pos==0){
node->next=head;
head=node;
return;
}
for(int i=1;i<pos;i++){
temp = temp->next;
}
node->next=temp->next;
temp->next=node;
return;
}
void insert(Node * ( & head), int n, int pos, int val) {
Node* temp = head;
Node * node = new Node(val);
if(pos==0){
node->next=head;
head=node;
return;
}
for(int i=1;i<pos;i++){
temp = temp->next;
}
node->next=temp->next;
temp->next=node;
return;
}