Adults ONLY ! - Sajha Mobile
SAJHA MOBILE
Adults ONLY !
Posts 15 · Viewed 10346 · Go to Last Post
helpjava11
· Snapshot 0
Like · Likedby · 0
Now I got all of yours attention, solve this problem.

A book has N pages, numbered the usual way, from 1 to N. The total number of digits in the page numbers is 1,095. How many pages does the book have?
instagram
· Snapshot 140
Like · Liked by · 0
Jhan bihana bihana ke dekhna paaiyela bhanera kholeko ta. Daka le jhukkai halyo ni
sajhamitra
· Snapshot 153
Like · Liked by · 0
N(N+1)/2=1095.. Solve for N. that's the answer
Slackdemic
· Snapshot 204
Like · Liked by · 0
From 1 to 9 ====> 9 digits
10 to 99 =====> 180 digits
.                           + ----------
Total of 1 digit and 2 digit no.s  = 189 digits
Now rest of the pages are the three numbered pages:
N - 189 = 1095 - 189 = 906
906/3 = 302

So the total pages: 9 + 90 + 302 = 401
Last edited: 11-Dec-14 11:34 AM
sara_solta11
· Snapshot 309
Like · Liked by · 0
1 to N = 1 to 129
helpjava11
· Snapshot 523
Like · Liked by · 0
Slackdemic got it right. Answer is 401.

Todays score:
Slackdemic +1
Sajhamitra -1
sara_solta11 -1

virusno1
· Snapshot 553
Like · Liked by · 0
Here is my tricky question.
You have range of contiguous numbers in array from 1 to 1 million. Among of them one of the numbers is missing. Find out that missing number. You can use any data structure or use a simple math.
aaitey
· Snapshot 659
Like · Liked by · 0
अहिलेको जमानामा यसो हल्का गुगल गर्नु पर्छ क्या, गुला खेलाउदै दिमाग चलाउन खोजेर मात्र हुदैन।

http://codepad.org/Hrj8BKZ7

int getMissingNo (int a[], int n)
{
    int i, total;
    total  = (n+1)*(n+2)/2;  
    for ( i = 0; i< n; i++)
       total -= a[i];
    return total;
}
 
/*program to test above function */
int main()
{
    int a[] = {1,2,4,5,6};
    int miss = getMissingNo(a,5);
    printf("%d", miss);
    /*getchar();*/
}
Last edited: 11-Dec-14 03:05 PM
sajhamitra
· Snapshot 711
Like · Liked by · 0
Do it with a datastructure.
helpjava11
· Snapshot 1337
Like · Liked by · 0
if the numbers are in sequence, this function works fine. if its not in sequence its different story.

main method(){
int[] arrayofMillionNumbers = new int[100000];
for(int i = 1 ; i< arrayofMillionNumbers+1 ; i++){
arrayofMillionNumbers.add(i);
}
findMissing(arrayofMillionNumbers);
}
private int findMissing(int[] num) {
int missingNumber = 0;
for (int i = 0; i < (num.length - 1); i++) {
if ((num[i + 1] - num[i]) > 1) {
missingNumber = num[i] + 1;
break;
}
}
return missingNumber;
}
neurologist
· Snapshot 1348
Like · Liked by · 0
if the numbers are in sequence, this function works fine. if its not in sequence its different story.


m = missing number
x = 1;
for i = 1 to million
{
if x is not equal to i
{
m = x = missing number;
stop iteration;}
x = x + 1;
}
output m;

sajhamitra
· Snapshot 1369
Like · Liked by · 0
those numbers are continuous but distributed randomly. like 1,3,2,5,4.....etc
your solution works only if numbers are continuous but there should be some efficient way to solve if sequential numbers are randomly distributed.
Last edited: 12-Dec-14 10:44 AM
KaliKoPoi
· Snapshot 1378
Like · Liked by · 0
Mr. D
· Snapshot 1412
Like · Liked by · 0
Add all the numbers in the array.
Then find n! ( that is 1,000,000!)
Subtract them, that would be number that is missing.

This is would be complete in O(n) which is better than sorting the number and then using one of above algorithm to find the missing one.
virusno1
· Snapshot 1460
Like · Liked by · 0
Yes that's true but there is another solution too. Hint: You can use an array.
Please log in to reply to this post

You can also log in using your Facebook
View in Desktop
What people are reading
You might like these other discussions...
· Posts 73 · Viewed 17100 · Likes 16
· Posts 1 · Viewed 73
· Posts 9 · Viewed 977
· Posts 1 · Viewed 99
· Posts 1 · Viewed 89
· Posts 1 · Viewed 138
· Posts 1 · Viewed 95
· Posts 1 · Viewed 239
· Posts 13 · Viewed 2355
· Posts 1 · Viewed 151



Your Banner Here
Travel Partners
Travel House Nepal