Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- # you can write to stdout for debugging purposes, e.g.]
- """
- // [1,2,1,3,2,1,9,6,2,1,9], k = 2
- print("This is a debug message")
- key -> value
- value -> key
- 1 -> 2
- 2 -> 1
- Space
- Linear
- Time
- input n, k
- n + logn *k
- k = 4
- n + logn*3
- (n) + log(n) *k => nlogn (k ~ n)
- freqMap (key) => count
- firstIndexMap (key) => first occurence
- maxHeap (count, firstoccurence, ele) => top K
- 1,9,9,1,1,1,1,2,2,2,2,2,2, k =1
- maxHeap
- 9,2
- 1 2
- heap
- top
- peek()
- add()
- """
- from collections import defaultdict
- import heapq
- class solution
- def getKthMostCommon(nums, k: int) -> list[int]:
- freqMap = defaultdict(int)
- indexMap = defaultdict(int)
- for index, ele in enumerate(nums):
- freqMap[ele] += 1
- if ele not in indexMap:
- indexMap[ele] = index
- # count, index, ele
- arr = []
- for key in freqMap:
- arr.append((-freqMap[key], -indexMap[key], key))
- heapq.heapify(arr)
- result = []
- for _ in range(k):
- freq, index, key = heapq.heappop(arr)
- result.append(key)
- return result
- nums = [1,2,1,3,2,1,9,6,2,1,9]
- k = 2
- print(getKthMostCommon(nums,k))
- """
- Design Leetcode for your collage
- 3rd year students would be using.
- Admin -> add question
- Student -> use
- dashboard -> leaderboard.
- Admin
- User
- Functionality (core Feture)
- User
- - User can submit a question
- - User can see the response of a question
- - user can explore the catalgoue
- Admin
- - Update the catagloue
- - Add new question, testcases (meta data )
- -
- System
- - Support multiple language (C++, python)
- - Online editor, auto complettion
- configuration (intput) -> config
- input
- language
- problem ID
- =>
- dockerTemplate
- gcc contemnt.cpp
- python3 a.app
- inputfiles
- outfiles
- python
- obj = solution()
- solution.kthlarges()
- block some of executation.
- ex python
- contiainer
- virtualization
- Leaderboard:
- userId
- how many question solved ->
- Top K score of all userbase over some time period
- User
- - UserId,
- - Profile
- -
- UserQuestionStatus:
- UserId
- questionId:
- status:
- question:
- ScoreTable:
- - User
- - Score
- -
- Cache
- UserId -> Score1
- SUserId -> Score2
- TopK: [UserId: score1, userId: score2] // BST OrderSet logn
- Non functional:
- - Security aspects (sandboxing )
- - Scable
- - Fast low latency (xx ms )
- - Observability
- Rate Limiter
- """
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement