nileshagarwal10
BAN USER
1) sort the numbers by radix sort O(32n)
2)then check last bit of each no....if 2 consecutive 0 or 1 comes then middle no is missing O(n)
complexity O(32n)+O(n)=O(n)
1) sort the array
2) then start with one pointer i=0 and another j=n(array length)
3) calculate sum if greater then k then j-- and if less then k than i++
4) repeat 3 step till you find the sum or i>j
Sorting can be performed with one more stack. The idea is to pull an item from the original stack and push it on the other stack. If pushing this item would violate the sort order of the new stack, we need to remove enough items from it so that it’s possible to push the new item. Since the items we removed are on the original stack, we’re back where we started. The algorithm is O(N^2) and appears below.
public static Stack<Integer> sort(Stack<Integer> s) {
Stack<Integer> r = new Stack<Integer>();
while(!s.isEmpty()) {
int tmp = s.pop();
while(!r.isEmpty() && r.peek() > tmp) {
s.push(r.pop());
}
r.push(tmp);
}
return r;
}
Repshivanojasy, Apple Phone Number available 24/7 for our Customers at A9
Dedicated worker with a following of regular customers and an understanding of sales and marketing.During my time away from ...
RepHondaRonda, Accountant at Achieve Internet
I am a communications specialist who develops and nurtures relationships between an organisation, members of the media and the public ...
RepKeithyMayes, Area Sales Manager at ASAPInfosystemsPvtLtd
Keithy , an administrative manager , Designs and access to technology to facilitate new infrastructure for students. and I have a hobby ...
RepI am Neeva with 6 years of experience,seeking a career of packers and movers in gurgaon that allows me ...
Repnovathomes, abc at 8x8
I am a friendly and outgoing person who enjoys greeting people with a smile. I have more than eight years ...
Repmylakleinm, Quality Assurance Engineer at Coupon Dunia
Articulate and accomplished admin executive experience at keeping an office running smoothly. A communicator and collaborator who is efficient in ...
RepAdaShipman, abc at 247quickbookshelp
During operation, determine all necessary adjustments to the printing press to maintain safety, quality and productivity standards and make such ...
RepHannahWilson, Android Engineer at A9
Hi, I’m Hannah from the USA and I am working as an account manager. I work for a hardware ...
Repkalerkant98, abc at ADP
I am DennisRue, seeking an entry level position where my strong work ethics and ability to learn quickly will contribute ...
Repruchikadolph, HR Executive at Accenture
I choose the talking books to match the book library clerk blind library patrons . I compare a list of borrowers ...
RepHey, my name is DooreMee and I completed all my study from California. And Nowadays I am working as a ...
RepDedicated and professional insurance manager with many years of experience. I love my work here. I have learned many things ...
Repmandybourne5463, Accountant at ABC TECH SUPPORT
MandyBourne, and I am a Computer typesetter and I love my work. Apart from this, today I am doing new ...
RepNaomiAdams, abc at 8x8
Passionate educator for nearly 5 years with a strong desire to help students recognize the connection between learning and experience ...
Repfanniepaisley, Computer Scientist at ABC TECH SUPPORT
Fannie Parsley, and I'm working as a Cartographer. And nowadays I am doing a new experiment on best tantrik ...
Repzk6354367, Financial Software Developer at Agilent Technologies
Hi , I am Zessie from the USA , working as Dien for the last three years. Previously I have served as ...
RepLisaNoto, Android Engineer at ADP
Annie has nearly 10 years of experience working on anadromous and estuarine fishery issues in California. She serves as a ...
Repfredlhenry, Android Engineer at Digital Merkating
Hi, I am Fred, 27 years old, I have done bachelor’s in IT.I have been working for a ...
RepHey, I am Ruth and I am working as an interviewer.I take too many Interviews For my Company and ...
RepAshleyDerri, Associate at Achieve Internet
I am Ashley, a highly qualified dynamic educator with experience educating and supporting students throughout the transition from high school ...
Repneshujaha, Member Technical Staff at BMO Harris Bank
I am Neshu, a Camera Operator with a creative eye for detail and dedication to quality work. I am always ...
RepRoseReynolds, Analyst at 8x8
Hi everyone I am Lilla from the UK.I am passionate about two things, gym and book lover.Last topic ...
Repmorganswitzer8475, Android test engineer at ABC TECH SUPPORT
Hey, I'm Morgan switzer and i am a sociologist. I also like to read some interesting books like get ...
RepRuthOrvis, AT&T Customer service email at 8x8
Hey I am Ruth Working as a branch manager in a bank.I have worked here for the last 4 ...
Repjeansboylan698, Associate at 247quickbookshelp
JeanBoylan, and I am a Financial examiner and I love my work. Apart from this, Nowadays I am doing new ...
RepAadavThomas, abc at A9
I am a well skilled and innovative Industrial Designer who focuses on taking products, noting product ideas and making them ...
Repjacksabjohne, Accountant at ABC TECH SUPPORT
Michael is a Biological Technician with 4 years of experience monitoring, characterizing, and quantifying riverine processes and habitat in the ...
Repthelmasaraht, Applications Developer at Accolite software
A child protection social worker is responsible for a variety of services designed to help families and children in a ...
Repaalvinbrowne, Android Engineer at ASAPInfosystemsPvtLtd
Working as an Agricultural laborer at Mars Music I maintain yields like natural products, vegetables, grains, and nuts, or take ...
Repleliakelsch6389, Associate at 247quickbookshelp
Hello, I am a News Anchor. And I have completed all my studies from Portland. And today I am a ...
Repjoycepwise, Blockchain Developer at Accenture
Hello, I’m Joyce. I’m a business developer living in Tampa, FL. I am a fan of music, travel ...
Repethelynfrose, Computer Scientist at 247quickbookshelp
Hello, I am Ethelyn and I live in Lake Worth, USA. I am working as a Dog Trainer and Dog ...
RepDavidTBevins, Apple Phone Number available 24/7 for our Customers at AMD
Hi am working as a writer and i wrote many books.Mostly i write books related to Magic and my ...
Repmarilyannrandall, Backend Developer at ABC TECH SUPPORT
As a Data input clerk, I deal with customers on a daily basis. Entering customer and account data from source ...
RepChloePerez, cashier at POS
Versatile cashier with exemplary cash register system skills and proven commitment to store cleanliness and safely. Learning new and knowledgeable ...
Repcorinnedonon, Backend Developer at A9
I am Corinne, a highly organised, professional and self-motivated Dietitian with a great passion for nutrition and people’s well-being ...
Repamayalopez800, Accountant at A9
I am Amaya ,working in the field of training and development coordinator for three years, focusing on teaching English as ...
Repamritatorr, Paramedic at Capital Medical Billing
By profession, I am a paramedic in Chicago. I want to know about Indian ayurvedic treatment. I like to explore ...
RepKellyLabbe, Animator at Future Advisor
My name is Kelly and I am currently a freshman Fitness trainer in Vibrant Man company .I have learned a ...
Repaaronyocoma, U.S. marshal at Pacific Stereo
Working as U.S. marshal at Pacific Stereo numerous years . I encountered heaps of things . With this I likewise like ...
Reppaytonmorrison48, Data Scientist at ADP
I am working as a date entry keyar . I have many years of experience . The data entry manager is primarily ...
RepMaryCParker, Dev Lead at ADP
My name is Mary and I am from usa.I am a representative sales advertising agent of (Specific Appraisals)company ...
Repbeverlybgill, Accountant at 247quickbookshelp
Hello, Beverly Gill and am health services manager. And I have completed all my studies in California and Nowadays am ...
RepNoraMiller, abc at A9
Confident and dedicated photographer with experience in both professional and freelance photography.. Prioritizes communication on the job to avoid errors ...
RepAakeshCruz, Accountant at Tinder
Exceptional knowledge of mathematical concepts, accounting and finance topics, tax code, and banking principles.Worked with clients and CFOs to ...
Repzippy28943, Data Scientist at AppNexus
Maxine , a grant writer specializing in researching and analysing grant opportunities, creating funding plans, and conducting proposals and budgets. Last ...
#include<stdio.h>
- nileshagarwal10 September 28, 2013#include<conio.h>
#include<malloc.h>
struct node
{
int val;
struct node* next;
};
struct node* create_node(int value)
{
struct node *ptr;
ptr=(struct node*)malloc(sizeof(struct node));
ptr->val=value ;
ptr->next=NULL;
}
void display(struct node* head)
{
while(head!=NULL)
{
printf("%d ",head->val);
head=head->next;
}
printf("\n");
}
struct node * merge(struct node *ptr1,struct node *ptr2)
{
struct node* result=NULL;
if(ptr1==NULL)
return ptr2;
else if(ptr2==NULL)
return ptr1;
if(ptr1->val < ptr2->val)
{
result=ptr1;
result->next=merge(ptr1->next,ptr2);
}
else
{
result=ptr2;
result->next=merge(ptr1,ptr2->next);
}
return result;
}
sort(struct node **head)
{
if(*head==NULL||(*head)->next==NULL)
return ;
struct node *ptr1=*head;
struct node* prv=ptr1;
struct node* ptr2;
ptr1=ptr1->next;
while(prv->val<ptr1->val)
{
prv=ptr1;
if(ptr1->next==NULL)
return;
ptr1=ptr1->next;
}
ptr2=ptr1;
prv->next=NULL;
*head=merge(*head,ptr2);
}
int main()
{
struct node *head;
head=create_node(1);
head->next=create_node(2);
head->next->next=create_node(3);
head->next->next->next=create_node(4);
head->next->next->next->next=create_node(5);
head->next->next->next->next->next=create_node(1);
head->next->next->next->next->next->next=create_node(2);
//display(head);
sort(&head);
display(head);
}