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

Databricks挂经

🔗
匿名用户-MEWGX  2021-7-23 06:24:02 |倒序浏览

2021(4-6月) 码农类General 博士 全职@databricks - 网上海投 - Onsite  | | Fail | 在职跳槽

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

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

x
发一下最近的databricks 面经,楼主没面到 传说中的港男,但还是跪在了HC。 以下是面经

店面是insert delete get random


1. Customer API的面经题。跟这个一样
问了一个followup,是让实现  get_nesting_level(int customer_id, int nesting_level)
比如 get_nesting_level(1, 0) -> 返回 customer_id=1 的自己的revenue
get_nesting_level(1,2) -> 返回custoemr_id=1, 同时 包括他refer的两层的结果。举个例子 1 refer 2, 2 refer 3, 那么这里就要return 1, 2, 3 的总和。

面试官想optimize这个function,牺牲insert的性能。我的解法就是维护一个Map<CustomerId, Map<NestingLevel, Revenue
您好!
本帖隐藏的内容需要积分高于 188 才可浏览
您当前积分为 0。
使用VIP即刻解锁阅读权限或查看其他获取积分的方式
游客,您好!
本帖隐藏的内容需要积分高于 188 才可浏览
您当前积分为 0。
VIP即刻解锁阅读权限查看其他获取积分的方式
Unlock interview details and practice with AI
Curated Interview Questions from Top Companies
。又等了两天,最后hr跟我说HC要reject。。。

