注册一亩三分地论坛,查看更多干货!
您需要 登录 才可以下载或查看附件。没有帐号?注册账号
x
分享一个周三刚刚完成的Palantir超冷门的电面。为啥冷门呢?因为它全是debug改错题.....为什么和网上的面经完全不一样的画风啊摔!不过不难是真的,可能看我是大三所以手下留情吧2333
下面是整套题的代码,给了几个function以及comments,让改最后一个function的错误,both correctness and performance
=========================================================================- class Result {
- public:
- /**
- * Gets the result's timestamp. Results with lower timestamps are loaded
- * before results with higher timestamps. Timestamps are guaranteed to be
- * non-negative, and different results have distinct timestamps.
- */
- long getTimestamp() const;
- /**
- * Prints a textual representation of this result.
- */
- std::string getDescription() const;
- // Other methods not important for this problem
-
- };
- /**
- * Return type used for page-based iteration. See the comment on loadResultsPage
- * for the precise meaning of the fields.
- */
- struct ResultsPage {
- std::vector<Result> resultList;
- bool hasMoreResults;
- };
- /**
- * Returns the next pageSize results that have a timestamp greater than or equal
- * to startTime. The results are guaranteed to be ordered by timestamp
- * (increasing).
- *
- * If there are at least pageSize results available, the resultList contains the
- * next pageSize results. If there are fewer than pageSize results available,
- * resultList contains all remaining results. hasMoreResults in the ResultsPage
- * is true if and only if there are more results to load after the ones in
- * resultList.
- *
- * The results are loaded from the database as a batch.
- */
- ResultsPage loadResultsPage(long startTime, int pageSize);
- /*******************************************************************************
- * Instructions: Find as many errors as possible in the code below. Make a copy
- * of the function and change the code to be correct.
- *
- * You should be looking for correctness and performance issues. You may assume
- * that the code correctly compiles.
- ******************************************************************************/
-
- /**
- * This method should print the contents of all results to the console.
- */
- void printAllResults() {
- int pageSize = 100;
- long currentTimestamp = 0;
- while (loadResultsPage(currentTimestamp, pageSize).hasMoreResults) {
- std::vector<Result> resultList = loadResultsPage(currentTimestamp, pageSize).resultList;
- for (int i = 0; i < pageSize; i++) {
- Result result = resultList[i];
- cout << result.getDescription() << endl;
- }
- Result lastResult = resultList[resultList.size()];
- currentTimestamp = lastResult.getTimestamp();
- }
- }
复制代码 =========================================================================
我找出了如下改进:
redundant calls to loadResultPage(), could be reduced to once per while-loop iteration;
最后一个iteration后应该再读一次被遗漏的resultPage, 然pageSize parameter应改成list.size();
您好! 本帖隐藏的内容需要积分高于 188 才可浏览 您当前积分为 0。 使用VIP即刻解锁阅读权限或查看其他获取积分的方式 游客,您好! 本帖隐藏的内容需要积分高于 188 才可浏览 您当前积分为 0。 VIP即刻解锁阅读权限 或 查看其他获取积分的方式 Unlock interview details and practice with AI Curated Interview Questions from Top Companies
r:rgb(247, 247, 247)">嗯,然后照例让我问问题,然后我说表示这个题很有趣,因为完全没碰到过这种形式,然后recruiter非常高冷的有嘲讽的语调说其他的面试问题都是algorithm对吧?立刻脑补到小哥一脸傲娇的“我们偏偏要与众不同”..然后周四被秒拒,跪的干脆利落~BTW,这个recruiter全程非常安静,也完全不要求我和他沟通交流,甚至和我说“只要你觉得舒服,埋头改就行,不用告诉我想法”......然后电话全程安静的都听不见呼吸,我几次以为他掉线了.....好不适应这种方式,话唠的我(实力不够)果然比较喜欢不停说想法少写代码的面试呐~就酱,希望对大家有帮助~
|