Google | L3 | Munich | July 2021 | Reject on phone interview
Anonymous User
1323

First Task : You given start and end in chessboard, you have bishop , need to find minimum number of move to reach to end

00 01 02 03 04 05 06 07

08 09 10 11 12 13 14 15

16 17 18 19 20 21 22 23

24 25 26 27 28 29 30 31

32 33 34 35 36 37 38 39

40 41 42 43 44 45 46 47

48 49 50 51 52 53 54 55

56 57 58 59 60 61 62 63

Example :
input : start = 00 , end = 27
output : 1

input : start = 00 , end = 20
output : 2

input : start = 00 , end = 00
output : 0

pair<int,int> proccessCoordinate(int pos){
   return hashmap[pos];
  ["0"] = {0,0}
  unordered_map<int,pair<int,int>> hashmap;
  
}
int minimumNumberOfMove(int start,int end){ 
if (start == end){
    return 0;
}
int startX = proccessCoordinate(start).first; 
int startY = proccessCoordinate(start).second; 

int endX = proccessCoordinate(end).first; 
int endY = proccessCoordinate(end).second;


// if they in same color

if ((startX + startY) % 2 != (endX + endY) % 2 ){ 
    return -1;
}

// if they in same diagonal

if (abs(startX - startY) == abs(endX - endY)) { 
    return 1; 
}
return 2;  
}

Second Task

Make review && improve code

======= ad.h ============
  
// An ad represents a text ad shown on a web site.
class Ad {    
  
  public:
    Ad(string adText, string keyword, int bid, Account& account) : 
      adText_(std::move(adText)), keyword_(keyword),bid_(bid),account_(account)
    {}
  
    // A user has clicked on this ad.  Bill the appropriate account.
    void handleClick();

    // All other methods omitted for brevity...

  private:
    string adText_;
    string keyword_;
    int bid_;
    Account& account_;
};
====== ad.c ======
  
void Ad::handleClick() {
  switch (account_.getType()) {

    case Account::kCREDIT_CARD_ACCOUNT:
      Biller::submitToBiller(account_.getCreditCardNumber(), bid_);// async call
      break;

    case Account::kPREPAID_ACCOUNT:
      account_.setPrepaidBalance(account_.getPrepaidBalance() - bid_);
      if (account_.getPrepaidBalance() <= 0) {
        account_.setEnabled(false);
        EmailUtil::sendOverdrawnEmail(account_.getEmailAddress()); // async call
      }
      break;

    case Account::kBANK_TRANSFER_ACCOUNT:
      Biller::billBankAccount(account_.getBankRoutingNumber(),
                              account_.getBankAccountNumber(), 
                              bid_); // async call
      break;

    default: 
      // do nothing.        
  }
}
==== account.h ======
  
 // An account hold the contact information and payment information.
class Account {

  public:
    static const int kCREDIT_CARD_ACCOUNT = 0;
    static const int kPREPAID_ACCOUNT = 1;
    static const int kBANK_TRANSFER_ACCOUNT = 2;

    
    

    void setEnabled(bool enabled) { enabled_ = enabled; }

  private:
    string bankAccountNumber_;
    string bankRoutingNumber_;
    string creditCardNumber_;
    string emailAddress_;
    int prepaidBalance_;
    int type_;
    bool enabled_;
};
   

Red Flags: Language barrier, OOP design

For algorithm problems I use C++, but for work I use Java, it was hard for me to improve code in C++.

Comments (3)