Advertisement
nirajs

microsoft

Feb 1st, 2024
559
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Python 2.91 KB | None | 0 0
  1. # you can write to stdout for debugging purposes, e.g.]
  2. """
  3.  
  4. // [1,2,1,3,2,1,9,6,2,1,9], k = 2
  5. print("This is a debug message")
  6.  
  7. key -> value
  8. value -> key
  9.  
  10.  
  11. 1 -> 2
  12. 2 -> 1
  13.  
  14. Space
  15.    Linear
  16.  
  17. Time
  18.  
  19.    input n, k
  20.    n + logn *k
  21.    k = 4
  22.  
  23.    n + logn*3
  24.  
  25.  
  26.    (n) + log(n) *k => nlogn (k ~ n)
  27.  
  28.  
  29.  
  30. freqMap (key) => count
  31. firstIndexMap (key) => first occurence
  32.  
  33.  
  34. maxHeap (count, firstoccurence, ele) => top K
  35.  
  36. 1,9,9,1,1,1,1,2,2,2,2,2,2, k =1
  37.  
  38. maxHeap
  39.  
  40. 9,2
  41. 1  2
  42.  
  43. heap
  44.    top
  45.    peek()
  46.    add()
  47.  
  48.  
  49. """
  50.  
  51. from collections import defaultdict
  52. import heapq
  53.  
  54.  
  55. class solution
  56.  
  57. def getKthMostCommon(nums, k: int) -> list[int]:
  58.     freqMap = defaultdict(int)
  59.     indexMap = defaultdict(int)
  60.     for index, ele in enumerate(nums):
  61.         freqMap[ele] += 1
  62.         if ele not in indexMap:
  63.             indexMap[ele] = index
  64.  
  65.     # count, index, ele
  66.     arr = []
  67.     for key in freqMap:
  68.         arr.append((-freqMap[key], -indexMap[key], key))
  69.  
  70.     heapq.heapify(arr)
  71.  
  72.     result = []
  73.  
  74.     for _ in range(k):
  75.         freq, index, key = heapq.heappop(arr)
  76.         result.append(key)
  77.  
  78.     return result
  79.  
  80.  
  81. nums = [1,2,1,3,2,1,9,6,2,1,9]
  82. k = 2
  83. print(getKthMostCommon(nums,k))
  84.  
  85.  
  86. """
  87.  
  88. Design Leetcode for your collage
  89.  
  90. 3rd year students would be using.
  91.  
  92. Admin -> add question
  93. Student -> use
  94.  
  95. dashboard -> leaderboard.
  96.  
  97.  
  98. Admin
  99. User
  100.  
  101. Functionality (core Feture)
  102.    
  103.    User
  104.        - User can submit a question
  105.        - User can see the response of a question
  106.        - user can explore the catalgoue
  107.    
  108.    Admin
  109.        - Update the catagloue
  110.        - Add new question, testcases (meta data )
  111.        -
  112.  
  113.  
  114.    System
  115.        - Support multiple language (C++, python)
  116.        - Online editor, auto complettion
  117.  
  118.  
  119.    configuration (intput) -> config
  120.    input
  121.        language
  122.        problem ID
  123.  
  124.    =>
  125.        dockerTemplate
  126.            gcc contemnt.cpp
  127.            python3 a.app
  128.        inputfiles
  129.        outfiles
  130.  
  131.        python
  132.         obj = solution()
  133.         solution.kthlarges()
  134.        
  135.  
  136.        block some of executation.
  137.        ex python
  138.        contiainer
  139.            virtualization
  140.  
  141.    Leaderboard:
  142.        userId
  143.            how many question solved ->
  144.            Top K score of all userbase over some time period
  145.  
  146.    
  147.  
  148.    User
  149.        - UserId,
  150.        - Profile
  151.        -
  152.    
  153.    UserQuestionStatus:
  154.        UserId
  155.        questionId:
  156.        status:
  157.  
  158.  
  159.    question:
  160.  
  161.    ScoreTable:
  162.        - User
  163.        - Score
  164.        -
  165.  
  166.    Cache
  167.        UserId -> Score1
  168.        SUserId -> Score2
  169.  
  170.  
  171.        TopK: [UserId: score1, userId: score2] // BST OrderSet logn
  172.    
  173.  
  174.  
  175.    
  176.    
  177.  
  178. Non functional:
  179.    - Security aspects (sandboxing )
  180.    - Scable
  181.    - Fast low latency (xx ms )
  182.    - Observability
  183.  
  184.  
  185.  
  186. Rate Limiter
  187.  
  188.  
  189.  
  190.  
  191.  
  192.  
  193.  
  194.  
  195.  
  196.  
  197.  
  198.  
  199.  
  200.  
  201.  
  202. """
  203.  
  204.  
  205.  
  206.  
  207.  
  208.  
  209.  
  210.  
  211.  
  212.  
  213.  
  214.  
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement