回复: 16
跳转到指定楼层
上一主题 下一主题
收起左侧

Flexport 上海面经

全局:

2022(7-9月) 码农类General 硕士 全职@华为Flexport - 内推 - 技术电面 视频面试  | Other | 应届毕业生

注册一亩三分地论坛,查看更多干货!

您需要 登录 才可以下载或查看附件。没有帐号?注册账号

x
目前进行Coding 1面
题目跟地理一样
地里的generate random sentence
this is a sentence it is a good one and it is also bad
5
. From 1point 3acres bbs
is not a sentence it. 1point 3acres

输入:一个句子
一个新组装句子长度
输出:组装的新句子
规则:按照随机选择一个单词作为句子头单词,然后在句子中寻找头单词后续节点,添加到新句子中

方案:将句子按照空格拆分,然后进行构建map,并将后续的单词作为value。
  1. /*
  2. * Click `Run` to execute the snippet below!
  3. this is a sentence it is a good one and it is also bad
  4. 5

  5. is not a sentence it
  6. */. 1point 3 acres

  7. import java.io.*;
  8. import java.util.*;

  9. public class ConstructNewWords {
  10.     public String getNewWords(String words, int n){
  11.         if(words==null){.--
  12.             return "";. check 1point3acres for more.
  13.         }
  14.         StringBuilder ans = new StringBuilder();
  15.         String[] wordsString = words.split(" ");
  16.         Map<String, Set<String>> wordsMap = new HashMap<>();
  17.         int length = wordsString.length;
  18.         // 构建map
  19.         for(int i=0;i<length-1;i++){
  20.             String tmpKey = wordsString[i];
  21.             String tmpValue = wordsString[i+1];
  22.             if(!wordsMap.containsKey(tmpKey)){.
  23.                 Set<String> wordSet = new HashSet<>();. ----
  24.                 wordSet.add(tmpValue);. ----
  25.                 wordsMap.put(tmpKey, wordSet);
  26.             }else{
  27.                 wordsMap.get(tmpKey).add(tmpValue);
  28.             }
  29.         }

  30.         if(!wordsMap.containsKey(wordsString[length-1])){
  31.             Set<String> wordSet = new HashSet<>();. .и
  32.             wordSet.add(wordsString[0]);
  33.             wordsMap.put(wordsString[length-1], wordSet);.1point3acres
  34.         }else{
  35.             wordsMap.get(wordsString[length-1]).add(wordsString[0]);. Waral dи,
  36.         }

  37.         int randomI = new Random().nextInt(length-1);
    . From 1point 3acres bbs
  38.         String randomWord = wordsString[randomI];
  39.         while(n>0){. From 1point 3acres bbs
  40.             ans.append(randomWord).append(" ");. check 1point3acres for more.
  41.             Set<String> wordTmpSet = wordsMap.get(randomWord);
  42.             int tmpLen = wordTmpSet.size();
  43.             randomI = new Random().nextInt(tmpLen);. 1point3acres
  44.             String[] tm = new String[tmpLen];
  45.             int indx = 0;
  46.             for (String v:wordTmpSet){
    . .и
  47.                 tm[indx] = v;
  48.                 indx++;
  49.             }
  50.             randomWord = tm[randomI];
  51.             n--;
  52.         }

  53.         return ans.toString();
  54.     }

  55.     public static void main(String[] args) {
  56.         String words = "this is a sentence it is a good one and it is also bad";
  57.         int n = 5;. check 1point3acres for more.
  58.         String ans = new ConstructNewWords().getNewWords(words,n);. ----
  59.         System.out.println(ans);
  60.     }. 1point 3 acres
  61. }.
复制代码

评分

参与人数 2大米 +16 收起 理由
hbkzqp + 1 给你点个赞!
匿名用户-EZV9L + 15

查看全部评分


上一篇:字节本地生活后端面经
下一篇:上海AWS挂经
推荐
our2008 2022-9-16 16:35:28 | 只看该作者
全局:
lwbhcg 发表于 2022-9-15 15:14
请问里面的not从哪里来的呀,好像没见到输入里面有not这个词,谢谢

原始句子应该是“this is a sentence it is not a good one and it is also bad”。楼主把not写丢了
回复

使用道具 举报

全局:
zkj2249629867 发表于 2022-8-18 19:37. 1point3acres.com
Hr 说国内的几乎没有组织校招

所以请问是不用管社招还是校招,只要网站有合适岗位就海投,大概是这个意思吗?
回复

使用道具 举报

推荐
 楼主| zkj2249629867 2022-8-20 22:17:28 | 只看该作者
全局:
游民星空 发表于 2022-8-20 04:13
所以请问是不用管社招还是校招,只要网站有合适岗位就海投,大概是这个意思吗?

就是这个意思,使劲投就是了
回复

使用道具 举报

全局:
赞,什么时候二面呢
回复

使用道具 举报

🔗
缅因的鱼 2022-8-19 04:41:23 | 只看该作者
全局:
可以问一下Flexport应届投的是什么岗吗楼主!感谢
回复

使用道具 举报

🔗
游民星空 2022-8-19 07:55:00 | 只看该作者
全局:
请问楼主是社招吗?因为看flexport的公众号好像中国还没有开秋招的样子?
回复

使用道具 举报

🔗
 楼主| zkj2249629867 2022-8-19 08:37:21 来自APP | 只看该作者
全局:
游民星空 发表于 2022-08-18 16:55:00. 1point 3 acres
请问楼主是社招吗?因为看flexport的公众号好像中国还没有开秋招的样子?
Hr 说国内的几乎没有组织校招
回复

使用道具 举报

🔗
baihou 2022-8-23 13:58:41 | 只看该作者
全局:
请教楼主,输出怎么会有not呢?
回复

使用道具 举报

🔗
 楼主| zkj2249629867 2022-8-23 16:12:00 | 只看该作者
全局:
baihou 发表于 2022-8-23 13:58
请教楼主,输出怎么会有not呢?

不应该啊,我这边测试的没问题啊
回复

使用道具 举报

🔗
lwbhcg 2022-9-15 15:14:36 | 只看该作者
全局:
请问里面的not从哪里来的呀,好像没见到输入里面有not这个词,谢谢
回复

使用道具 举报

您需要登录后才可以回帖 登录 | 注册账号
隐私提醒:
  • ☑ 禁止发布广告,拉群,贴个人联系方式:找人请去🔗同学同事飞友,拉群请去🔗拉群结伴,广告请去🔗跳蚤市场,和 🔗租房广告|找室友
  • ☑ 论坛内容在发帖 30 分钟内可以编辑,过后则不能删帖。为防止被骚扰甚至人肉,不要公开留微信等联系方式,如有需求请以论坛私信方式发送。
  • ☑ 干货版块可免费使用 🔗超级匿名:面经(美国面经、中国面经、数科面经、PM面经),抖包袱(美国、中国)和录取汇报、定位选校版
  • ☑ 查阅全站 🔗各种匿名方法

本版积分规则

>
快速回复 返回顶部 返回列表