CVTE前端一面面经

1. 自我介绍
2. 问实习经历,觉得最困难的是什么
3. 问场景题
    现在有三个场景,你怎么分析,怎么排查问题
    a. 类似与百度图片,图片加载不出来
            (前端问题、后台问题、cdn、浏览器版本过低、网络问题)
    b. 页面出现白屏
    c. 做一个无限加载列表,下滑的时候会有卡顿,查看大图的时候左滑右滑也有卡顿
4. 在一个页面中html中,背景颜色是红色,有很多img,但是src是比较大的资源,在网页打开的一瞬间,所看到的变化都有什么
5. 目前存在一批任务,这些任务数据结构如下,任务默认不存在循环依赖。要求实现一个函数,该函数可以计算出一批任务的最长耗时,并给出最长耗时的任务执行顺序
interface Task {
    // 任务id
    id: string;
    // 任务执行耗时
    cost: number;
    // 前置任务id,可选
    dep?: string;
}

// 实例任务列表
const tasks: Task[] = [
    { id: '1', cost: 100 },
    { id: '2', cost: 100, dep: '4' },
    { id: '4', cost: 100, dep: '3' },
    { id: '3', cost: 100 },
];

// 输出
300
3 4 2

// interface Task {
//   // 任务id
//   id: string;
//   // 任务执行耗时
//   cost: number;
//   // 前置任务id,可选
//   dep?: string;
// }

// // 实例任务列表
// const tasks: Task[] = [
//   { id: '1', cost: 100 },
//   { id: '2', cost: 100, dep: '4' },
//   { id: '4', cost: 100, dep: '3' },
//   { id: '3', cost: 100 },
// ];

// 输出
// 300
// 3 4 2

const tasks = [
  { id: '1', cost: 100 },
  { id: '2', cost: 100, dep: '4' },
  { id: '4', cost: 100, dep: '3' },
  { id: '3', cost: 100 },
];

function time(tasks) {
  let max = 0;
  let maxArr = [];
  let arr = [0];
  let cost = [0];
  for(i = 0;i < tasks.length; i++){
    if(tasks[i]?.dep){
      arr[tasks[i]?.id] = tasks[i].dep;
    }else{
      arr[tasks[i]?.id] = 0;
    }
    cost[tasks[i]?.id] = tasks[i].cost;
  }
  // console.log(arr,cost);
  for(i = 1;i <= tasks.length; i++){
    if(arr[i] != 0){
      // let sum = tasks[i-1].cost;
      // let sumArr = [i];
      let sum = 0;
      let sumArr = [];
      let j = i;
      while(true){
        sum += cost[j];
        sumArr.push(j)
        j = arr[j]
        if(j==0) break;
      }

      if(sum > max){
        max = sum;
        maxArr = sumArr;
      }
    }
  }
  return [max, maxArr];
}
console.log(time(tasks));


#前端面经##CVTE#
全部评论
一模一样,直接挂掉
点赞 回复 分享
发布于 2023-02-24 16:27 辽宁
昨天面的那道题目也是任务队列的...挂了
点赞 回复 分享
发布于 2022-10-21 10:29 广东
大佬哇
点赞 回复 分享
发布于 2022-09-16 16:19 浙江
我刚面完来看CVTE面经,我的问题和你的一模一样,我感觉要凉了
点赞 回复 分享
发布于 2022-09-16 10:20 江苏
请问快手进面了没
点赞 回复 分享
发布于 2022-09-15 13:26 北京
请问过了吗?
点赞 回复 分享
发布于 2022-09-08 07:28 陕西
hi~同学,秋招遇“寒气”,牛客送温暖啦!23届秋招笔面经有奖征集中,参与就得牛客会员7天免费体验,最高赢300元京东卡!戳我去看>>>https://www.nowcoder.com/link/zhengjipinglun
点赞 回复 分享
发布于 2022-09-07 08:02 北京
正式批吗大佬
点赞 回复 分享
发布于 2022-09-06 18:44 广东

相关推荐

评论
3
51
分享

创作者周榜

更多
牛客网
牛客网在线编程
牛客网题解
牛客企业服务