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

数据🧱 Algorithm & Coding 面经汇总

   
🔗
匿名用户-KCSHE  2025-6-12 11:24:37 |倒序浏览

2025(4-6月) 码农类General 硕士 全职@databricks - 猎头 - Onsite  | 😃 Positive 😐 Average | Pass | 在职跳槽

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

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

x
本帖最后由 匿名 于 2025-6-11 20:28 编辑

前段时间面 databricks 总结了一下他们的面试题,截止到去年10月好像。我面试的时候都是下面的原题

求米!!🥺 祝大家都能过
Algorithm Problems
  • Delete Interval

    • Delete index from interval
  • Max Area of Island (dfs, O(M*N))

    • LC695 - Max Area of Island
  • SnapshotSet

    • SnapshotSet with versioned iterator (结合 LC1146 思路)
          实现一个set,需要一个支持当前状态的iterator,无论是put还是remove,不影响iterator之后的遍历

  • KV Store

    • LC 981,设计一个支持高效 get/put 和 query 的 KV store
          技术点:滑动窗口,TreeMap 或双端队列处理时间戳。
      您好!
      本帖隐藏的内容需要积分高于 188 才可浏览
      您当前积分为 0。
      使用VIP即刻解锁阅读权限或查看其他获取积分的方式
      游客,您好!
      本帖隐藏的内容需要积分高于 188 才可浏览
      您当前积分为 0。
      VIP即刻解锁阅读权限 或 查看其他获取积分的方式
      Unlock interview details and practice with AI
      Popular Interview Questions from Top Companies
      yArray([10, 20, 30, 40, 50])
          arr.map(lambda x:x*2).indexOf(40)  ----> 1
          arr.map(lambda x:x2).map(lambda x:x3).indexOf(240) ----> 3 注意这里重新开了一个chain,上一行的map就不计算在内了
    • Each map() must return a new LazyArray, because chains are independent

  1.    [backcolor=rgb(247, 247, 247)]import java.util.*;[/backcolor][list]
  2. [list]
  3. [*][code]import java.util.function.Function;

  4. public class LazyArray {
  5.     private List<Integer> base;
  6.     private List<Function<Integer, Integer>> operations;

  7.     public LazyArray(List<Integer> base) {
  8.         this.base = base;
  9.         this.operations = new ArrayList<>();
  10.     }

  11.     private LazyArray(List<Integer> base, List<Function<Integer, Integer>> ops) {
  12.         this.base = base;
  13.         this.operations = ops;
  14.     }

  15.     public LazyArray map(Function<Integer, Integer> func) {
  16.         List<Function<Integer, Integer>> newOps = new ArrayList<>(this.operations);
  17.         newOps.add(func);
  18.         return new LazyArray(this.base, newOps);
  19.     }

  20.     public int indexOf(int target) {
  21.         for (int i = 0; i < base.size(); i++) {
  22.             int val = base.get(i);
  23.             for (Function<Integer, Integer> op : operations) {
  24.                 val = op.apply(val);
  25.             }
  26.             if (val == target) {
  27.                 return i;
  28.             }
  29.         }
  30.         return -1;
  31.     }
  32. }
复制代码



2. Circuit Breaker
  1.     import java.time.Duration;
  2.     import java.time.Instant;
  3.     import java.util.concurrent.atomic.*;
  4.     import java.util.function.Supplier;
  5.    
  6.     public class CircuitBreaker<T> {
  7.    
  8.         private enum State {
  9.             CLOSED, OPEN, HALF_OPEN
  10.         }
  11.    
  12.         private final AtomicReference<State> state = new AtomicReference<>(State.CLOSED);
  13.         private final AtomicInteger failureCount = new AtomicInteger(0);
  14.         private final AtomicReference<Instant> lastFailureTime = new AtomicReference<>(null);
  15.    
  16.         private final int failureThreshold;
  17.         private final Duration recoveryTimeout;
  18.    
  19.         public CircuitBreaker(int failureThreshold, Duration recoveryTimeout) {
  20.             this.failureThreshold = failureThreshold;
  21.             this.recoveryTimeout = recoveryTimeout;
  22.         }
  23.    
  24.                     // or we can use synchronized and don't need to use atomic
  25.         public T call(Supplier<T> supplier) throws Exception {
  26.             Instant now = Instant.now();
  27.             State currentState = state.get();
  28.    
  29.             if (currentState == State.OPEN) {
  30.                 Instant lastFailure = lastFailureTime.get();
  31.                 if (lastFailure != null &&
  32.                     Duration.between(lastFailure, now).compareTo(recoveryTimeout) > 0) {
  33.                     // Try to transition from OPEN → HALF_OPEN
  34.                     if (!state.compareAndSet(State.OPEN, State.HALF_OPEN)) {
  35.                         throw new RuntimeException("Circuit is OPEN. Request blocked.");
  36.                     }
  37.                 } else {
  38.                     throw new RuntimeException("Circuit is OPEN. Request blocked.");
  39.                 }
  40.             }
  41.    
  42.             try {
  43.                 T result = supplier.get();
  44.                 onSuccess();
  45.                 return result;
  46.             } catch (Exception e) {
  47.                 onFailure();
  48.                 throw e;
  49.             }
  50.         }
  51.    
  52.         private void onSuccess() {
  53.             failureCount.set(0);
  54.             if (state.get() == State.HALF_OPEN) {
  55.                 state.compareAndSet(State.HALF_OPEN, State.CLOSED);
  56.             }
  57.         }
  58.    
  59.         private void onFailure() {
  60.             int failures = failureCount.incrementAndGet();
  61.             lastFailureTime.set(Instant.now());
  62.    
  63.             if (failures >= failureThreshold) {
  64.                 state.set(State.OPEN);
  65.             } else if (state.get() == State.HALF_OPEN) {
  66.                 state.compareAndSet(State.HALF_OPEN, State.OPEN);
  67.             }
  68.         }
  69.    
  70.         public String getState() {
  71.             return state.get().name();
  72.         }
  73.     }
