Meta | E5 Phone Screening | USA
Anonymous User
1325

/*

  • Click Run to execute the snippet below!
    */

import java.io.;
import java.util.
;

/*

  • To execute Java, please define "static void main" on a class
  • named Solution.
  • If you need more classes, simply define them inline.
    */

class Solution {
public static void main(String[] args) {
ArrayList strings = new ArrayList();
strings.add("Hello, World!");
strings.add("Welcome to CoderPad.");
strings.add("This pad is running Java " + Runtime.version().feature());

for (String string : strings) {
  System.out.println(string);
}

}
}

// Your previous Plain Text content is preserved below:

// Welcome to Meta!

// This is just a simple shared plaintext pad, with no execution capabilities.

// When you know what language you would like to use for your interview,
// simply choose it from the dropdown in the top bar.

// Enjoy your interview!

// // Ocean View
// //
// // Write a function to determine which apartments have a clear view of
// // the ocean.
// //
// // The input is an array of integers that represent the height of
// // apartments. Left most apartment is in index 0 and the array lists
// // the apartments from left to right. After the rightmost apartment,
// // we hit the ocean. Apartments are of the same width and in a
// // straight line from left to right towards the ocean.
// //
// // Output the indexes of the apartments that have ocean view.
// //
// // Example
// //
// // Input: [4, 3, 2, 3, 1]
// // Output: [0, 3, 4]
// //
// // ___
// // 4 | | ___ ___
// // 3 | | | | ___ | |
// // 2 | | | | | | | | ___
// // 1 | | | | | | | | | |
// // ~~~~~ Ocean
// // b0, b1, b2, b3, b4

class Solution {
  public List<Integer> buildingswithOceanView(int[] buildings){
      List<Integer> result = new ArrayList<>();
      if(buildings == null || buildings.lenght == 0)
        return result;
      int last = Integer.MIN_VALUE;
      for(int i = buildings.length -1; i>=0; i--){
        if(buildings[i] > last){
          result.add(0,i);
          last = buildings[i];
        }
      }
      return result;
  }

// # Tic-Tac-Toe is a game where two players alternate placing their
// # pieces (X or O) in empty spots on a 3x3 grid. The first player to
// # get three pieces in a row is the winner.
// #
// # Write a function that takes a board state, a player, and a move and
// # returns whether or not that player has won the game.
// #
// # bool isWin(board, player, x, y)
  public static boolean isWin(char[][] board, char player, int x, int y){
    //check the current row
    boolean hasPlayerWon = true;
    for(int i=0; i< board.length; i++){
        if(board[x][i] != player)
          hasPlayerWon = false;
    }
    if(hasPlayerWon) return true;
    hasPlayerWon = true;
    //check the current col
    for(int i=0; i< board[0].length; i++){
        if(board[i][y] != player)
          hasPlayerWon = false;
    }
    if(hasPlayerWon) return true;
    hasPlayerWon = true;
    //check the  diagonal
    for(int i=0; i< board.length; i++){
        if(board[i][i] != player)
          hasPlayerWon = false;
    }
    if(hasPlayerWon) return true;
    //check the reverse diagonal
    hasPlayerWon = true;
    for(int i=0; i< board.length; i++){
        if(board[i][board.length - i - 1] != player)
          hasPlayerWon = false;
    }
    if(hasPlayerWon) return true;
    return false;
  }
}
Comments (3)