## Twitter Interview Questions

- 3of 3 votes
Twitter

Count number of each character in a string and print out the counts from highest to lowest.

- 2of 2 votes
Twitter

Create a simple stack which takes a list of elements.

Each element contains a stack operator (push, pop, inc) and a value to either push/pop or two values, n and m,

which increment the bottom n values by m.

Then print the topmost value of the stack after every operation. If the stack is empty, print "empty"

- 1of 1 vote
Tweet Recommendation

Twitter Interview Online Test

On Twitter, millions of tweets are posted on a daily basis. Help Twitter write a simple ranking algorithm to find the best of all tweets. It works as follows: A good tweet receives many “likes” from people on Twitter, either from people you follow, or people you do now follow. A tweet is more relevant to you if people you follow also liked the tweet. If enough people you follow have liked that tweet, we recommend that tweet to you.

Your task is to complete the function

getRecommendedTweets(followGraph_edges, likeGraph_edges, targetUser, minLikeThreshold), which returns a list of tweet IDs in sorted order that should be recommended for a certain user. It takes 4 parameters:

followGroup_edges stores follow relationships as an array of tuple of integers.

For example, followGraph_edges = Array{(A, B), (A, C), (B, C)} represents 3 follow relationships:

A follows B

A follows C

B follows C

likeGraph_edges stores like relationships, also in an array of tuple of integers.

For example, likeGraph_edges = Array{(A, T1), (B, T2), (A, T2)} means:

A liked tweet T1

B liked tweet T2

A liked tweet T2

targetUser is the user ID for which we generate recommended tweets

minLikeThreshold is the minimum number of likes a tweet mush receive from people you follow to be recommended

For example, if minLikeThreshold = 4, only tweets that received at least 4 likes from people you follow should be recommended

Note: If you cannot find a single tweet that meets our requirement, simply return an empty list. You may also use any functions provided by the standard library.

- -1of 1 vote
Employees Per Department

Twitter Interview Online Test SQL

A company uses 2 data tables, Employee and Department, to store data about its employees and departments.

Table Name: Employee

Attributes:

ID Integer,

NAME String,

SALARY Integer,

DEPT_ID Integer

Table Name: Department

Attributes:

DEPT_ID Integer,

Name String,

LOCATION String

View sample tables:

https://s3-us-west-2.amazonaws.com/aonecode/techblog/50cfcdd1d61f1bd6002cf4d3b4a61deb-min.jpeg

Write a query to print the respective Department Name and number of employees for all departments in the Department table (even unstaffed ones).

Sort your result in descending order of employees per department; if two or more departments have the same number of employees, then sort those departments alphabetically by Department Name.

- 2of 2 votes
Hacking Time

Twitter Interview Online Test

Alice and Bob are avid Twitter users and tweet to each other every day. One day, Alice decides to send Bob a secret message by encrypting it and tweeting it publicly to Bob. They had anticipated a scenario like this, and exchanged a shared secret key some time in the past. Unfortunately, Alice isn’t very familiar with encryption algorithms, so she decides to make her own. Her encryption algorithm works as follows:

1. Choose a key entirely composed of digits 0 - 9, for example: 12345.

2. Iterate each letter of the plaintext message and rotate the letter forward a number of times equal to the corresponding digit in the key. If the rotation of the letter passes Z, start back at A.

3. If the message is longer than the key, loop back to the first digit of the key again, as many times as needed.

4. If a non-alphabetical character is encountered, leave it as it is and don’t move to the next digit in the key.

5. Characters should maintain their upper or lowercase orientation after rotation.

Here is an example message and its encrypted output using Alice’s algorithm:

Original message: Hi, this is an example

Example Key: 4071321

Encrypted message: Li, ailu jw facntll

Where H was rotated forward 4 letters to L, i rotated 0 to i, t rotated forward 7 letters to a, etc.

Satisfied with the security of her algorithm, Alice tweets the following ciphertext to Bob:

Otjfvknou kskgnl, K mbxg iurtsvcnb ksgq hoz atv. Vje xcxtyqrl vt ujg smewfv vrmcxvtg rwqr ju vhm ytsf elwepuqyez. -Atvt hrqgse, Cnikg

Uh oh! Unfortunately for Alice and Bob, you are “Eve”, the world’s greatest hacker. You’ve been intercepting Alice’s messages for some time now, and know she always ends her messages with the signature “-Your friend, Alice”. You job is now as follows:

Determine the key Alice is using.

Using this key, write a function to decrypt any future communications from Alice. This method should take the encrypted string as an input and return the original unencrypted string.

- 0of 0 votes
Design a system to find top 10 twitter hashtags in the most recent 1 min, 10 min, 1 hr

- 0of 0 votes
Input: expression_tree | sequence_of_operations

The input is a single line of text with a expression tree and a sequence of operations separated by | character and ended by a \n newline character. Spaces are allowed in the input but should be ignored.

The expression tree is a sequence of 1-character variables A-Z and with sub expression trees formed by parenthesis (expression_tree). Examples: AB, A(B C D), (AB)C((DE)F)

The sequence of operations is a string of with characters R (reverse) or S (simplify)

Reverse means reverse the order of everything in expression tree. Applying reverse twice in a row cancels out. Example: (AB)C((DE)F) | R should print (F(ED))C(BA)

Simplify means remove the parentheses around the very first element in the expression tree and each of its subexpression trees. Applying S multiple times should have same result as applying S once. Example: (AB)C((DE)F) | S should print ABC(DEF)

String process(String input){

}

- 0of 0 votes
Solve the 24 Game

- 0of 0 votes
There is a DNA Strand having values as A , T , C , G.

All combinations are present in the the file.

Write a method which takes starting mutation string , ending mutation string and string bank and calculates the minimum mutation distance required. But the condition is that either of the start or end must be present in the bank.

Input:

AATTGGCC is starting and TTTTGGCA is ending then mutation distance will be 3.

AATTGGCC - TATTGGCC - TTTTGGCC - TTTTGGCA as it takes three mustaion for start to reach the end string and for this , all intermediate string and final string must be present in the bank.

static int findMutationDistance(String start, String end, String[] bank) {

}

- 0of 0 votes
You have a string of phrases present. For your simplicity consider them to be integer length.

String s= " I am Tom"

will be stored in an interger array as [1,2,3] where each represents length of each word in the string.

Write a method to compute the longest subsequence such that it is less than given k value.

Input:

3 //length of array

1 //a[0]

2 //a[1]

3 //a[2]

4 // value of k

Output:

2

Input:

4 //length of array

3

1

2

1

4 //value of k

Output:

3

static int maximumLength(int[] a, int k) {

}

- 1of 1 vote
Find the anagrams from a list of strings

Input : {"tea", "ate", "eat", "apple", "java", "vaja", "cut", "utc"}

Output : {"tea", "ate", "eat","java", "vaja", "cut", "utc"}

- 0of 0 votes
Stanford has to select a team of dodgeball players from its class of 2013. There are n students in the class and each student is identified by his/her student ID, which is between 1 and n. The coach has to select K players out of these n students for his team. But there is a twist, if among the K dodgeball players, a player's ID number evenly divides another player's ID number, then there is a high chance of them getting into a fight. The coach will do his best to select the K players so that no pair of players among them will want to fight one another. But if the game turns out to be very popular, this becomes impossible. Complete the function dodgeBall to return the minimum size of K at which it becomes impossible to choose a dodgeball team that has no fighting?

Input Format:

One line of text, containing the size of the class of 2013, n

Constraints:

1 <= n <= 5,000,000,000

n is guaranteed to be an even number

Output Format:

The minimum size of K that guarantees the existence of 2 players who fight with each other in any K-sized subset of the class.

Sample Input:

4

Sample Output:

3

Explanation:

If the team = {1,2,3}: 1&2 or 1&3 can fight with each other

If the team = {1,3,4}: 1&3 or 1&4 can fight with each other

If the team = {2,3,4}: 2&4 can fight with each other

If K=2, then the teams {3,4} or {2,3} will have no fights. So 3 is the smallest value of K for which any K-sized team, must include a fighting pair.

Sample Input:

2

Sample Output:

2

Explanation:

The team = {1,2}: 1&2 can fight with each other

- 0of 0 votes
Design a unique hash function for every tweet in Twitter which will be used as part of a service.

- 2of 2 votes
Given an array of task and k wait time for which a repeated task needs to wait k time to execute again. return overall unit time it will take to complete all the task.

Example:

1. A B C D and k = 3

ans: 4 (execute order A B C D)

2. A B A D and k = 3

ans: 6 (execute order A B . . A D)

3. A A A A and k =3

ans: 13 (A . . . A . . . A . . . A)

4. A B C A C B D A and k = 4

ans: 11 (A B C . . A .C B D A )

- 0of 0 votes
Design Twitter.

- 1of 1 vote
1) You have a folder full of .bin files that are proprietary.

2) You have a class called converter with a "binToTSV" method which you can pass the name of a .bin file and will generate a .tsv file.

3) The TSV file is a tab separated value file with a key on each line, and a value next to it spaced with a tab as such.

-------

num_connections 65

latency_ms 70

bandwidth 20

.... //etc.

-------

Q: Write a method to calculate the average latency and total bandwidth.

- 0of 2 votes
Objective: Write a function to find all the combinations of three numbers that sum to zero

Sample input:

[2, 3, 1, -2, -1, 0, 2, -3, 0]

Sample output:

2, -2, 0

1, -1, 0

3, -2, -1

3, 0, -3

3, 0, -3

- 1of 1 vote
write a function that has an int as input and return the equivalent String as an output

12 -> 'twelve'

4345 -> 'four thousand three hundred and forty-five'

7654567643 -> 'seven billion six hundred and fifty-four million five hundred and sixty-seven thousand six hundred and forty-three'

- 0of 2 votes
You have n - 1 numbers from 1 to n. Your task is to find the missing number.

I.e.

n = 5

v = [4, 2, 5, 1]

The result is 3.

- -2of 2 votes
Given an array with numbers, your task is to find 4 numbers that will satisfy this equation:

A + B + C = D

- 1of 1 vote
given two nodes of a binary tree, find number of nodes on the path between the two nodes.

`1 2 3 4 5 4, 3 -> (4-2-1-3): 4`

- -4of 4 votes
Two sorted 2D arrrays, get the third one sorted

A = [["a", 1], ["b", 2]] sorted all elements have different names

B = [["a", 2], ["c", 3]] sorted

C = [["a", 3], ["b", 2], ["c", 3]] sorted

- 1of 3 votes
Implement LRU cache.

- 0of 0 votes
Given a list of names. Find whether a particular name occurs inside a given tweet or not. If found return true otherwise false Time complexity should be less than O(n).

Ex: "Katy Perry","Ronan Keating" given as a list of string.

List<String> names;

bool findName(String tweet)

{

}

- 0of 0 votes
Given a preorder sequence from a Binary Tree, how many unique trees can be created from this? (They want a recurrence relation and start with the easy cases):

T(0) = 1

T(1) = 1

T(2) = 2

What is T(N) ?

- -2of 4 votes
For a technical phone screen:

Given a string "aaabbcccc", write a program to find the character with the second highest frequency.

- 0of 0 votes
given 4 points, whose x and y coordinates are both integers. they are all different. write a function to check if they form a square.

i forgot to point out that the points can be given in any order

- 0of 0 votes
Write a method to validate that given Binary tree is a BST.

- 0of 0 votes
Given a Tuple for eg. (a, b, c)..

Output : (*, *, *), (*, *, c), (*, b, *), (*, b, c), (a, *, *), (a, *, c), (a, b, *), (a, b, c)

- 1of 1 vote
String getSentence(String text, Set<String> dictionary);

// text is a string without spaces, you need to insert spaces into text, so each word seperated by the space in the resulting string exists in the dictionary, return the resulting string

// running time has to be at least as good as O(n)

// getSentence("iamastudentfromwaterloo", {"from, "waterloo", "hi", "am", "yes", "i", "a", "student"}) -> "i am a student from waterloo"