Interview Question
Software Engineer / DevelopersCountry: United States
Interview Type: Written Test
We still can optimize this by one operation where,
calculate the sum first and keep subtracting the page numbers and the last remaining is the page we need to find.
We still can optimize this by one operation where,
calculate the sum first and keep subtracting the page numbers and the last remaining is the page we need to find.
I do not see the difference. Sum up and subtracted from expected sum versus expected sum subtracting all remaining page. Same~
This will work if the pages are single sided.
If the pages are double sided, then the number obtained by subtracting has to be divided by 2.
calculate Sum of all page num. now subtract from n(n+1)/2... answer is missing page num
- loveCoding March 06, 2012