Algorithm interview: a selection of typical algorithms for Microsoft and other companies. interview question 100-35

Source: Internet
Author: User

AlgorithmInterview: typical algorithms for Microsoft and other companies are selected for interview: Question 26-35

 

26. Rotate string left

Question:
Define the left rotation operation of the string: Move several characters before the string to the end of the string.

For example, the string abcdef is rotated two places to the left to obtain the string cdefab. Please implement the left rotation function of the string.
Requires that the complexity of the string operation with a length of N is O (n), and the auxiliary memory is O (1 ).

27. Step jumping
Question: a step has a total of N levels. If you can skip one level at a time, you can also skip two levels.
Calculate the total number of hops in total and analyze the time complexity of the algorithm.

This topic has been frequently used recently, including companies that place greater importance on algorithms, such as microstrategy.
I have selected this question as an interview or pen question.

28. The binary value of an integer indicates the number of values in 1.
Question: enter an integer to calculate the number of 1 in the Binary Expression of this integer.
For example, input 10. Because the binary value is 1010 and there are two 1 s, Output 2.

Analysis:
This is a basic quiz on bit operations.
Many companies, including Microsoft, have used this question.

29. Stack push and pop Sequences
Question: enter two integer sequences. One sequence represents the push order of the stack,
Determine whether another sequence may be in the pop sequence.
For the sake of simplicity, we assume that any two integers in the push sequence are not equal.

For example, if the input push sequence is 1, 2, 3, 4, 5, 3, 2, and 1, it may be a pop series.
Because there can be the following push and pop sequences:
Push 1, Push 2, Push 3, Push 4, Pop, Push 5, pop,
The pop sequence is 4, 5, 3, 2, and 1.
However, sequences 4, 3, 5, 1, and 2 cannot be pop sequences of push sequences 1, 2, 3, 4, and 5.

30. number of occurrences of 1 in a positive number from 1 to n
Question: enter an integer n to calculate the number of times 1 appears in the decimal representation of the N integers from 1 to n.

For example, input 12, integers from 1 to 12 contain numbers 1, 10, 11, and 12, and 1 appear 5 times in total.
Analysis: This is a widely used Google interview question.

 

 

 

31. Huawei interview questions:
Search for the shortest path (5 minutes required) in a graph similar to the structure of a honeycomb)

32.
There are two sequences, A and B, all of which are n. The values of the sequence elements are random integers and unordered;
Requirement: by exchanging elements in A and B, the deviation between [Sum of Element A] and [Sum of Element B] is minimized.
For example:
VaR A = [100,99, 98,1, 2, 3];
VaR B = [1, 2, 3, 4, 5, 40];

33.
Implement a very advanced character matching algorithm:
For a long string, you must find a string that meets the requirements, for example, the target string: 123
1*3*2, 12*3.
In fact, it is similar to some harmonious systems .....

34.
Implement a queue.
The application scenarios of queues are as follows:
A producer thread columns the int type, and a consumer thread columns the int type.

35.
Returns the largest two-dimensional matrix (element and maximum) in a matrix. For example:
1 2 0 3 4
2 3 4 5 1
1 1 5 3 0
The largest in:
4 5
5 3
Requirements: (1) write algorithms; (2) analyze time complexity; (3) use C to write the keyCode

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.