📣 黑五价提前开抢|VIP一年通行证5折,蓝莓、Offer多多同步特惠
回复: 23
跳转到指定楼层
上一主题 下一主题
收起左侧

NextCapital暑期实习三轮技术面(back-to-back)面经1.5

全局:

2018(7-9月) 码农类General 硕士 实习@nextcapital - 网上海投 - 技术电面  | | Other | 应届毕业生

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

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

x
Next-capital在线面试,分成三轮技术面(back-to-back),总共持续了接近3小时,先是HR简单简单介绍了一下他们公司,然后在HackerRank平台上分享屏幕面试。
可以自己选择Java, python或者javascript语言编写,但不能选C++,他们公司不用C++。
第一轮,就一个题,按照保龄球的评分标准计算总分,比较有特点的是面试官注重test-driven development,先写测试用例再写实现的代码。
每次先写简单一些的test case,然后按照这个test case写出相应的实现代码,不需要一次性考虑所有情况。在满足这个test case的基础上再设计更复杂、特殊情况的test case,再完善实现代码。
Build an implementation to score a game of bowling, using test-driven development.
A game of bowling has 10 frames. Each frame has 2 rolls, except the 10th frame, which can have a bonus third roll depending on the first or second roll.
The goal is to knock down all 10 pins in each frame. Bowling a strike means all 10 pins are knocked down in the first roll of the frame. A spare means it took 2 rolls to knock down all 10.
Bowling a strike gives you 10 points + the next 2 rolls as a bonus.
Bowling a spare gives you 10 points + the next roll as a bonus.
There are no bonuses for strikes or spares in the 10th frame.

Sample game:
[
'3', '4',
'X', '0',
'8', '1',
'5', '/',
'6', '2',
'X', '0',
'X', '0',
'7', '1',
'1', '/',
'6', '/', 'X'
]

Notes:
The game is an array of strings, always of length 21 (all possible rolls).
Strikes are indicated with 'X'.
Spares are indicated with '/'.

以下是代码,面试时先给出了大部分框架,要自己写出核心函数和测试用例:
import java.lang.annotation.*;
import java.lang.reflect.*;
import java.io.*;
import java.util.*;
import java.math.*;
import java.util.regex.*;


@Target(ElementType.METHOD)
@Retention(RetentionPolicy.RUNTIME)
@interface Test {}

public class BowlingScorer {

    // Given a frame and array of scores, determines if a strike occurred
    private boolean wasAStrike(int frame, String[] scores) {
                return "X" == scores[(2*frame)-2];
        }

    // Given a frame and array of scores, determines if a spare occurred
    private boolean wasASpare(int frame, String[] scores) {
                return "/" == scores[(2*frame)-1];
        }

    // Given a frame and array of scores, returns the score for the rolls within that frame
    private int getFrameScore(int frame, String[] scores) {
        if (wasAStrike(frame, scores) || wasASpare(frame, scores)) {
            return 10;
        } else {
            return Integer.parseInt(scores[(2*frame)-1], 10) + Integer.parseInt(scores[(2*frame)-2], 10);
        }
    }

    // Given a frame and array of scores, return the score for the first roll of that frame
    private int getFirstRoll(int frame, String[] scores) {
        if (wasAStrike(frame, scores)) {
            return 10;
        } else {
            return Integer.parseInt(scores[(2*frame)-2], 10);
        }
    }

