Weekly #11

@Date : 2019-06-10 09:11:00

@Author : Lewis Tian (taseikyo@gmail.com)

@Link : https://taseikyo.github.io

@Range : 2019/06/10 - 2019/06/16

Weekly #11 Photo by Pavel Brodsky on Unsplash

Table of Contents

algorithm

347. Top K Frequent Elements

Medium

Given a non-empty array of integers, return the k most frequent elements.

Example 1:

Input: nums = [1,1,1,2,2,3], k = 2
Output: [1,2]
Example 2:

Input: nums = [1], k = 1
Output: [1]

Note:

  • You may assume k is always valid, 1 ≤ k ≤ number of unique elements.
  • Your algorithm's time complexity must be better than O(n log n), where n is the array's size.

solution

I think using Python is just cheating. Just one linehttps://github.com/taseikyo/arts/blob/master.

def topKFrequent(self, nums: List[int], k: int) -> List[int]:
    return [key for key, value in Counter(nums).most_common(k)]

448. Find All Numbers Disappeared in an Array

Easy

Given an array of integers where 1 ≤ a[i] ≤ n (n = size of array), some elements appear twice and others appear once.

Find all the elements of [1, n] inclusive that do not appear in this array.

Could you do it without extra space and in O(n) runtime? You may assume the returned list does not count as extra space.

Example:

Input:
[4,3,2,7,8,2,3,1]

Output:
[5,6]

solution

One line Python cheating

def findDisappearedNumbers(self, nums: List[int]) -> List[int]:
        return list((set(range(1, len(nums) + 1))) - (set(nums)))

538. Convert BST to Greater Tree

Easy

Given a Binary Search Tree (BST), convert it to a Greater Tree such that every key of the original BST is changed to the original key plus sum of all keys greater than the original key in BST.

Example:

Input: The root of a Binary Search Tree like this:
              5
            /   \
           2     13

Output: The root of a Greater Tree like this:
             18
            /   \
          20     13

solution

preorder (right child node first) traversal

review

This article describes several paging mechanisms in x86 and x64.

tip

share

  • A Virtual Machine Introspection Triggering Mechanism Based on VMFUNC

I found this paper when I googled VMFUNC keyword.

This paper proposes a VMFUNC based VM introspection mechanism, which avoids the system pause and minimizes the overhead of VM exits.

results matching ""

    No results matching ""