Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- FB Production Engineering Interview Question and Code:
- 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.
- */
- // dataset1.csv
- // NAME,LEG_LENGTH,DIET
- // T-Rex,1.3,carnivore
- // dataset2.csv
- // NAME,STRIDE_LENGTH,WALK_TYPE
- // T-Rex,3.7,bipedal
- // Output in sorted order the name and speed of all bipedal dinosaurs.
- public static final double g = 9.8;
- class Dinosaur {
- public class DiNode {
- String name;
- double stride_len;
- double leg_len;
- double speed;
- public DiNode(String name, double stride_len) {
- this.name = name;
- this.stride_len = stride_len;
- this.speed = Integer.MIN_VALUE;
- }
- public calculate_speed() {
- this.speed = ((stride_len/leg_len)/g);
- }
- public toString() {
- String s = "";
- s += this.name;
- s += this.speed;
- return s;
- }
- }
- public static void main(String[] args) {
- try {
- HashMap<String, DiNode> map = new HashMap<String, DiNode>();
- ArrayList<DiNode> list = new ArrayList<DiNode>();
- Scanner sc = new Scanner(new File("dataset2.csv"));
- String[] line;
- DiNode node;
- while (sc.hasNext()) {
- line = sc.next().split(",");
- // Error checks for args
- if (line[2].equals("bipedal")) {
- map.put(line[0], new DiNode(line[0], line[1]));
- }
- }
- sc.close();
- sc = new Scanner(new File("dataset1.csv"));
- while (sc.hasNext()) {
- line = sc.next().split(",");
- // Error checks for args
- node = map.get(line[0]);
- if (node != null) {
- node.leg_len = line[1];
- node.speed = node.calculate_speed();
- }
- }
- for (Map.Entry<String, DiNode> node : map) {
- if (node.speed != Integer.MIN_VALUE) {
- list.add(node);
- }
- }
- mergesort(list);
- for (DiNode node : list) {
- System.out.println(node);
- }
- } catch (FileNotFoundException e) {
- e.printStackTrace();
- } catch (IOException e) {
- e.printStackTrace();
- } finally {
- sc.close();
- }
- }
- }
- 2nd Q:
- host range: web0001-1000.facebook.com
- process name: app
- optimal number of instances: 4
- Assume authentication is not an issue.
- Give me a list of all the hosts running the optimal number of instances of the given process.
- def int_to_host():
- # ...Input 1, output web0001.facebook.com
- list = [x for x in range(1,1000)]
- host_list = map(int_to_host, list)
- output = []
- for host in host_list:
- if ssh(host, "ps aux | grep app | count -n") == 4:
- output.append(host)
- print(output)
Advertisement
Add Comment
Please, Sign In to add comment