亚_麻_OA2

  1. 找出句子里面最多but not in the word to exclude list
    https://leetcode.com/problems/most-common-word/

  2. count number of substrings with exactly k distinct characters
    一道是用滑动窗口求包含K个distinct字符的子串数目
    https://blog.csdn.net/roufoo/article/details/84934364
    12个test case, 最后一个test case是当k为0时的输出

  3. reOrder log files

  4. find subtree with maximum average node
    https://yeqiuquan.blogspot.com/2017/03/lintcode-597-subtree-with-maximum.html

  5. Highest 5
    highest five, 背景知识是有一堆productID 和product的reviews, 给每一个productID找出最高的五个review的平均值,用priorityqueue做就可以,注意data type是double
    highest five reviews,给一个Map储存的是id和其对应的review score,返回一个Map, key是id,value是相对应的5个最高评分的平均数
    https://yeqiuquan.blogspot.com/2017/03/lintcode-613-high-five.html
    lintcod 第613题类似,区别是amazon的score是double,lintcode是int,注意下就好

  6. find substrings of size k with k-1 distinct characters
    input是inputString和num,output是所有长为num且distinct character为num - 1的subString的list


public List<String> subStringWithKDistinct(String s, int k) {
        Map<Character, Integer> map = new HashMap<>();
        List<String> result = new ArrayList<>();
        int n = s.length();
        if( n * k == 0) {
            return 0;
        } 
        
        int left = 0, right = 0;
        
        while(right < n) {
            map.put(s.charAt(right), right++);
            
            if(map.size() == k) {
                if(right - left == k + 1) {
                    result.add(s.substring(left,right));
                }
            }
            
            if(map.size() > k) {
                int del_idx = Collections.min(map.values());
                map.remove(s.charAt(del_idx));
                left = del_idx + 1;
            }
        }
        
        return result;
        
    }
  1. 有一排数据中心,求最小的cost把所有的数据中心连起来 (MST)
  2. K closest points to origin.
    https://leetcode.com/problems/k-closest-points-to-origin/
  3. 给一个字符串和一个整数k,问有多少个substring有k个distinct character。仔细读题,题目要求的是重复的substring也可以满足要求
    https://leetcode.com/problems/longest-substring-with-at-most-k-distinct-characters/
    https://www.geeksforgeeks.org/count-number-of-substrings-with-exactly-k-distinct-characters/

小土刀

  1. Right Rotation

  2. Grey code

  3. 去元音 remove vowel

  4. 检验括号

  5. longest palindromic substring
    https://leetcode.com/problems/longest-palindromic-substring/

  6. merge two sorted linkedlist

  7. reverse second half of linked list

  8. Subtree

  9. Two Sum

  10. Find K Nearest Point

  11. Overlap Rectangle
    给两个长方形的topLeft和bottomRight坐标, 判断这两个长方形是否重叠
    Rectangle Overlap。这题和leetcode 算相交面积的区别:它帮你定义好两个类,一个叫Point,一个叫Rectangle,Rectangle包括左上右下两个Point, Point包括x, y的值, 这种细节并不影响程序,总之一句判断直接通过了全部20多个case.

  12. window sum

  13. GCD Greatest Common Divisor

  14. LRU Cache count miss

  15. Round Robin

  16. Rotate Matrix

  17. insert into cycle linked list

  18. Loop in linked list

  19. Shorted job first
    一个处理器要处理一堆request,一次只能处理一条,如果它有几个积压着的requests,它会先执行持续时间短的那个;对于持续时间相等的requests,先执行最早到达处理器的request。问平均每个request要等多久才能被处理。input:requestTimes[],每个request到达处理器的时间; durations[] 每个request要处理的持续时间。 两个数组是一一对应的,并已按requestTimes[] 从小到大排序过

  20. Binary search tree minimum sum from root to leaf

  21. Day change(cell growth)
    https://leetcode.com/problems/prison-cells-after-n-days/

  22. Maze
    https://leetcode.com/problems/the-maze/

to 9

public int shortestDistance(int[][] maze, int[] start, int[] dest) {
        int[][] distance = new int[maze.length][maze[0].length];
        for (int[] row: distance)
            Arrays.fill(row, Integer.MAX_VALUE);
        distance[start[0]][start[1]] = 0;
         int[][] dirs={{0, 1} ,{0, -1}, {-1, 0}, {1, 0}};
        Queue < int[] > queue = new LinkedList < > ();
        queue.add(start);
        while (!queue.isEmpty()) {
            int[] s = queue.remove();
            for (int[] dir: dirs) {
                int x = s[0] + dir[0];
                int y = s[1] + dir[1];
                int count = 0;
                while (x >= 0 && y >= 0 && x < maze.length && y < maze[0].length && maze[x][y] == 0) {
                    x += dir[0];
                    y += dir[1];
                    count++;
                }
                if (distance[s[0]][s[1]] + count < distance[x - dir[0]][y - dir[1]]) {
                    distance[x - dir[0]][y - dir[1]] = distance[s[0]][s[1]] + count;
                    queue.add(new int[] {x - dir[0], y - dir[1]});
                }
            }
        }
        return distance[dest[0]][dest[1]] == Integer.MAX_VALUE ? -1 : distance[dest[0]][dest[1]];
    }

  1. Minimum Path Sum 窗口内最小
  2. Four Integer 四个数字 差的绝对值最大
  3. Arithmetic sequence
    https://leetcode.com/problems/arithmetic-slices/
  4. Tree Amplitude
    Given a tree of N nodes, return the amplitude of the tree
    就是从 root 到 leaf max - min 的差
  5. Maximum Minimum Path
    给一个int[][]的matirx,对于一条从左上到右下的path pi,pi中的最小值是mi,求所有mi中的最大值。只能往下或右.
  6. Search in 2D matrix
  7. two close capacity
