Oracle | Principal Software Engineer | Bangalore | April 2022 [Result: Awaited]]
2334
Apr 14, 2022
Apr 15, 2022

Oracle Bangalore

Please upvote if you like to reach article to wider audience.

Round-1. Choose Data Structure

  • What DS will you choose to find which service is visited maximum times in last 1 hour.
  • You have services s1,s2..sn. All services are accessed using common gateway, you can install your process to find which service is accessed.
  • Answer
    • Purge timer will fire every second and check services from head of ll. if (current_timestamp > timestamp_on_list) remove
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 timer

Round-2. OOD => Parking lot

  • Design a parking lot which can accomodate 2 wheeler, 4 wheeler, truck into parking.
  • n 2 wheelers will combine to create 1 4 wheeler. m 4 wheelers will combine to create 1 truck parking.
  • Take driveway into consideration when designing parking lot.

Round-3

1. DS: Counts Anagrams from Dictionary

Count Anagrams in Dictionary

  • What is Anagram
  • Give a dictionary of words, we need to count anagrams except present word. Dictionary can have meaningful or unmeaningful words.
Input 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 anagrams

Approch, Sort, map

Logic

  • 1. Sort each word and store count in map
input:      {"rat", "cat", "bus", "art", "tar"}
sorted:     {"art", "act", "bsu", "art", "art"}
map:
  art,3 | act,1 | bsu,1
  • 2. Iterate thru original Dictionary, sort each word and search in map
input:      {"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)..

Code


CPP

#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;
    }
}

Complexity

  • Time: n*mlogm
    • m: length of longest word in dictionary. mlogm
    • n: length of dictionary.
  • Space: 2m*n
    • n: number of words in dictionary
    • m: max length of word in dictionary
    • m*n: storing map
    • m*n: storing output.

2. System Design

Design Stock Trading System

  • Requirements:
    • 1. You can buy n units of particular stock (Eg: google 100)
    • 2. Preference should be give to user who buys more stocks. (Eg: (user-A stocks=100,company google), (user-B stocks=50,company google))
    • 3. Give OOD
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(){
            }

3. OOD

  • Design a system where original base class is not touched and we need to add new features. Design a window class which initially supports:
    • text window, image window
    • Now we want to add a new window(video window), base class should not change.
Comments (1)