↳
FYI, in 2020, this is still relevant.
↳
Relevant in 2021 too.
↳
OP here. Yes, for my interview on site they only asked two
↳
Another approach would be to create a hashtable/dict with key as a tuple (city,hotel name) and value to be the occurrence of the hotel name in that city (count, keep incrementing the count when seen). When the hashtable is created, iterate over items and see whose value >= 3 and return the tuple's/key 1st value Less
↳
using golang ---- package main import ( "fmt" ) func main() { input := [][]string{{"hotel_1234", "Sheraton", "Amsterdam"}, {"hotel_1000", "Sheraton", "Buenos Aires"}, {"hotel_1001", "Hilton", "Amsterdam"}, {"hotel_1002", "Royal Palace", "Bogota"}, {"hotel_1003", "Hilton", "Amsterdam"}, {"hotel_1004", "Sheraton", "Buenos Aires"}, {"hotel_1005", "Sheraton", "Buenos Aires"}, } confuse_cities := []string{} Cities := make(map[string]map[string]int) for _, line := range input { if _, ok := Cities[line[2]]; ok { if val, ok2 := Cities[line[2]][line[1]]; ok2 { Cities[line[2]][line[1]] = val + 1 if Cities[line[2]][line[1]] == 3 { confuse_cities = append(confuse_cities, line[2]) } } } else { Cities[line[2]] = map[string]int{} Cities[line[2]][line[1]] = 1 } } fmt.Println(confuse_cities) } Less
↳
from collections import Counter Input = [ ("hotel_1234", "Sheraton", "Amsterdam") , ("hotel_1000", "Sheraton", "Buenos Aires") , ("hotel_1001", "Hilton", "Amsterdam") , ("hotel_1002", "Royal Palace", "Bogota") , ("hotel_1003", "Hilton", "Amsterdam") , ("hotel_1004", "Sheraton", "Buenos Aires") , ("hotel_1005", "Sheraton", "Buenos Aires"), ("hotel_1232", "Sheraton", "Amsterdam"), ("hotel_123222", "Sheraton", "Amsterdam") ] confusing_cities = [] for i,v in Counter((elem[1],elem[2]) for elem in Input).items(): if v >= 3: confusing_cities.append(i[1]) print(confusing_cities) Less
↳
The correct approach is to show that you can break down the problem. 2^32 = 2^10 * 2^10 * 2^10 * 2^2. 2^10 = 2^8 * 2*2 = 256 * 4 ~(roughly) 1000 So: 2^32 ~ 1000 * 1000 * 1000 * 4 = 4,000,000,000 Less
↳
4 giga
↳
The number that will overflow a variable of type unsigned 32-bit int. const MAX_U32INT = 2^32 -1 Less
↳
P2P is the first thing that came to my mind. BitTorrent is a good tool and I believe Twitter or Facebook has developed this kind of distributing tool based on BitTorrent protocol. And I don't believe the 1TB data will be read at the same time. We can write a FUSE module that mount the directory from the central server. When one of the files was read, we can copy it and cache it locally. Less
↳
P2P is the best solution. If P2P is not allowed. We can use broadcast, for example: server1-> server2, then we have 2 sources, server1->server3, server2-server4; then it will take about (time to transfer one copy)*log(10000)= 3*3.32192809489*(time to transfer one copy). For fault tolerance, redundancy or retry. Or deploy a distributed file system so that file can be accessed. Central server solution is like NFS, however, NFS's server could be bottleneck. Less
↳
We can take checksum of the file when it is correct and compare it with the checksum of the same file in future. If both checksum are found to be same then the file isn't corrupted otherwise it is corrupted. Less
↳
Those are not the answers that they are looking for. You basically answered what happens when you turn your computer on with: "The picture appears on the monitor". A proper answer involves: shell word splitting, searching PATH, loading dynamic libs, argument parsing, syscalls, /proc. If you don't know what ps is doing, it isn't hard to find out. Less
↳
It's a question to check if you understand behind the scenes of a terminal when a command is issued. I would answer it in that way: when I type a command and press enter, the Shell has a command line parser that checks if the text entered is a available command in the PATH or not, if not found it checks the system libs to see if it can find the definition of it, if nothing is found, it throws error ": command not found". In the successful case, where the command is found it loads the binary from the defined path and a system call is executed accordingly to fetch the process data from the OS. Less
↳
see list of all processes
↳
1 CPU 2 Memory 3 Context switching 4 Disk
↳
context switch - 3
↳
context switching is costlier than RAM access. I think we all have read this in those operating system lectures. Less
↳
Wrote code.
↳
This is what I came up with, probably not the smartest way : #!/usr/bin/env python def sum_to_n(numbers, n): """ Pick the first two numbers in the list first, then add the third one. Return if the sum is equal to n. Then remove the first two, since you are done with them. Do the same thing as long as you have at least 3 elements in the list """ numbers = numbers.split(",") output = [] first = int(numbers[0]) second = int(numbers[1]) while len(numbers) > 2: for item in numbers[2:]: if first + second + int(item) == n: output.append((first, second, item)) numbers.pop(0) numbers.pop(1) first = int(numbers[0]) second = int(numbers[1]) return output numbers = raw_input("Enter a comma separated list of integers:") n = raw_input("Enter an integer:") print sum_to_n(numbers, int(n)) Less
↳
public static void printPairSums(int[] array, int sum) { Arrays.sort(array); // 2 pointeurs int first = 0; int last = array.length - 1; while (first < last) { int s = array[first] + array[last]; if (s == sum) { System.out.println("( "+array[first] + " ," + array[last]+ " )"); ++first; --last; } else { if (s < sum) ++first; else --last; } } } //Exemple public static void main(String[] args) { // TODO Auto-generated method stub int[] myIntArray = new int[]{1,2,3,-1,4,5,-2,7,1}; printPairSums (myIntArray, 3); } Less
↳
A palindrome is a word that has the same spelling forward and backwards. “1234” are numbers and cannot be a palindrome. Less
↳
“acrecar” is a palindrome by that definition of the word, “racecar”, “dad”, “pop”, “poop”. These I feel like may be better examples. “454” would be an example of a palindrome that is a number. Less
↳
Count the occurrence of each character; if more than one char has odd number of occurrences, it’s false Less
↳
Your python skills are just garbage.. here is how is done for i in range(1,101): if i % 4 == 0 and i % 6 == 0: print('LinkedIn') elif i % 6 == 0: print('In') elif i % 4 == 0: print('Linked') Less
↳
standard fizzbuzz algorithm. I answered in python.
↳
for i in range(1,101): a=i if(i%4==0): a='linked' if(i%6==0): a='in' if((i%4==0) and (i%6==0)): a="linkedin" print a Less