©著作权归作者所有,转载或内容合作请联系作者
  • 序言:七十年代末,一起剥皮案震惊了整个滨河市,随后出现的几起案子,更是在滨河造成了极大的恐慌,老刑警刘岩,带你破解...
    沈念sama阅读 195,980评论 5 462
  • 序言:滨河连续发生了三起死亡事件,死亡现场离奇诡异,居然都是意外死亡,警方通过查阅死者的电脑和手机,发现死者居然都...
    沈念sama阅读 82,422评论 2 373
  • 文/潘晓璐 我一进店门,熙熙楼的掌柜王于贵愁眉苦脸地迎上来,“玉大人,你说我怎么就摊上这事。” “怎么了?”我有些...
    开封第一讲书人阅读 143,130评论 0 325
  • 文/不坏的土叔 我叫张陵,是天一观的道长。 经常有香客问我,道长,这世上最难降的妖魔是什么? 我笑而不...
    开封第一讲书人阅读 52,553评论 1 267
  • 正文 为了忘掉前任,我火速办了婚礼,结果婚礼上,老公的妹妹穿的比我还像新娘。我一直安慰自己,他们只是感情好,可当我...
    茶点故事阅读 61,408评论 5 358
  • 文/花漫 我一把揭开白布。 她就那样静静地躺着,像睡着了一般。 火红的嫁衣衬着肌肤如雪。 梳的纹丝不乱的头发上,一...
    开封第一讲书人阅读 46,326评论 1 273
  • 那天,我揣着相机与录音,去河边找鬼。 笑死,一个胖子当着我的面吹牛,可吹牛的内容都是我干的。 我是一名探鬼主播,决...
    沈念sama阅读 36,720评论 3 386
  • 文/苍兰香墨 我猛地睁开眼,长吁一口气:“原来是场噩梦啊……” “哼!你这毒妇竟也来了?” 一声冷哼从身侧响起,我...
    开封第一讲书人阅读 35,373评论 0 254
  • 序言:老挝万荣一对情侣失踪,失踪者是张志新(化名)和其女友刘颖,没想到半个月后,有当地人在树林里发现了一具尸体,经...
    沈念sama阅读 39,678评论 1 294
  • 正文 独居荒郊野岭守林人离奇死亡,尸身上长有42处带血的脓包…… 初始之章·张勋 以下内容为张勋视角 年9月15日...
    茶点故事阅读 34,722评论 2 312
  • 正文 我和宋清朗相恋三年,在试婚纱的时候发现自己被绿了。 大学时的朋友给我发了我未婚夫和他白月光在一起吃饭的照片。...
    茶点故事阅读 36,486评论 1 326
  • 序言:一个原本活蹦乱跳的男人离奇死亡,死状恐怖,灵堂内的尸体忽然破棺而出,到底是诈尸还是另有隐情,我是刑警宁泽,带...
    沈念sama阅读 32,335评论 3 313
  • 正文 年R本政府宣布,位于F岛的核电站,受9级特大地震影响,放射性物质发生泄漏。R本人自食恶果不足惜,却给世界环境...
    茶点故事阅读 37,738评论 3 299
  • 文/蒙蒙 一、第九天 我趴在偏房一处隐蔽的房顶上张望。 院中可真热闹,春花似锦、人声如沸。这庄子的主人今日做“春日...
    开封第一讲书人阅读 29,009评论 0 19
  • 文/苍兰香墨 我抬头看了看天上的太阳。三九已至,却和暖如春,着一层夹袄步出监牢的瞬间,已是汗流浃背。 一阵脚步声响...
    开封第一讲书人阅读 30,283评论 1 251
  • 我被黑心中介骗来泰国打工, 没想到刚下飞机就差点儿被人妖公主榨干…… 1. 我叫王不留,地道东北人。 一个月前我还...
    沈念sama阅读 41,692评论 2 342
  • 正文 我出身青楼,却偏偏与公主长得像,于是被迫代替她去往敌国和亲。 传闻我的和亲对象是个残疾皇子,可洞房花烛夜当晚...
    茶点故事阅读 40,893评论 2 335

推荐阅读更多精彩内容