2022 Spring NetEase Leihuo Frontend Summer Internship Written Exam (Full Score)

发表于 2022-03-26 16:00 561 字 3 min read

cos avatar

cos

FE / ACG / 手工 / 深色模式强迫症 / INFP / 兴趣广泛养两只猫的老宅女 / remote

笔试包含7道不定项选择题、5道填空题、2道问答题和3道编程题,总分较高,编程题难度较低且代码量少,完成时间短。考生在编程题中快速完成斐波那契、括号匹配等题,但最长递增子序列题做错,整体表现稳定,最终通过Copilot辅助完成问答题。

This article has been machine-translated from Chinese. The translation may contain inaccuracies or awkward phrasing. If in doubt, please refer to the original Chinese version.

  • Multiple choice: 7 questions, 21 points
  • Multiple select: 5 questions, 30 points
  • Fill-in-the-blank: 2 questions, forgot how many points
  • Short answer: 2 questions, don’t remember
  • Programming: 3 problems at easy, easy, medium difficulty. Core code mode. Total code volume under 40 lines.

Finished the programming problems in 20 minutes, submitted, and went out to have fun. Tsk.

Short Answer 2 - Implementing a get Function

After the exam, I let Copilot auto-complete it. Hilarious.

let obj = { a: [{ b: { c: 1 } }] };
// console.log(obj.a[0].b.c)
function get(obj, str) {
  str = str.split('.');
  let len = str.length;
  for (let i = 0; i < len; ++i) {
    if (str[i] && str[i].indexOf('[') != -1) {
      let index = str[i].match(/\[(\d+)\]/)[1];
      let name = str[i].split('[')[0];
      if (name in obj) {
        obj = obj[name][index];
      } else {
        return undefined;
      }
    } else if (str[i] in obj && obj[str[i]]) {
      obj = obj[str[i]];
    } else {
      return undefined;
    }
  }
  return obj;
}
console.log(get(obj, 'a[0].b.c'));
console.log(get(obj, 'a[0].b.s'));
console.log(get(obj, 'a.s.q'));

Programming Problem 1 - Fibonacci

Fibonacci, one-liner: return n == 0 || n == 1? n: fib(n-1)+fib(n-2)

Programming Problem 2 - Bracket Matching

Solved instantly. Just use a stack, ignore * characters.

/**
 * 代码中的类名、方法名、参数名已经指定,请勿修改,直接返回方法规定的值即可
 *
 *
 * @param str string字符串 输入字符串
 * @return bool布尔型
 */
function isVerified(str) {
  // write code here
  let len = str.length;
  let s = [];
  for (let i = 0; i < len; ++i) {
    if (str[i] == '*') continue;
    if (str[i] == '{' || str[i] == '[' || str[i] == '(') {
      s.push(str[i]);
    } else {
      let top = s[s.length - 1];
      if ((str[i] == '}' && top == '{') || (str[i] == ']' && top == '[') || (str[i] == ')' && top == '(')) {
        s.pop();
      }
    }
  }
  return s.length == 0;
}
module.exports = {
  isVerified: isVerified,
};

Programming Problem 3 - Longest Increasing Subsequence Length

Done this so many times. Just DP.

  • dp[i] represents the length of the longest increasing subsequence from index 0 to i. Each time, find the j from 0 to i-1 that can form an increasing sequence with the current i, and take the maximum as dp[i].
/**
 * 代码中的类名、方法名、参数名已经指定,请勿修改,直接返回方法规定的值即可
 *
 *
 * @param arr int整型一维数组 数组
 * @return int整型
 */
function lengthOfLis(arr) {
  // write code here
  let len = arr.length;
  let dp = new Array(len).fill(1);
  dp[0] = 1;
  for (let i = 1; i < len; ++i) {
    for (let j = 0; j < i; ++j) {
      if (arr[i] > arr[j]) dp[i] = Math.max(dp[j] + 1, dp[i]);
    }
  }
  return dp[len - 1];
}
module.exports = {
  lengthOfLis: lengthOfLis,
};
// 求数组最长递增子序列长度

喜欢的话,留下你的评论吧~

© 2020 - 2026 cos @cosine
Powered by theme astro-koharu · Inspired by Shoka