回复: 5
跳转到指定楼层
上一主题 下一主题
收起左侧

stripe 总结8题

   
🔗
匿名用户-DRXYT  2021-10-16 03:26:58 |倒序浏览

2021(10-12月) 码农类General 硕士 全职@stripe - 实习ReturnOffer - 技术电面  | 😐 Neutral 😐 Average | Other | 在职跳槽

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

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

x
本帖最后由 匿名 于 2021-10-15 12:36 编辑

manager reaches out 2 周前,🈷️了一个call,然后说 给我一个 link。让我apply for that position然后 让我提供面试时间, 再然后就没再然后了
非常恼火
准备
您好!
本帖隐藏的内容需要积分高于 188 才可浏览
您当前积分为 0。
使用VIP即刻解锁阅读权限或查看其他获取积分的方式
游客,您好!
本帖隐藏的内容需要积分高于 188 才可浏览
您当前积分为 0。
VIP即刻解锁阅读权限查看其他获取积分的方式
Unlock interview details and practice with AI
Curated Interview Questions from Top Companies
E_4        ]6.  http header

  1. import java.util.ArrayList;
  2. import java.util.Arrays;
  3. import java.util.List;

  4. public class HttpHeader {
  5.   public static List<String> parseAcceptLanguage(String required, List<String> supported) {
  6.     List<String> r = new ArrayList<String>();
  7.     if (required == null || supported == null) return r;
  8.     List<String> list = new ArrayList<>(supported);

  9.     String[] ls = required.split(",\\s+");
  10.     for (String l : ls) {
  11.       if (l.length() == 5) {
  12.         if (list.contains(l)) {
  13.           r.add(l);
  14.           list.remove(l);
  15.         }
  16.       } else if (l.length() == 2) {
  17.         List<String> matchs = new ArrayList<>();
  18.         for (String s : list) {
  19.           if (s.startsWith(l)) {
  20.             matchs.add(s);
  21.           }
  22.         }
  23.         for (String s : matchs) {
  24.           r.add(s);
  25.           list.remove(s);
  26.         }
  27.       } else if (l.equals("*")) {
  28.         for (String left : list) {
  29.           r.add(left);
  30.         }
  31.       } else {
  32.         throw new RuntimeException("not supported tag");
  33.       }
  34.     }
  35.     return r;
  36.   }

  37.   public static void main(String[] args) {
  38.     System.out.println(
  39.         parseAcceptLanguage("en-US, fr-CA, fr-FR", Arrays.asList("fr-FR", "en-US"))
  40.             .toString()
  41.             .equals("[en-US, fr-FR]"));
  42.     System.out.println(
  43.         parseAcceptLanguage("fr-CA, fr-FR", Arrays.asList("en-US", "fr-FR"))
  44.             .toString()
  45.             .equals("[fr-FR]"));
  46.     System.out.println(
  47.         parseAcceptLanguage("en-US", Arrays.asList("en-US", "fr-CA")).toString().equals("[en-US]"));
  48.     // part 2
  49.     System.out.println(
  50.         parseAcceptLanguage("en", Arrays.asList("en-US", "fr-CA", "fr-FR"))
  51.             .toString()
  52.             .equals("[en-US]"));
  53.     System.out.println(
  54.         parseAcceptLanguage("fr", Arrays.asList("en-US", "fr-CA", "fr-FR"))
  55.             .toString()
  56.             .equals("[fr-CA, fr-FR]"));

  57.     System.out.println(
  58.         parseAcceptLanguage("fr-FR, fr", Arrays.asList("en-US", "fr-CA", "fr-FR"))
  59.             .toString()
  60.             .equals("[fr-FR, fr-CA]"));
  61.     // part 3
  62.     System.out.println(
  63.         parseAcceptLanguage("en-US, *", Arrays.asList("en-US", "fr-CA", "fr-FR"))
  64.             .toString()
  65.             .equals("[en-US, fr-CA, fr-FR]"));

  66.     System.out.println(
  67.         parseAcceptLanguage("fr-FR, fr, *", Arrays.asList("en-US", "fr-CA", "fr-FR"))
  68.             .toString()
  69.             .equals("[fr-FR, fr-CA, en-US]"));
  70.   }
  71. }
