Some interview questions and thoughts

Source: Internet
Author: User
1. Microsoft interview questions: in the sorting array, find the number of occurrences of a given number. For example, in [1, 2, 2, 2, 3], 2 appears three times. Solution: Binary Search comments: Binary Search and sorting are in many numerical classes. Algorithm Is widely used. It can be said that these two algorithms are not skilled and will be tragic. The preceding question can be extended to: Find the number of numbers that appear in unordered numbers. The expanded solution can be sorted first, and the subsequent solution is the same. Sort is of course to use Quick sort. This solution is a satisfactory answer. 2. Sina interview questions: Delete unnecessary spaces in the string For a given string, remove spaces at the beginning and end, and combine multiple consecutive spaces in the middle into one.
For example, "I like http://hi.baidu.com/mianshiti" will become "I like http://hi.baidu.com/mianshiti ". Solution: not to mention, find one by one and give your own Code Implementation:
 Void Trimstr ( Char * SRC, Char * DST)
{
Int I, J;

For (I = 0 , J = 0 ; 1 ;)
{
For (; SRC [I] = ' ' ; I ++ );
If (SRC [I] = ' \ 0 ' )
{
DST [J] = ' \ 0 ' ;
Break ;
}

If (J = 0 )
{
DST [ 0 ] = SRC [I];
J ++;
}
Else
{
DST [J] =' ' ;
DST [J + 1 ] = SRC [I];
J + = 2 ;
}
}
}

 

Google interview questions: 1024! How many zeros are there at the end? Solution:
The number of 0 at the end is determined by the number of factors 2 and 5 in the multiplication. Obviously, the number of factor 2 in multiplication is greater than 5, so we only need to count the number of Factor 5.
Number of multiples of 5: 1024/5 = 204
The number is a multiple of 25: 1024/25 = 40
Number of multiples of 125: 1024/125 = 8
Which is a multiple of 625: 1024/625 = 1
So 1024! A total of 204 + 40 + 8 + 1 = 253 factors 5.
That is, 1024! There are 253 0 at the end. comment: although this question does not seem to be difficult, it is actually the knowledge in number theory, that is, the prime number we have learned in elementary school. The 1024 factorial can be divided into several prime numbers for multiplication. A pair of 2 and 5 of these prime numbers produces a 10 value, which adds a 0 value to the end, the combination of other prime numbers cannot produce 10. In addition, in the calculation process, for example, the reason why the multiples of 125 do not multiply by 3 in the final result is that "the first two 5" have already been computed before, this problem also needs to be carefully considered ~~

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.