Joke Collection Website - Blessing messages - Ali Interview Algorithm Problem Set 1
Ali Interview Algorithm Problem Set 1
For example, the five numbers 0, 1, 2, 3 and 4 form a circle. If the third digit is deleted from the number 0 at a time, the first four digits deleted are 2, 0, 4 and 1 in turn, so the last remaining digit is 3.
Example 1:
Input: n = 5, m = 3.
Output: 3
Example 2:
Input: n = 10, m = 17.
Output: 2
Please implement a function, input an integer and output the binary number 1. For example, representing 9 as binary is 100 1, and two bits are 1. Therefore, if you enter 9, the function outputs 2.
Example 1:
Input: 000000000000000000000000000000101.
Output: 3
Description: In the input binary string 00000000000000000000000000 1 kloc-0/,* * has three digits "1".
Numbers are serialized into a character sequence in the format of 0 1 23456789112 131415 ... In this sequence, the 5th digit (counting from subscript 0) is 5.
Please write a function to find the number corresponding to any nth bit.
Example 1:
Input: n = 3
Output: 3
Example 2:
Input: n = 1 1
Output: 0
Please note that this must be a long type.
Input a non-negative integer array, splice all the numbers in the array into a number, and print out the smallest number among all the spliced numbers.
Example 1:
Input:
Output: "102"
Example 2:
Input:
Output: "3033459"
The teacher wants to distribute candy to the children. There are n children standing in a straight line, and the teacher will grade them in advance according to their performance.
You need to help teachers distribute candy to these children according to the following requirements:
Each child is allocated at least 1 candy.
Among the children in the neighborhood, the children with high scores must get more candy.
So how many sweets does the teacher need to prepare at least?
Example 1:
Input:
Output: 5
Note: You can distribute 2, 1 and 2 sweets to these three children respectively.
Example 2:
Input:
Output: 4
Note: You can distribute 1, 2, 1 to these three children respectively.
The third child only got 1 candy, which has met the above two conditions.
There are n gas stations on a ring road, among which the I-th gas station has gasoline gas.
Cost =
Output: 3
The greedy idea is that as long as the sum is greater than 0, it can be bypassed.
The greedy idea of the starting position is that if the sum is less than 0 from the beginning, then it must not start from the previous position, but from the current next position, and sum = 0 is cleared.
Given an array of non-negative integers, you are initially in the first position of the array.
Each element in the array represents the maximum length that can jump at that position.
Your goal is to reach the last position of the array with the least number of hops.
Example:
Input:
Output: 2
Note: The minimum number of jumps to the last position is 2.
Jump from subscript 0 to subscript 1, jump to 1, and then jump 3 steps to the last position of the array.
Given an array of non-negative integers, you are initially in the first position of the array.
Each element in the array represents the maximum length that can jump at that position.
Judge whether you can reach the final position.
Example 1:
Input:
Output: true
Description: We can jump to 1 first, from position 0 to position 1, and then from position 1 to the last position in 3 steps.
Messages containing letters A-Z are encoded in the following ways:
A'-> 1
b '-& gt; 2
...
z '-& gt; 26
Given a non-empty string containing only numbers, please calculate the total number of decoding methods.
Example 1:
Input: "12"
Output: 2
Description: It can be decoded as "AB" (12) or "L" (12).
We must pay attention to the situation that the first number is 0. s.charAt(0) == '0 '。 If the first number is 0, we must return 0 directly.
Given an array, its i-th element is the price of the given stock on the i-th day.
If you are only allowed to complete a transaction at most (that is, buy and sell a stock once), design an algorithm to calculate the maximum profit you can get.
Note: You can't sell stocks before you buy them.
Example 1:
Input:
Output: 5
Explanation: Buy on the second day (share price = 1) and sell on the fifth day (share price = 6). Maximum profit = 6- 1 = 5.
Note that the profit cannot be 7- 1 = 6, because the selling price needs to be greater than the buying price; At the same time, you can't sell stocks before buying them.
Given three strings s 1, s2, s3 and s3, verify whether S3 is composed of s 1 and s2.
Example 1:
Input: s 1 = "aabcc ",S2 = "dbbca", S3 = "aadbbcbcac".
Output: true
Given a string S and a character rule P, please implement a regular expression matching and "*" that supports'.'.
. Matches any single character.
*' matches zero or more previous elements.
The so-called matching is to cover the whole string s, not a part of the string.
Description:
S can be empty and contain only lowercase letters from a to z.
P can be empty and contain only lowercase letters and characters from a to z. And *.
Example 1:
Input:
s = "aa "
p = "a "
Output: false
Explanation:' a' cannot match the whole string of' aa'.
Given an integer matrix, find the length of the longest incremental path.
For each cell, you can move up, down, left and right. You can't move diagonally, and you can't cross the line (that is, you can't wrap around).
Example 1:
Input: nums =
,
,
Output: (of course correct)
Given some envelopes marked with width and height, the width and height are displayed as integer pairs (w, h). When the width and height of another envelope are larger than this envelope, this envelope can be put into another envelope, just like a Russian doll.
Please calculate the maximum number of envelopes that can form a group of "Russian dolls" (that is, one envelope can be placed in another envelope).
Description:
Rotating envelopes is not allowed.
Example:
Input: envelope =,,]
Output: 3
Note: The maximum number of envelopes is 3, and the combination is: =>=>.
Standard dynamic programming
A frog wants to cross the river. Suppose the river is divided into x cells on average, and there may or may not be stones in each cell. Frogs can jump on rocks, but they can't jump into the water.
Given a list of stone positions (in ascending order of cell number), please decide whether the frog can successfully cross the river (that is, whether it can jump to the last stone in the last step). At the beginning, the frog has stood on the first stone by default, so it can be assumed that only one unit can be jumped in the first step (that is, only cell 1 can be jumped to cell 2).
If the frog jumps k units in the previous step, then its next jump distance can only be k- 1, k or k+ 1 unit. Please also note that frogs can only jump forward (towards the end).
Please note:
The number of stones is ≥ 2 and <1100;
The position serial number of each gem is a non-negative integer, and its
The position of the first stone is always 0.
Example 1:
Output: 3
The idea is to ignore the first one to get a result, and ignore the last one to get a result, as long as there is one result at a time.
//you can use rangeCopy to solve in the function.
Given a triangle, find the minimum path sum from top to bottom. Each step can only be moved to the adjacent node of the next row.
Adjacent nodes here refer to two nodes whose subscripts are equal to or equal to the upper node subscript+1.
For example, given a triangle:
,
,
]
The minimum path sum from top to bottom is 1 1 (that is, 2+3+5+1=1).
Given an m×n grid containing non-negative integers, please find a path from the upper left corner to the lower right corner to minimize the sum of the numbers on the path.
Note: You can only move down or right one step at a time.
Example:
Input:
,
,
]
Output: 2
A robot is located in the upper left corner of an m x n grid (the starting point is marked as "start" in the figure below).
The robot can only move down or right one step at a time. The robot tries to reach the lower right corner of the grid (marked "Done" in the figure below).
How many different paths are there?
Suppose you are climbing stairs. It takes n steps to get to the roof.
You can climb 1 or 2 steps at a time. How many different ways can you climb to the top of the building?
Note: the given n is a positive integer.
Example 1:
Input: 2
Output: 2
- Previous article:Love greeting SMS
- Next article:How do I know if my new shares have won the lottery?
- Related articles
- Cherish friendship good morning wishes, friendship morning greetings
- When will the admission notice of Meishan Pharmaceutical Vocational College come out-quick inquiry entrance
- How long does it take for mobile banking to check credit information?
- How to unsubscribe from Unicom CRBT?
- Happy birthday to my son.
- Materials needed for fresh graduates from other places to enter Shenzhen
- What is the failure of credit card activation?
- The mobile phone is not answering the phone, and there is no SMS reminder.
- Why can't I book adult tickets for Suzhou amusement park? I am actually a minor. But can I buy a student ticket to the scenic spot with the college entrance examination admission ticket?
- I was set up by my mother?