复制代码
3. Encoding & Decoding

    • Encoding & Decoding implementation

  1. import java.util.*;
  2.    
  3.     interface Run {
  4.         String encode();
  5.     }
  6.    
  7.     class RLERun implements Run {
  8.         int value;
  9.         int count;
  10.    
  11.         RLERun(int value, int count) {
  12.             this.value = value;
  13.             this.count = count;
  14.         }
  15.    
  16.         @Override
  17.         public String encode() {
  18.             return "RLE[" + value + ", " + count + "]";
  19.         }
  20.     }
  21.    
  22.     class BPRun implements Run {
  23.         List<Integer> values;
  24.    
  25.         BPRun(List<Integer> values) {
  26.             this.values = values;
  27.         }
  28.    
  29.         @Override
  30.         public String encode() {
  31.             return "BP" + values.toString();
  32.         }
  33.     }
  34.    
  35.     class Encoder {
  36.         public List<Run> encode(int[] input) {
  37.             List<Run> result = new ArrayList<>();
  38.             int i = 0;
  39.             while (i < input.length) {
  40.                 int j = i;
  41.                 while (j < input.length && input[j] == input[i]) {
  42.                     j++;
  43.                 }
  44.                 int count = j - i;
  45.                 if (count >= 8) {
  46.                     result.add(new RLERun(input[i], count));
  47.                     i = j;
  48.                 } else {
  49.                     int bpEnd = Math.min(input.length, i + 8);
  50.                     List<Integer> bpValues = new ArrayList<>();
  51.                     for (int k = i; k < bpEnd; k++) {
  52.                         bpValues.add(input[k]);
  53.                     }
  54.                     result.add(new BPRun(bpValues));
  55.                     i += bpValues.size();
  56.                 }
  57.             }
  58.             return result;
  59.         }
  60.     }
  61.    
  62.     class Decoder {
  63.         public List<Integer> decode(List<Run> runs) {
  64.             List<Integer> output = new ArrayList<>();
  65.             for (Run run : runs) {
  66.                 if (run instanceof RLERun) {
  67.                     RLERun rle = (RLERun) run;
  68.                     for (int i = 0; i < rle.count; i++) {
  69.                         output.add(rle.value);
  70.                     }
  71.                 } else if (run instanceof BPRun) {
  72.                     output.addAll(((BPRun) run).values);
  73.                 }
  74.             }
  75.             return output;
  76.         }
  77.     }
  78.    
  79.     class Main {
  80.         public static void main(String[] args) {
  81.             Encoder encoder = new Encoder();
  82.             Decoder decoder = new Decoder();
  83.    
  84.             int[] input = {1, 1, 1, 1, 1, 1, 1, 1, 2, 3, 4, 5};
  85.             List<Run> encoded = encoder.encode(input);
  86.             for (Run run : encoded) {
  87.                 System.out.println(run.encode());
  88.             }
  89.    
  90.             List<Integer> decoded = decoder.decode(encoded);
  91.             System.out.println("Decoded: " + decoded);
  92.         }
  93.     }
复制代码

评分

参与人数 42大米 +69 收起 理由
Character-Y + 1 很有用的信息!
financeFree + 3 很有用的信息!
微信用户_sm3sy + 1 GOOD
kidd-4 + 1 欢迎分享你知道的情况,会给更多积分奖励!
低调的橙 + 1 给你点个赞!

查看全部评分


上一篇:买它 店面
下一篇:买它 VO 挂经
地里匿名用户
推荐
匿名用户-X1J9Z  2025-9-18 05:03:57
LC 981,设计一个支持高效 get/put 和 query 的 KV store
    技术点:滑动窗口,TreeMap 或双端队列处理时间戳。
不是用binary search+map做就可以吗?是题号给错了吗
回复

使用道具 举报

地里匿名用户
推荐
匿名用户-IQ0OE  2025-8-29 11:13:10
哇, 这么好的帖子居然没人赞, 谢谢楼主, 祝楼主offer多多
回复

使用道具 举报

全局:
algorithm 一小时大概做几道题呢 谢谢!
回复

使用道具 举报

🔗
bostenkg5 2025-9-9 04:22:57 | 只看该作者
全局:
谢谢楼主, 祝楼主offer多多!!
回复

使用道具 举报

🔗
祈福香菇 2026-3-22 17:04:12 | 只看该作者
全局:
楼主可以说下,防火墙那道题的follow up要实现吗?我感觉写不完啊
回复

使用道具 举报

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

本版积分规则

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