38. April 1, 2014 ad search interview questions in 360

Source: Internet
Author: User

360 of the Headquarters was located near Wangjing 798 in Beijing. A friend went to the interview this week and gave a general talk about the process.


360 there is a lobby on the first floor of the headquarters, and there are a lot of MM at the front desk, indicating the intention. It is directed to the interview area (there are quite a lot of people, there should be very few people, or there should be new projects ).


Side:

Technically, he is a younger brother.

1) Introduce Yourself

2) I spoke about several important projects and asked about the projects. These are all topics of interest to the interviewer.

3) a programming question is given: design a trie tree to create a trie tree and search functions. The data is a batch of English words, all of which are lowercase letters.

Analysis:

This topic mainly involves three aspects: design the data structure of the trie tree, implement the trie tree creation function, and search for English words to see if they exist.


The implementation is as follows:

#include<iostream>#include<string.h>using namespace std;#define MAXNODE 26struct TrieNode{        int counts;        TrieNode* next[MAXNODE];//next character        TrieNode():counts(1){                int i = 0;                while(i < MAXNODE)                {                        next[i++] = NULL;                }        }};void createTrie(TrieNode* &root, char* str){        if(strlen(str) <= 0) return;        if(root == NULL)                root = new TrieNode();        int i = 0;        TrieNode* p = root;        while(i < strlen(str))        {                int k = str[i++] - 'a';                if(p->next[k])                {                        p->next[k]->counts ++;                }                else                        p->next[k] = new TrieNode();                p = p->next[k];        }}int SearchTrie(TrieNode* root, char* str){        TrieNode* p = root;        if(p == NULL) return -1;        int i = 0;        while(i < strlen(str))        {                int k = str[i++] - 'a';                if(p->next[k] == NULL)                        return 0;                else                        p = p->next[k];                if(i == strlen(str))                        return p->counts;        }}int main(){        char a[][4] = {"abc", "bcd", "ade", "acd", "bgf"};        int i = 0;        int j = 0;        TrieNode* root = NULL;        while(i < 5)        {                createTrie(root, a[i++]);        }        char* b = "bcd";        int in = SearchTrie(root, b);        if( in <= 0)                cout << "Trie can't find \"" << b << "\"" << endl;        else                cout << "Trie have find \"" << b << "\"" << endl;        return 0;}

Output result:

Trie have find "bcd"


Summary:

This algorithm can be used for string prefix queries, such as searching TIPS.




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.