2015 technical questions for Xiaomi school recruitment, 2015 Mi
I. Q &
1. Are you familiar with the reply strings? If a string is the same as the string from the past and the back, it is the back-to-text string. For example, "Shanghai tap water comes from the sea" is a text string. Now, let's look at a number as a string and ask if it is a return number? This simple question is certainly not a problem for you who want to become a Xiaomi engineer. But let me remind you that the higher the score, the lower the time complexity and space complexity.
C ++:
Bool isPalindromeNumber (long num)
Java:
Boolean isPalindromeNumber (long num)
Example: 12321-> true
3-> true
133434-> false
2. The problem of product of two polynomials is often encountered in middle school. It is such a problem:
Pa = an * x ^ n + an-1 * x ^ (n-1) +... + A1 * x + a0
Pa = bm * x ^ m + bn-1 * x ^ m-1) +... + B1 * x + b0
Where, an, an-1 ,..., A0, bm, bm-1 ,... , B0 is an integer in the range of [-10000,100 00]. 0 <= n, m <= 1000.
The pa * pb result is also a polynomial. Please program it to solve this problem. You need to design a program to represent a polynomial and write a program to multiply two polynomials.
C ++:
String multiplyPolynormial (const string & pA, const string & pB)
Java:
String multiplyPolynormial (String pA, String pB)
The format of pA and pB is "(-), (), ()", indicating a polynomial: -3 * x ^ 5 + 87 * x ^ 4 + 93 * x ^ 3 + 3
The input is legal. Except for numbers, Parentheses, and commas, there are no other characters, and the power is arranged from high to low. The output must also be in such a standard format.
package com.mi.recruitment;import java.util.HashMap;import java.util.Iterator;import java.util.Map;public class MultiplyPolynormial { public static void main(String[] args) { // TODO Auto-generated method stub System.out.println(multiplyPolynormial("(-3,1),(1,4),(4,0)", "(4,0),(3,1),(5,2)")); } public static String multiplyPolynormial(String pA,String pB){ String[] paArray = pA.split("\\),\\("); String[] pbArray = pB.split("\\),\\("); HashMap<Integer, Integer> paMap = new HashMap<Integer, Integer>(); HashMap<Integer, Integer> pbMap = new HashMap<Integer, Integer>(); HashMap<Integer, Integer> pcMap = new HashMap<Integer, Integer>(); String result = ""; for(int i=0; i<paArray.length; i++){ String pa = paArray[i].replaceAll("\\(|\\)", ""); paMap.put(Integer.parseInt(pa.split(",")[1]), Integer.parseInt(pa.split(",")[0])); } for(int i=0; i<pbArray.length; i++){ String pb = pbArray[i].replaceAll("\\(|\\)", ""); pbMap.put(Integer.parseInt(pb.split(",")[1]), Integer.parseInt(pb.split(",")[0])); } Iterator paIterator = paMap.entrySet().iterator(); while(paIterator.hasNext()){ Map.Entry<Integer, Integer> paEntry = (Map.Entry<Integer, Integer>)paIterator.next(); Iterator pbIterator = pbMap.entrySet().iterator(); while(pbIterator.hasNext()){ Map.Entry<Integer, Integer> pbEntry = (Map.Entry<Integer, Integer>)pbIterator.next(); int key = paEntry.getKey()+pbEntry.getKey(); if(pcMap.containsKey(key)){ pcMap.put(key, paEntry.getValue()*pbEntry.getValue()+pcMap.get(key)); } else{ pcMap.put(key, paEntry.getValue()*pbEntry.getValue()); } } } Iterator pcIterator = pcMap.entrySet().iterator(); while(pcIterator.hasNext()){ Map.Entry<Integer, Integer> pcEntry= ( Map.Entry<Integer, Integer>)pcIterator.next(); result = "(" + pcEntry.getValue() + "," + pcEntry.getKey() + "),"+result; } return result.substring(0, result.length()-1); }}
3. each employee in Xiaomi company will have an exclusive work mailbox, mailbox prefix is employee name pinyin full spell, for example, Zhangqiang mailbox is zhangqiang@xiaomi.com, but at the same time there are many people with the same name in the company, to prevent people from sending wrong emails to each other, the engineers thought of a rule to solve this problem, that is, among these same-person employees, the earliest mailbox prefix is the name of the pinyin spelling, add "_ a" after the pinyin full spelling of the name prefix of the mailbox for the second employee, add "_ B" after the pinyin full spelling of the name for the third employee, and so on, according to this rule, if the company has three employees named Zhangqiang at the same time, their mailboxes are
Zhangqiang@xiaomi.com, zhangqiang_a@xiaomi.com, zhangqiang_ B @xiaomi.com... the mailbox prefix is one of the important identifiers of employees in the company. The problem arises: Xiaomi wants to hold a full field training activity, requiring all employees to join the team and, some employees require him to be at the front or back of someone. As the organizer, after receiving such a requirement, how can you provide a queue that satisfies everyone?
Java:
Class RequestItem
{
Public String member;
Public boolean standFront; // true indicates to be placed before this person; false indicates to be placed behind this person
}
Class Request