sahaj
BAN USER
when array is not sorted, create an array (which will act like a hash map, index as key). If you get number for which the array[number] is already filled, you found a duplicate. Now, you can stop right there and using summation function for 1toN number, you can find missing number.
sum_of_n = (N (N+1))/2
i.e. missing_number = sum_of_n - (sum_of_array_elements - duplicate_number_found)
If array is sorted, traverse the array, if A[i] != i+1 then i is a duplicate number and again use above formula for missing number.
int ptr1incr = 1;
int ptr2incr = 2; //this is for 2x
// You can substitute it with 3, 4, 5 etc for 3x, 4x, 5x respectively
int count = 0;
int ptr1pos = 0;
int ptr2pos = 0;
int N = 3; // Total number of nodes
do {
count++;
ptr1pos = (ptr1pos + ptr1incr) % N;
ptr2pos = (ptr2pos + ptr2incr) % N
} while (ptr1pos != ptr2pos);
float total_cycles = (float) count/N;
RepDimaOxygen15, Computer Scientist at Headrun Technologies Pvt Ltd
Hi! all my sweets friends My name is Dimo Oxygen! Now I study in Victoria University of Wellington New Zealand ...
RepIsotherm is providing quality ceiling insulation and roofing insulation services to homes. We are one of the leading manufacturer company ...
RepAmber Van is registered and fully insured cheap removal company in Bristol.Our featured services includes domestic moves,commercial moves ...
Repannasteven1246, Analyst at Accenture
Creative, highly visual fashion professional who can brilliantly mix and match the technical expertise and intuition like fabric and color ...
RepIsotherm provides the best roof insulation products in Cape Town, South Africa. We offer insulation products for roofs, water pipes ...
Repmelonydmaxwell, maintenence engineer at AMD
Hi, I am working as a health information technician and my work is to collect and maintain a patient's ...
Repallisonepollard, Applications Developer at Accenture
I am Allison from Germantown. I work as a Staff manager at The LawnGuru company. But my interest in blogging ...
Repriverajenny935, i love my shop piano at xyz
Hello Everyone,My Name is Jenny Rivera .I have been a piano instructor for more than 25 years! I earned ...
Repjudydschultz1234, Android test engineer at Eterno Infotech Pvt Ltd
Spent a weekend researching weebles in Nigeria. My current pet project is developing strategies for how to break someone's ...
Repwilliamchansen95, Computer Scientist at 247quickbookshelp
I am working as a manager in Lionel Kiddie City company. I really enjoy my job. I like to play ...
Reppaulajheineman, Consultant at Bank of America
Hello, I am from Las Vegas, NV.Completed a Diploma course in Advanced Technological Developments and Staff Management. I have ...
RepStonefire Arms manufacture and bring Firearms parts & accessories to the market at reasonable prices. We offer a wide variety of ...
RepVirginialdelmonte, Animator at lostlovebackvashikaran
Have you lost your husband love? And you want to control your husband mind with vashikaran mantra. Guru ji is ...
Rephoychrista, Blockchain Developer at ASU
Worked with Clients to guide them through the event details about copier leasing companies and served as their personal coordinator ...
RepSince 1991, Lakeview Blinds Awnings & Shutters offers stunning interior and exterior blinds, shutters, awnings and security doors & windows to the ...
RepHandyman Homes is the one-stop destination for all your home improvement and handyman needs.We take care of residential & commercial ...
Repmaccydonal4747, Data Engineer at A9
Hi my sweet companions! My name is Maccy Donal, I conceived in Canada Toronto 1994 and I am unceasingly appreciative ...
Repracheljennir, Personnel consultant at Infinite Wealth
Rachel, I am a Personnel consultant who acts as mediator between employers and job seekers. The main task of I ...
With binary elimination it will take log(n) time.
- sahaj October 11, 2012