Bar高我能理解,因为我也不是infra出身,个人觉得自己实力也不强,只不过onsite完了听hr口气是觉得自己面的还挺好的。reference的时候我也是到处联系人,最终给拒了,也是花了好多精力和时间。耽误自己不说,reference也要和hm约时间打电话。。。我只是想吐槽,如果一开始HC觉得我case不strong,能不能onsite完就把我拒了,何必让我做take home 以及team match呢?

  1. package databricks;

  2. import java.io.BufferedReader;
  3. import java.io.FileReader;
  4. import java.io.IOException;
  5. import java.nio.file.Files;
  6. import java.nio.file.Paths;
  7. import java.util.ArrayList;
  8. import java.util.Arrays;
  9. import java.util.Iterator;
  10. import java.util.List;
  11. import java.util.Map;
  12. import java.util.stream.Stream;
  13. import java.util.stream.Collectors;

  14. /**
  15. * A CSVViwer represents a view of a csv file, backed by Stream<Row> data
  16. * columnNames
  17. */

  18. public class CSVViewer {
  19.     // Column Names for this CSVViewer
  20.     private List<String> columnNames;

  21.     // Contains CSVViewer data.
  22.     private Stream<Row> data;

  23.     // fileName could be empty if it not constructed from reading a file.
  24.     private String fileName = "";

  25.     /**
  26.      * Reads from a given path and construct CSVViewer.
  27.      *
  28.      * @param path
  29.      * @throws IOException
  30.      */
  31.     public CSVViewer(String path) throws IOException {
  32.         fileName = path;

  33.         Stream<String> dataLines = Files.lines(Paths.get(fileName));

  34.         String firstLine = dataLines.iterator().next();
  35.         columnNames = Arrays.asList(firstLine.split(","));

  36.         data = dataLines.map(Row::new);
  37.     }

  38.     /**
  39.      * Contructs a CSVViewer from columnNames and data.
  40.      *
  41.      * @param columnNames
  42.      * @param data
  43.      * @throws IOException
  44.      */
  45.     public CSVViewer(List<String> columnNames, Stream<Row> data) {
  46.         this.columnNames = columnNames;
  47.         this.data = data;
  48.     }

  49.     /**
  50.      * Print ColumnNames in one line.
  51.      */
  52.     public List<String> getColumnNames() {
  53.         return columnNames;
  54.     }

  55.     /**
  56.      * Print ColumnNames first, followed by all the data rows.
  57.      */
  58.     public List<String> getData() {
  59.         return data.map(Row::toString).collect(Collectors.toList());
  60.     }

  61.     /**
  62.      * Truncates data to length.
  63.      *
  64.      * @param length the final size truncates to.
  65.      * [url=home.php?mod=space&uid=160137]@return[/url] this.
  66.      */
  67.     public CSVViewer take(int length) {
  68.         assert length > 0 : "TAKE length should be larger than 0.";

  69.         this.data = data.limit(length);
  70.         return this;
  71.     }

  72.     /**
  73.      * Truncates data to length.
  74.      *
  75.      * @param cols a list of column names to be selected.
  76.      */
  77.     public CSVViewer select(List<String> cols) {
  78.         List<Integer> colIndex = cols.stream().map(col -> getColIndex(col)).collect(Collectors.toList());

  79.         this.columnNames = cols;
  80.         this.data = data.map(row -> {
  81.             List<String> list = new ArrayList<>();

  82.             for (int i = 0; i < colIndex.size(); i++) {
  83.                 list.add(row.get(colIndex.get(i)));
  84.             }

  85.             return new Row(list);
  86.         });
  87.         return this;
  88.     }

  89.     /**
  90.      * Order by colName.
  91.      *
  92.      * @param colName
  93.      * @return this.
  94.      */
  95.     public CSVViewer orderby(String colName) {
  96.         final int sortIndex = getColIndex(colName);

  97.         this.data = data.sorted((row1, row2) -> Row.compareAtIndex(row1, row2, sortIndex));
  98.         return this;
  99.     }

  100.     /**
  101.      * Countby colName
  102.      *
  103.      * @param colName
  104.      * @return this.
  105.      */
  106.     public CSVViewer countby(String colName) {
  107.         final int colIndex = getColIndex(colName);

  108.         Map<String, Long> map = data.collect(Collectors.groupingBy(row -> row.get(colIndex), Collectors.counting()));

  109.         this.columnNames = Arrays.asList(colName, "count");
  110.         this.data = map.entrySet().stream().map(entry -> new Row(entry.getKey(), Long.toString(entry.getValue())));
  111.         return this;
  112.     }

  113.     /**
  114.      * Performs a left join with the joinFile.
  115.      *
  116.      * @param joinFile
  117.      * @param joinCol
  118.      * @return this.
  119.      */
  120.     public CSVViewer leftjoin(CSVViewer joinFile, String joinCol) {
  121.         final int joinColIndex = joinFile.getColIndex(joinCol);
  122.         Map<String, Row> map = joinFile.data.collect(Collectors.toMap(row -> row.get(joinColIndex), row -> {
  123.             List<String> newCols = new ArrayList<>();
  124.             for (int j = 0; j < row.columns.length; j++) {
  125.                 if (j != joinColIndex) {
  126.                     newCols.add(row.get(j));
  127.                 }
  128.             }
  129.             return new Row(newCols);
  130.         }, (left, right) -> left));

  131.         List<String> colNamesList = new ArrayList<>();
  132.         colNamesList.addAll(columnNames);
  133.         colNamesList
  134.                 .addAll(joinFile.columnNames.stream().filter(col -> !col.equals(joinCol)).collect(Collectors.toList()));
  135.         this.columnNames = colNamesList;

  136.         final int colIndex = getColIndex(joinCol);
  137.         this.data = data.map(row -> {
  138.             List<String> newCols = new ArrayList<>();
  139.             newCols.addAll(Arrays.asList(row.columns));
  140.             if (map.containsKey(row.get(colIndex))) {
  141.                 newCols.addAll(Arrays.asList(map.get(row.get(colIndex)).columns));
  142.             } else {
  143.                 for (int i = newCols.size(); i < colNamesList.size(); i++) {
  144.                     newCols.add("");
  145.                 }
  146.             }

  147.             return new Row(newCols);
  148.         });

  149.         return this;
  150.     }

  151.     /**
  152.      * Performs a sort merge join with the joinFile.
  153.      *
  154.      * @param joinFile
  155.      * @param joinCol
  156.      * @return this.
  157.      */
  158.     public CSVViewer sortMergeJoin(CSVViewer joinFile, String joinCol) {

  159.         this.orderby(joinCol);
  160.         joinFile = joinFile.orderby(joinCol);

  161.         final int colIndex1 = getColIndex(joinCol);
  162.         final int colIndex2 = joinFile.getColIndex(joinCol);

  163.         List<String> colNamesList = new ArrayList<>();
  164.         colNamesList.addAll(columnNames);
  165.         colNamesList
  166.                 .addAll(joinFile.columnNames.stream().filter(col -> !col.equals(joinCol)).collect(Collectors.toList()));
  167.         this.columnNames = colNamesList;

  168.         Stream<Row> joinedRows = Stream.of();

  169.         Iterator<Row> iter1 = this.data.iterator();
  170.         Iterator<Row> iter2 = joinFile.data.iterator();

  171.         Row row2 = iter2.hasNext() ? iter2.next() : null;
  172.         while (iter1.hasNext()) {
  173.             Row row1 = iter1.next();

  174.             // Advance row2 to row1 or pass row1 if possible.
  175.             int cmp = -1;
  176.             while (row2 != null) {
  177.                 cmp = row1.get(colIndex1).compareTo(row2.get(colIndex2));
  178.                 if (cmp >= 0) {
  179.                     break;
  180.                 } else {
  181.                     if (iter2.hasNext()) {
  182.                         row2 = iter2.next();
  183.                     } else {
  184.                         row2 = null;
  185.                     }
  186.                 }
  187.             }

  188.             List<String> cols = new ArrayList<>();
  189.             cols.addAll(Arrays.asList(row1.columns));

  190.             if (row2 != null && cmp == 0) {
  191.                 for (int i = 0; i < row2.columns.length; i++) {
  192.                     if (i != colIndex2) {
  193.                         cols.add(row2.columns[i]);
  194.                     }
  195.                 }
  196.             } else {
  197.                 for (int i = cols.size(); i < colNamesList.size(); i++) {
  198.                     cols.add("");
  199.                 }
  200.             }
  201.             joinedRows = Stream.concat(joinedRows, Stream.of(new Row(cols)));
  202.         }

  203.         this.data = joinedRows;
  204.         return this;
  205.     }

  206.     // Returns the col index of specified colName.
  207.     // Throws AssertionError if colName is not found.
  208.     // NOTE: this is used by SELECT/SORT/ORDERBY/COUNTBY/JOIN to throw if columnName
  209.     // doesn't exist.
  210.     private int getColIndex(String colName) {
  211.         for (int i = 0; i < columnNames.size(); i++) {
  212.             if (columnNames.get(i).equals(colName)) {
  213.                 return i;
  214.             }
  215.         }

  216.         throw new AssertionError(String.format("Cannot find COLUMN %s in %s", colName, fileName));
  217.     }

  218. }
