背景很少說了,入正題,先說下筆試吧,研發崗位總共三道編程題,總的來講不是特別難,但要求要紙上寫代碼,因此寫代碼前先三思下,能夠在試卷上寫僞代碼思路(答卷分開),後在答卷上寫題,切記:必定別忘記註釋。python
筆試題:
程序員
1、部分有序旋轉數組查找問題。web
有一遞增數組可向右移動,如:{1,2,3,4,5}向右移動後可爲:{3,4,5,1,2},如今相似的數組中想找一個固定值,若存在則返回對應下標,若不存在則返回-1。須要考慮算法效率。面試
題解:很容易的就想到二分查找,是否是?但問題來了:數組有多是由兩部分遞增的數組組成的,這樣子就不能用二分查找法了。等等,這兩部分有特別發現了沒?數組第一個元素和最後一個比較,若是第一個比最後一個大,那麼數組就是旋轉了,此時很容易就想到先將原數組分割成兩個遞增數組再分別二分查找。算法
public int indexInTurnedArray(int[] array, int index) {// find out where the target int is int tmp = -1; if(null == array || 0 == array.length) {//error input tmp = -1; } else{ int bound = findArrayBound(array);//get the boundary of the array, which means the bigest one in array if(index == array[bound]) {//the target int is the boundary tmp = bound + 1; } else { //the target int should in the left side of the boundary, or the right side //anyside should return the index of the array, else return -1 //so, if none exist in both sides, the result will be -1 //if the target is match to the first one of the array, the 0 should be the reslut tmp = 1 + binarySearch(array, 0, bound - 1, index) + binarySearch(array, bound + 1, array.length -1, index); } } return tmp; } /** * find the bigest element in the turned-array * @param array * @return */ public int findArrayBound(int[] array) { if(array[0] < array[array.length - 1]) {//the array is a sequnced array, small to big... return array.length - 1; } else { int tmp = 0; //begin is used for index the last one in the bigger side //end is the first one in the smaller side int begin = 0, end = array.length - 1; while(begin < end) {//when the begin = end ,the circle will exist, means find the boundary if(1 == end - begin) {//found the boundary tmp = end - 1; break; } tmp = (begin + end) / 2; if(array[tmp] >= array[begin]) {//the middle one is bigger than begin begin = tmp; } else if(array[tmp] <= array[end]) {//the middle one is small than end end = tmp; } } return tmp; } } public int binarySearch(int[] array, int begin, int end, int index) {//binary research function if(begin == end) { return index == array[begin] ? begin : -1; } else { int middle = (begin + end) / 2; if(index == array[middle]) { return middle; } else if(index < array[middle]){ return binarySearch(array, begin, middle - 1, index); } else { return binarySearch(array, middle + 1, end, index); } } }
2、字符串解釋數據庫
對輸入的字符串,如:a2b3c4解密,解密結果應該爲aabbbcccc。編程
題解:比較簡單的一題字符操做,考查ASCII碼運用及,字符串的相關知識。數組
string stringDecode(tring s) { char* c = const_cast<char*>(s.c_str());//將輸入字符串強制轉換成字符 String tmp; while (*c != '\0') { char a = 0; int j = -1; if ((*c>='A' && *c <= 'Z') || (*c >= 'a'&&*c<='z'))//斷定是不是字母 { a = *c; c++; } if (*c != '\0' && *c >= '0' && *c <= '9')//斷定是不是數字 { while (*c != '\0' && *c >= '0' && *c <= '9')//將全部數字轉換成int { if (-1 == j) { j = (int)*c-48; } else { j = j * 10 + ((int)*c-48); } c++; } } if (a != 0)//若第一個是字母,則輸出 { if (-1 == j) { tmp += a; } else { for (int i = 0; i < j; i++) { tmp += a;//迭加以前的字母個數 } } } } return tmp; }
3、多維數組操做安全
有一酒店某段時間內價格是由三元組肯定的,如:第一天至第30天的價格是300元,則三元組爲:[1,30,300]。後來出現的三元組的價格能夠覆蓋以前三元組的價格,如再出現[20, 50, 100]則其價格爲:[1,19, 300], [20, 50, 100]。網絡
題解:題目即爲輸入是二維數組,每行第一個元素是起始日期,第二個元素是截至日期,第三個元素爲此段時間內價格。我很容易的想到了上萬數亂序查找哪一個數不存在的問題,即:創建一個較目標大點的一維數組(此處大小爲366,一年不超過366天),若輸入的三元組中規定了日期的價格,則分別將對應下標的數組中的值改成價格,後來再有重複的話將以前的價格覆蓋便可。最後在遍歷數組,找出非0的部分,值相同的一段將起始下標、終止下標、價格做爲新的三元組輸出。
1 public void hotelPrice(int[][] array) { 2 int beginDay = 365, endDay = 0; //store the begin and end day of the input 3 int[] price = new int[366]; //the price must in a year 4 int tmp = 0; 5 for(int i = 0; i < array.length; i++) { //the 3-element-array number 6 if(beginDay > array[i][0]) { //price begin day 7 beginDay = array[i][0]; 8 } 9 if(endDay < array[i][1]) { //price end day 10 endDay = array[i][1]; 11 } 12 tmp = array[i][0]; 13 while(tmp <= array[i][1]) { 14 price[tmp++] = array[i][2]; //pice 15 } 16 } 17 int i = beginDay; 18 while(i <= endDay) {//print result 19 if(0 == price[i]) { 20 i++; 21 continue; 22 } else { 23 int begin = i; 24 int tmpV = price[i]; 25 while(i < 366 && price[++i] == tmpV) {//find the same price day 26 continue; 27 } 28 int end = i - 1; 29 System.out.println("[" + begin + " , " + end + " , " + tmpV + "]");//print 30 } 31 } 32 }
面試:
主要問了些關於簡歷和筆試中的細節問題。
1、因爲以前我在銳捷實習過4個月,問了些關於銳捷實習過程當中我作的一個用robotframework搭建的自動化測試平臺的東西,這部分聊的比較HIGH,和麪試官聊了半天算是科普了許多無線方面的知識吧,還說了一些我在項目中遇到的問題和相應的解決思路和過程。
2、socket和http的區別。
http是超文本傳輸協議,主要是用來在應用程序層面封裝web數據的一個協議,封裝完後再交由TCP封裝,IP封裝,最後由底層網絡送出報文交付;
socket能夠分爲IP層的socket和TPC層的socket,其主要功能是爲了方便程序員更好的調用協議棧完成相應工做,簡單的說就是對協議棧封裝提供一套API給開發者用。
故,一個是協議;另外一個只是一系列的接口API。
3、什麼是線程安全。
(從度娘搬運來的)線程安全就是多線程訪問時,採用了加鎖機制,當一個線程訪問該類的某個數據時,進行保護,其它線程不能進行訪問直到該線程讀取完。不會出現數據不一致或污染。線程不安全就是不提供數據訪問保護,有可能出現多個線程前後更改數據形成所獲得的數據是髒數據。
4、Spring主要做用
(從CSDN上搬運過來,http://blog.csdn.net/dyllove98/article/details/8586312)
5、數據庫外鍵
外鍵主要是用於兩個或多個表關聯時,關聯的關鍵字便是外鍵。
因爲當時問到銳捷項目後,問了許多python語言類的東西,本人實在太菜未系統學過,因此基本答的很亂,最後妥妥的跪了。歡迎你們來拍磚和補充。