Oracle Bangalore
Please upvote if you like to reach article to wider audience.
list<timestamp, service>
2pm 2.30 2.45 3 3.01
s1 s2 s3 s2 s3
[2,s1] -> [2.30,s2] -> [2.45,s3] -> [3,s2] -> [3.01,s3]
/\
Purge timerInput Dictionary: {"rat", "cat", "bus", "art", "tar", "usb"}
Output:
rat,2 //rat,art,tar are anagrams but we output 2 since present word is not counted
cat,0 //cat does not have anagram in dictionary
bus,1 //bus,usb are anagramsinput: {"rat", "cat", "bus", "art", "tar"}
sorted: {"art", "act", "bsu", "art", "art"}
map:
art,3 | act,1 | bsu,1input: {"rat", "cat", "bus", "art", "tar"}
word: rat => art, search art in map, if found push count on vector
<(rat,2)
word: cat => act, search act in map, if found push count on vector
<(rat,2), (cat,0)..#include<vector>
#include<string>
#include<unordered_map>
#include<algorithm>
#include<iostream>
using namespace std;
using vecStr = vector<string>;
vector<pair<string,int>> fun(vecStr& dic) {
unordered_map<string, int> um;
vector<pair<string,int>> out;
//Count anagrams after sort
for (auto i:dic){
sort(i.begin(), i.end());
um[i]++;
//um will have
//art:3, act:1, bsu:1
}
//Search word inside map after sort
for (auto i:dic){
string word = i;
sort(i.begin(), i.end());
auto it = um.find(i);
if (it != um.end()){
int count = it->second;
out.push_back({word, count-1});
}
}
return out;
}
int main() {
//output:
//rat:2, cat:0, bus:0, art:2, tar:2
//rat,art,tar are anagrams
vector<string> dictionary = {"rat", "cat", "bus", "art", "tar"};
vector<pair<string,int>> out = fun(dictionary);
for (auto i:out){
cout << i.first << "," << i.second;
}
}n*mlogm
m*n
m*n: storing mapm*n: storing output.Design Stock Trading System
Objects:
1. MoneyTransfer
2. GlobalStock: This keeps avialble stock count globally
stock value available_count
3. Userbookeeping: This keeps stocks aviable per user inside datacenter.
stock value time_picked user_name(id) count
globalStock(stock,count)
moneyTransfer
4. display: Shows stocks to user. Take values from GlobalStock -> vector<object>
5. user_microservice: call display's method show(). informs userbooking about stock picked
pick(stock_name){
gbk(count, stock, selfid)
}
sell(){
}