复制代码
7 stripe inbox

  1. import java.math.BigDecimal;
  2. import java.math.RoundingMode;
  3. import java.util.*;

  4. public class Stripe {
  5.   /*
  6.   Question comes from https://www.1point3acres.com/bbs/thread-668514-1-1.html

  7.   4 actions
  8.     - 1 CHARGE, customer-> merchant
  9.       2 CONFIRM <-mutually exclusive->REFUND,


  10.       CHARGE->CONFIRM: approved. no refund
  11.       CHARGE->REFUND, no confirm
  12.       3 REFUND: refunded charge's amount should not be included
  13.         in the payout balance. but the card network processing fee
  14.         should be deduced from the payout balance. strip processing
  15.         fee not be deduced in this case

  16.       4 PAYOUT:  stripe-> merchant.
  17.                 up until that point of receiving the action
  18.                 print the merchant's balance from beginning
  19.                 or the previous payout action if any
  20.                 then merchant payout balance is reset to 0

  21.                 include only confirmed charges
  22.                 after deducing card network and stripe
  23.                 processing fee
  24.                 Strip has a fixed processing fee of 2%.


  25.      Input Format
  26.      N
  27.      CARD_NETWORK<space>PERCENT
  28.      no duplicated entries for the same card network

  29.      M
  30.      actions

  31.    Constrains
  32.      2<=N<=5 (Integer)
  33.      0<=M<=100(Integer)
  34.      0.1<=PERCENT<=10.0 (Float)
  35.      CARD_NETWORK (String)

  36.    Actions:
  37.      /charge?network=<CARD_NETWORK>&amount=<AMOUNT>&merchant_id=<MERCHANT_ID>&charge_id=<CHARGE_ID>

  38.      network: credit card String
  39.      amount: 0<=AMOUNT<=4,294,967,295 Integer
  40.      merchant_id: String
  41.      charge_id:String

  42.      /payout?merchant_id=<MERCHANT_ID>

  43.      /confirm?charge_id=<CHARGE_ID>
  44.      /refund?charge_id=<CHARGE_ID>

  45.   Comments on the input
  46.      - All actions are well-formed URLs. need not verifying
  47.      the ordering of query parameters could change
  48.      - charge_id is unique
  49.      - input action are properly ordered. refund or confirm will not
  50.        occur before the charge action itself
  51.      - charge action only use the card network whose processing fee
  52.        percentage is specified in the input

  53.   Output
  54.      for each payout action in the input

  55.       merchant ID, payout balance.
  56.       rounded *up* to the nearest whole number integer
  57.       do not round the numbers after each action. Only the final
  58.       number to be printed


  59.    Example
  60.       2
  61.       visa 2.0
  62.       mastercard 3.0
  63.       3
  64.       /charge?network=visa&amount=100&merchant_id=m001&charge_id=c001
  65.       /confirm?charge_id=c001
  66.       /payout?merchant_id=m001

  67.       output
  68.       m001, 96
  69.       Stripe precessing fee is fixed 2%

  70.       --------
  71.       2
  72.       visa 2.0
  73.       mastercard 3.0
  74.       5
  75.       /charge?network=visa&amount=100&merchant_id=m001&charge_id=c001
  76.       /charge?merchant_id=m001&amount=56network=mastercard&charge_id=c002
  77.       /refund?charge_id=c001
  78.       /confirm?charge_id=c002
  79.       /payout?merchant_id=m001

  80.       output
  81.       m001, 52
  82.       Stripe precessing fee is fixed 2%
  83.       for c001: refund,
  84.                 but need pay visa fee
  85.                 -0.02*100=-2
  86.       for c002: confirmed
  87.                 +56*(1-0.03+0.02)=53.2
  88.       So left   51.2
  89.       round_up(51.2)=52


  90.      --------
  91.       2
  92.       visa 2.0
  93.       mastercard 3.0
  94.       8
  95.       /charge?merchant_id=m001&charge_id=c001&amount=1000&network=visa
  96.       /charge?merchant_id=m001&charge_id=c002&amount=1000&network=mastercard
  97.       /confirm?charge_id=c001
  98.       /confirm?charge_id=c002
  99.       /payout?merchant_id=m001

  100.       /charge?merchant_id=m001&charge_id=c003&amount=1000&network=visa
  101.       /confirm?charge_id=c003
  102.       /payout?merchant_id=m001

  103.       output
  104.        m001, 1910
  105.        m001, 960

  106.      Explain
  107.        +1000-20-20
  108.        +1000-20-30
  109.        total 1910

  110.        +1000-20-20
  111.        total 960

  112.      Followup
  113.      merchant has so many refund
  114.      so that the balance is negative, how to handle it???
  115.    */

  116.   public void processActions(List<String> lines) {
  117.     int i = 1;
  118.     for (; i <= Integer.valueOf(lines.get(0)); i++) {
  119.       String[] kv = lines.get(i).split(" ");
  120.       fee.put(kv[0], Float.valueOf(kv[1]));
  121.     }
  122.     i++;
  123.     for (; i < lines.size(); i++) {
  124.       parse(lines.get(i));
  125.     }
  126.   }

  127.   private void parse(String action) {
  128.     String[] a = action.split("\\?");
  129.     String[] ps = a[1].split("&");
  130.     Map<String, String> map = new HashMap<>();
  131.     for (String p : ps) {
  132.       String[] kv = p.split("=");
  133.       map.put(kv[0], kv[1]);
  134.     }

  135.     String k = a[0].substring(1);
  136.     switch (k) {
  137.       case "charge":
  138.         charge(map.get("merchant_id"), map.get("charge_id"), map.get("network"), map.get("amount"));
  139.         break;
  140.       case "refund":
  141.         refund(map.get("charge_id"));
  142.         break;
  143.       case "confirm":
  144.         confirm(map.get("charge_id"));
  145.         break;
  146.       case "payout":
  147.         payout(map.get("merchant_id"));
  148.         break;
  149.       default:
  150.     }
  151.   }

  152.   private static float stripFee = 2.0f;
  153.   private Map<String, Float> fee;

  154.   private Map<String, BigDecimal> payout;

  155.   private Map<String, String> chargeOf;
  156.   private Map<String, String> charges;
  157.   private Map<String, String> chargeCard;

  158.   public Stripe() {
  159.     fee = new HashMap<>();

  160.     payout = new HashMap<>();
  161.     chargeOf = new HashMap<>();
  162.     charges = new HashMap<>();
  163.     chargeCard = new HashMap<>();
  164.   }

  165.   private void charge(String merchat_id, String charge_id, String network, String amount) {
  166.     chargeOf.put(charge_id, merchat_id);
  167.     chargeCard.put(charge_id, network);
  168.     charges.put(charge_id, amount);
  169.   }

  170.   private void refund(String chargeId) {
  171.     String merchant = chargeOf.get(chargeId);
  172.     payout.putIfAbsent(merchant, BigDecimal.ZERO);
  173.     BigDecimal balance = payout.get(merchant);
  174.     // what happened if the fist charge is refunded and no money in merchant payout balance

  175.     BigDecimal charge = new BigDecimal(charges.get(chargeId));
  176.     BigDecimal rate = BigDecimal.valueOf(fee.get(chargeCard.get(chargeId)));
  177.     BigDecimal reduce = charge.multiply(rate).divide(BigDecimal.valueOf(100.00));
  178.     payout.put(merchant, balance.subtract(reduce));
  179.     // charges.remove(chargeId);
  180.   }

  181.   private void confirm(String chargeId) {
  182.     String id = chargeId;
  183.     String m = chargeOf.get(id);
  184.     payout.putIfAbsent(m, BigDecimal.ZERO);
  185.     BigDecimal b = payout.get(m);

  186.     // what happened if the fist charge is refunded and no money in merchant payout balance
  187.     BigDecimal charge = new BigDecimal(charges.get(id));
  188.     BigDecimal rates =
  189.         BigDecimal.valueOf(fee.get(chargeCard.get(id))).add(BigDecimal.valueOf(stripFee));
  190.     BigDecimal reduce = charge.multiply(rates).divide(BigDecimal.valueOf(100.00));
  191.     payout.put(m, b.add(charge.subtract(reduce)));

  192.     //  charges.remove(chargeId);
  193.   }

  194.   private void payout(String merchant) {
  195.     String m = merchant;
  196.     payout.putIfAbsent(m, BigDecimal.ZERO);
  197.     System.out.println(m + " " + payout.get(m).setScale(0, RoundingMode.CEILING));
  198.     payout.put(m, BigDecimal.ZERO);
  199.   }

  200.   public static void main(String[] args) {
  201.     List<String> lines = new LinkedList<>();
  202.     lines.add("2");
  203.     lines.add("visa 2.0");
  204.     lines.add("mastercard 3.0");
  205.     lines.add("3");
  206.     lines.add("/charge?network=visa&amount=100&merchant_id=m001&charge_id=c001");
  207.     lines.add("/confirm?charge_id=c001");
  208.     lines.add("/payout?merchant_id=m001");
  209.     Stripe t = new Stripe();
  210.     t.processActions(lines);

  211.     // m001, 96
  212.     lines = new LinkedList<>();
  213.     lines.add("2");
  214.     lines.add("visa 2.0");
  215.     lines.add("mastercard 3.0");
  216.     lines.add("5");
  217.     lines.add("/charge?network=visa&amount=100&merchant_id=m001&charge_id=c001");
  218.     lines.add("/charge?merchant_id=m001&amount=56&network=mastercard&charge_id=c002");
  219.     lines.add("/refund?charge_id=c001");
  220.     lines.add("/confirm?charge_id=c002");
  221.     lines.add("/payout?merchant_id=m001");
  222.     t = new Stripe();
  223.     t.processActions(lines);

  224.     // m001, 52
  225.     lines = new LinkedList<>();
  226.     lines.add("2");
  227.     lines.add("visa 2.0");
  228.     lines.add("mastercard 3.0");
  229.     lines.add("8");
  230.     lines.add("/charge?merchant_id=m001&charge_id=c001&amount=1000&network=visa");
  231.     lines.add("/charge?merchant_id=m001&charge_id=c002&amount=1000&network=mastercard");
  232.     lines.add("/confirm?charge_id=c001");
  233.     lines.add("/confirm?charge_id=c002");
  234.     lines.add("/payout?merchant_id=m001");

  235.     lines.add("/charge?merchant_id=m001&charge_id=c003&amount=1000&network=visa");
  236.     lines.add("/confirm?charge_id=c003");
  237.     lines.add("/payout?merchant_id=m001");
  238.     t = new Stripe();
  239.     t.processActions(lines);

  240.     // m001, 1910
  241.     // m001, 960
  242.   }
  243. }
