Kensho Technologies | Phone Interview + Onsite
Anonymous User
1160

**online assessment: **
https://leetcode.com/discuss/interview-question/1179932/Kensho-Technologies-or-OA

phone interview:

1. compress a string. the string includes ASCII characters
2. given a compressed string from 1, return the original string

solution:

1. aa,abber -> a2,,1,a1,b2,e1,r1 (I decided to use comma as delimiter)
2. tokenize based on comma and process the token (i.e. a2). 
   if the token is empty (due to a comma in the original string),
   read the next token as well since it indicates the count of the current comma

follow up 1: when is such compressing heplful?
ans: when we have consecutive same characters not mostly distinct characters

follow up 2: how do you compress abcabcabcdd to save space?
ans: abc3d2 (no coding needed)

onsite:
coding interview 1:

Implement the function update_board(board, color) for the following game.
Given a m x n grid (10x20 for example), initialized so that each tile is randomly assigned a color from a 3-color palette. 
The user chooses one of those three colors.  
The upper left hand corner of the board is updated to the new color and any tile that was a neighbor of the tile before the update.  
A neighbor is defined as a tile in the NSEW direction, (no diagonals) of the matching color.
 
R R B
G B R
G B R
 
With input B becomes:
B B B
G B R
G B R
 
With input G becomes:
G G G
G G R
G G R


def update_board(board, color):
    pass
 
board=[['R', 'R', 'B'],
       ['G', 'B', 'R'],
       ['G', 'B', 'R']]

solution:

#include <iostream>
#include <vector>
#include <queue>

using namespace std;
vector <vector <char>> update_board (vector <vector<char>>& board , char newColor){
    //board is updated in place
    
    // check if the board is empty
    if (board.empty() || board[0].empty())
        return board;
    
    int numberOfRows = board.size();
    int numberOfColumns = board[0].size();
    
    // no update needed if new color is the same as old color
    pair <int,int> currCell = {0,0};
    char originalColor = board[currCell.first][currCell.second];
    if (originalColor == newColor)
        return board;
        
    
    queue <pair <int, int>> cellsWithOriginalColor;
    cellsWithOriginalColor.push({currCell.first , currCell.second});
    board[currCell.first][currCell.second] = newColor;

    // helper for getting the neighbors' rows and columns
    vector <vector <int>> neighbors = {{-1, 0} , {1,0} , {0,1} , {0,-1}};
    
    // process cells having the original color
    while (!cellsWithOriginalColor.empty()){
        currCell = cellsWithOriginalColor.front();
        cellsWithOriginalColor.pop();
        for (int i=0 ; i<(int)neighbors.size() ; i++){
            int newRow = currCell.first + neighbors[i][0];
            int newCol = currCell.second + neighbors[i][1];
            // check if new cell is within the range and has the original color
            if (newRow >=0 && newCol >=0 && newRow < numberOfRows && newCol < numberOfColumns && board[newRow][newCol] == originalColor){
                cellsWithOriginalColor.push({newRow , newCol});
                board[newRow][newCol] = newColor;
            }
        }
    }
    return board;
}

void print (vector <vector <char>>& board){
    for (int i=0 ; i<(int)board.size() ; i++){
        for (int j=0 ; j<(int)board[i].size() ; j++){
            cout << board[i][j] << " ";
        }
        cout << endl;
    }
    cout << endl;
}
int main (){
    vector <vector <char>> board = {{'R' , 'R' , 'B'} , {'G' , 'B' , 'R'} , {'G', 'B' ,'R'}};
    vector <vector <char>> updatedBoard1 = update_board (board , 'B');
    print (updatedBoard1);
    vector <vector <char>> updatedBoard2 = update_board (updatedBoard1 , 'G');
    print (updatedBoard2);
    return 0;
}

coding interview 2:

build a data structure that supports three operations
collection of strings
we can use anything in the standard library
add a string to the collection
remove a string from the collection
get a random string from the collection (without removal)
Comments (0)