亚_麻_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
©著作权归作者所有,转载或内容合作请联系作者
【社区内容提示】社区部分内容疑似由AI辅助生成,浏览时请结合常识与多方信息审慎甄别。
平台声明:文章内容(如有图片或视频亦包括在内)由作者上传并发布,文章内容仅代表作者本人观点,简书系信息发布平台,仅提供信息存储服务。

相关阅读更多精彩内容

友情链接更多精彩内容