复制代码
8 compress

  1. package string;

  2. public class Numeronym {
  3.   /*
  4.   Question comes from https://www.1point3acres.com/bbs/thread-800813-1-1.html

  5.   Not clear what is the meaing of the `m`.
  6.   Just assume `m` means at most keep m minors for each major,
  7.   when there are more than `m` minors in a major,
  8.   the first m-1 one are handled as usual,
  9.   but left minors [mth,last] will be merged as the m-th one

  10.   Java:
  11.     String.split("\\."); // when it is . need escape
  12.    */
  13.   public static String compress(String input, int m) {
  14.     StringBuilder r = new StringBuilder();
  15.     // assume input is valid, else need validation in advance
  16.     String[] majs = input.split("/");
  17.     for (int i = 0; i < majs.length; i++) {
  18.       String maj = majs[i];
  19.       String[] mins = maj.split("\\.");
  20.       int j = 0;
  21.       int sum = 0;
  22.       for (; j < Math.min(m - 1, mins.length); j++) {
  23.         String min = mins[j];
  24.         sum += min.length();
  25.         r.append(min.charAt(0));
  26.         r.append(min.length() - 2);
  27.         r.append(min.charAt(min.length() - 1));
  28.         if (j != mins.length - 1) r.append(".");
  29.       }
  30.       if (j < mins.length) {
  31.         r.append(maj.charAt(sum));
  32.         sum = 0;
  33.         for (; j < mins.length; j++) sum += mins[j].length();
  34.         r.append(sum - 2);
  35.         r.append(maj.charAt(maj.length() - 1));
  36.       }
  37.       if (i != majs.length - 1) r.append("/");
  38.     }
  39.     return r.toString();
  40.   }

  41.   public static void main(String args[]) {
  42.     System.out.println(
  43.         compress("stripe.com/checkout/payments/customer.maria.bay.area.next.job", 3)
  44.             .equals("s4e.c1m/c6t/p6s/c6r.m3a.a12b"));
  45.   }
  46. }
复制代码

评分

参与人数 36大米 +56 收起 理由
JK2018 + 1 给你点个赞!
花三岁 + 1 很有用的信息!
aquafilet08 + 1 给你点个赞!
frandblinkc + 1 很有用的信息!
morrisc1102 + 1 很有用的信息!

查看全部评分


上一篇:Cisco 2022 SWE Summer Intern OA
下一篇:imc quant trader online video interview
推荐
Chacaj 2021-10-18 11:58:44 | 只看该作者
全局:
感謝分享,雖然不用 java 但是很有用
回复

使用道具 举报

🔗
jifengyzh 2021-11-2 10:55:54 | 只看该作者
全局:
感谢分享
回复

使用道具 举报

🔗
111180611 2021-12-3 15:16:19 | 只看该作者
全局:
感谢分享
回复

使用道具 举报

地里匿名用户
🔗
匿名用户-WRLTB  2023-9-15 00:43:51
好人一生平安
回复

使用道具 举报

🔗
Pepper10 2024-1-16 13:47:48 | 只看该作者
全局:
Thank you for sharing
回复

使用道具 举报

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

本版积分规则

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