复制代码


评分

参与人数 5大米 +37 收起 理由
北邮未水天 + 1 给你点个赞!
hadoopG + 2 很有用的信息!
isildur3 + 1 给你点个赞!
匿名用户-ZYXNS + 30
ilstxfe + 3 很有用的信息!

查看全部评分


上一篇:方块 MLE tech面
下一篇:新鲜阿酷OA
推荐
ivanyang 2021-7-23 16:30:35 | 只看该作者
全局:
您好!
本帖隐藏的内容需要积分高于 100 才可浏览
您当前积分为 0。
使用VIP即刻解锁阅读权限或查看其他获取积分的方式
游客,您好!
本帖隐藏的内容需要积分高于 100 才可浏览
您当前积分为 0。
VIP即刻解锁阅读权限查看其他获取积分的方式
Unlock interview details and practice with AI
Curated Interview Questions from Top Companies
回复

使用道具 举报

推荐
eat_orange 2021-7-23 08:28:47 | 只看该作者
全局:
您好!
本帖隐藏的内容需要积分高于 100 才可浏览
您当前积分为 0。
使用VIP即刻解锁阅读权限或查看其他获取积分的方式
游客,您好!
本帖隐藏的内容需要积分高于 100 才可浏览
您当前积分为 0。
VIP即刻解锁阅读权限查看其他获取积分的方式
Unlock interview details and practice with AI
Curated Interview Questions from Top Companies
回复

使用道具 举报

推荐
itshighnoon 2021-7-23 08:01:43 | 只看该作者
全局:
匿名者 发表于 2021-7-22 16:49
和lz 类似的遭遇,只不过我homework 写了3000多行,各种优化了下。我觉得在homework和reference之前,你得 ...

3000行也是够用心的,话说都优化啥呢。。。
回复

使用道具 举报

地里匿名用户
🔗
匿名用户-RVJYQ  2021-7-23 06:59:58 来自APP
大热都是这样 上次我面一个还没上市的公司也是莫名其妙被拒
回复

使用道具 举报

地里匿名用户
🔗
匿名用户-WVGOY  2021-7-23 07:49:38
和lz 类似的遭遇,只不过我homework 写了3000多行,各种优化了下。我觉得在homework和reference之前,你得大概保证个能过的概率,不然真是很浪费时间,包括hiring manager的,得和reference聊天啥的。
回复

使用道具 举报

🔗
eat_orange 2021-7-23 08:26:29 | 只看该作者
全局:
您好!
本帖隐藏的内容需要积分高于 100 才可浏览
您当前积分为 0。
使用VIP即刻解锁阅读权限或查看其他获取积分的方式
游客,您好!
本帖隐藏的内容需要积分高于 100 才可浏览
您当前积分为 0。
VIP即刻解锁阅读权限查看其他获取积分的方式
Unlock interview details and practice with AI
Curated Interview Questions from Top Companies

评分

参与人数 3大米 +5 收起 理由
xueraijier + 1 赞一个
ilstxfe + 3 很有用的信息!
itshighnoon + 1 很有用的信息!

查看全部评分

回复

使用道具 举报

🔗
itshighnoon 2021-7-23 08:36:35 | 只看该作者
全局:
eat_orange 发表于 2021-7-22 17:28
我不是层主,但这种就按照sql查询引擎和数据处理的思路优化呗,各种batch/vectorization/pipeline/query  ...

明白了,这要是不搞query engine的话确实不知道啊。。。
回复

使用道具 举报

全局:
人家ONSITE完给你TAKE HOME,不一定是必要程序,也可能是国人HM再给你一个机会来IMPRESS HC。我只是说可能哈。

我NG的时候,就是被一个加拿大的华裔HM用一个TAKE HOME来摆平组里的个别不同意见,最后上岸一个二线大厂。
回复

使用道具 举报

🔗
ilstxfe 2021-7-25 09:17:45 | 只看该作者
全局:
楼主你面的是senior还是staff?已加米,谢谢
回复

使用道具 举报

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

本版积分规则

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