    // Given a frame and array of scores, returns the cumulative score up to the frame.
    // The array contains 1 score for each roll - it should be of length 21.
    public int getScore(int frame, String[] scores) {
        int i, sum=0;
        for (i=1; i<=frame; i++){
            if (wasAStrike(i, scores) && i<10){
                sum+=10;
                if (!wasAStrike(i+1, scores)){
                    sum+=getFrameScore(i+1, scores);
                } else {  // next frame is a strike
                      // for the 9th frame, it would be different
                      if (i==9){
                          if (scores[18]=="X"){
                              sum+=10;
                              if (scores[19]=="X"){
                                  sum+=10;
                              } else {
                                  sum+=Integer.valueOf(scores[19]); // the scores[19] cannot be '/' if scores[18]=='X'
                              }
                          } else {
                              sum+=getFrameScore(10, scores);
                          }
                          continue;
                      }
                    sum+=10;
                    sum+=getFirstRoll(i+2, scores);
                }
            } else if (wasASpare(i, scores) && i<10){
                 sum+=10;
                 sum+=getFirstRoll(i+1, scores);
            } else if (i<10){
                   sum+=getFrameScore(i, scores);
            } else {  //i==10
                if (!wasAStrike(10, scores) && !wasASpare(10, scores) ){
                      sum+=getFrameScore(10, scores);
                } else if (wasAStrike(10, scores)){
                    sum+=10;
                    if (scores[19]=="X"){
                        sum+=10;
                    } else if (scores[20]=="/"){
                        sum+=10;
                        return sum;
                    }
                    else sum+=Integer.valueOf(scores[19]); // it cannot be "/" for scores[19]

                    if (scores[20]=="X"){
                       sum+=10;   
                    } else sum+=Integer.valueOf(scores[20]);

                } else if (wasASpare(10, scores)){
                    sum+=10;
                    if (scores[20]=="X"){
                        sum+=10;
                    } else if (scores[20]=="/"){
                        sum+=10;
                    } else {
                        sum+=Integer.valueOf(scores[20]);
                    }
                }
            }
            //   System.out.println("line "+i+" sum:"+sum);
        }
        return sum;
    }

    @Test
    public static void itShouldReturnZeroForAllGutterBalls() {
        runTest(
            1,
            new String[] {"0", "0", "0", "0", "0", "0", "0", "0", "0", "0", "0", "0", "0", "0", "0", "0", "0", "0", "0", "0", "0"},
            0
        );

    }

    @Test
    public static void itShouldHaveMoreTests() {
         runTest(
            10,
            new String[] {"3", "4", "X", "0", "8", "1", "5", "/", "6", "2", "X", "0", "X", "0", "7", "1", "1", "/", "6", "/", "X"},
            148
        );

    };

       @Test
    public static void itShouldHave10thTest() {
         runTest(
            10,
            new String[] {"3", "4", "X", "0", "8", "1", "5", "/", "6", "2", "X", "0", "X", "0", "7", "1", "1", "/", "X", "X", "6"},
            158
        );

    };

      @Test
      public static void itShouldHave10thTest2() {
         runTest(
            10,
            new String[] {"0", "0", "0", "0", "0", "0", "0", "0", "0", "0", "0", "0", "0", "0", "0", "0", "0", "/", "4", "3", "X"},
            21
        );
    };

      @Test
      public static void itShouldHave10thTest3() {
         runTest(
            10,
            new String[] {"0",
您好!
本帖隐藏的内容需要积分高于 188 才可浏览
您当前积分为 0。
使用VIP即刻解锁阅读权限或查看其他获取积分的方式
游客,您好!
本帖隐藏的内容需要积分高于 188 才可浏览
您当前积分为 0。
VIP即刻解锁阅读权限 或 查看其他获取积分的方式
Unlock interview details and practice with AI
Popular Interview Questions from Top Companies
(int i = 0; i < strings.length - mid; i++) {
            rightHalf[i] = strings[mid + i];
        }
        return new String[][]{ leftHalf, rightHalf };
    }

    static String[] merge(String[] left, String[] right) {
        if (left.length == 0) {
            return right;
        } else if (right.length == 0) {
            return left;
        } else if (left[0].compareTo(right[0]) < 0) {
            String[][] arrays = pluckFirst(left);
            String[] firstLeft = arrays[0];
            String[] newLeft = arrays[1];
            return concatArrays(firstLeft, merge(newLeft, right));
        } else {
            String[][] arrays = pluckFirst(right);
            String[] firstRight = arrays[0];
            String[] newRight = arrays[1];
            return concatArrays(firstRight, merge(left, newRight));
        }
    }

    static String[][] pluckFirst(String[] strings) {
        String[] first;
        first = new String[1];
        first[0] = strings[0];
        String[] rest;
        if (strings.length > 1) {
            rest = new String[strings.length - 1];
            for(int i = 1; i < strings.length; i++) {
                rest[i-1] = strings[i];
            }
        } else {
            rest = new String[0];
        }
        return new String[][]{first, rest};
    }

    static String[] concatArrays(String[] first, String[] second) {
        int length = first.length + second.length;
        String[] result = new String[length];
        for(int i = 0; i < first.length; i++) {
            result[i] = first[i];
        }
        for(int i = 0; i < second.length; i++) {
            int index = first.length + i;
            result[index] = second[i];
        }
        return result;
    }

    static String[] rejiggerArray(String[] strings) {
        String[] output = mergeSort(strings);
        List<String> resultList = new LinkedList<String>();
        for (int i = 1; i < output.length-1; i++) {
          //  System.out.println("The "+i+"-th string:"+ output[i]);
            char[] chars = output[i].toCharArray();
            List<Character> charList = new ArrayList<Character>();
            for(int j = 0; j < chars.length; j++) {
                if (j == 0) {
                    charList.add(chars[0]);
                    continue;
                }
                if(chars.length % j != 0) {
                    charList.add(chars[j]);
                }
            }
            StringBuilder result = new StringBuilder(charList.size());
            for (Character c : charList) {
                result.append(c);
            }
            resultList.add(result.toString());
        }
        return resultList.toArray(new String[resultList.size()]);
    }

    public static void main(String[] args) throws IOException {
        Scanner in = new Scanner(System.in);
        final String fileName = System.getenv("OUTPUT_PATH");
        BufferedWriter bw = new BufferedWriter(new FileWriter(fileName));
        String[] res;

        int _strings_size = 0;
        _strings_size = Integer.parseInt(in.nextLine().trim());
        String[] _strings = new String[_strings_size];
        String _strings_item;
        for(int _strings_i = 0; _strings_i < _strings_size; _strings_i++) {
            try {
                _strings_item = in.nextLine();
            } catch (Exception e) {
                _strings_item = null;
            }
            if (_strings_item.equals("%")) {
                _strings_item = "";
            }
            _strings[_strings_i] = _strings_item;
        }

        res = rejiggerArray(_strings);
        for(int res_i=0; res_i < res.length; res_i++) {
            if (res[res_i].equals("")) {
                res[res_i] = "%";
            }
            bw.write(String.valueOf(res[res_i]));
            bw.newLine();
        }

        bw.close();
    }
}

评分

参与人数 6大米 +17 收起 理由
UC小王子 + 3 有用
ycl + 1 很有用的信息!
moneshine + 2 很有用的信息!
prince123 + 5 很有用的信息!
天遥 + 3 很有用的信息!

查看全部评分


上一篇:airbnb skype面
下一篇:Godaddy二面
推荐
moneshine 2018-2-23 06:46:18 | 只看该作者
全局:
楼主您好,我刚过了他家oa,不知道你有没有收到说 一个30分钟的电话聊天之类的。我也是usc的!好巧!

补充内容 (2018-2-23 06:46):
这是我朋友的号哈哈哈
回复

使用道具 举报

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

使用道具 举报

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

使用道具 举报

🔗
applezhang01 2018-1-9 02:33:20 | 只看该作者
全局:
谢谢楼主!!!请问有回音了吗
回复

使用道具 举报

🔗
 楼主| qianlizimu 2018-1-9 02:48:59 | 只看该作者
全局:
applezhang01 发表于 2018-1-9 02:33
谢谢楼主!!!请问有回音了吗

他们还没回复
回复

使用道具 举报

🔗
applezhang01 2018-1-9 02:59:41 | 只看该作者
全局:

下周去onsite,谢谢楼主分享
回复

使用道具 举报

全局:
LZ很牛!
我OA都过不了。。
回复

使用道具 举报

🔗
 楼主| qianlizimu 2018-1-16 04:48:24 | 只看该作者
全局:
过了10天发了offer,在芝加哥提供两个月的免费住宿,实习生待遇是每小时25刀。如果不需要公司安排住宿的话那么实习工资标准是每小时30刀。

评分

参与人数 1大米 +5 收起 理由
prince123 + 5 谢谢

查看全部评分

回复

使用道具 举报

🔗
nswzhbdc 2018-2-9 06:04:17 | 只看该作者
全局:
请问楼主实习的话电面之后还有onsite吗
回复

使用道具 举报

🔗
天遥 2018-2-9 06:45:39 | 只看该作者
全局:
面试直接做题没有聊简历吗
回复

使用道具 举报

🔗
 楼主| qianlizimu 2018-2-10 03:50:15 | 只看该作者
全局:
只有电面没有onsite.技术面试只是做题不聊简历
回复

使用道具 举报

全局:
楼主能问下oa都有什么题吗,谢谢!
回复

使用道具 举报

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

本版积分规则

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