## Recent Interview Questions

- 0of 0 votes
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.

- 0of 0 votes
The numbers on a telephone keypad are arranged thus:

`1 2 3 4 5 6 7 8 9 0`

Starting from any digit, and choosing successive digits as a knight moves in chess, determine how many different paths can be formed of length n. There is no need to make a list of the paths, only to count them.

A knight moves two steps either horizontally or vertically followed by one step in the perpendicular direction; thus, from the digit 1 on the keypad a knight can move to digits 6 or 8, and from the digit 4 on the keypad a knight can move to digits 3, 9 or 0. A path may visit the same digit more than once.

Your task is to write a function that determines the number of paths of length n that a knight can trace on a keyboard starting from any digit .

public int findNumberOfPaths(int digit, int step){

- 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.

- 1of 1 vote
Explain the Data Structure which is well suited to implement UNIX commands like PWD, LS, MKDIR, CD in an imaginary OS. No code required.

- 0of 0 votes
Unsorted array and a position ‘P’. Return the element that is likely to come to the given location upon sorting the array. TC in O(n).

- 0of 0 votes
A thief trying to escape from a jail has to cross ‘N’ walls each with varying heights. He climbs ‘X’ feet every time. But, due to the slippery nature of those walls, every times he slips back by ‘Y’ feet. Now the input is given as (N, {H1, H2, H3,….Hn}, X, Y}. Calculate the total number of jumps required to cross all walls and escape from the jail.

- 2of 2 votes
Singleton Design pattern. How you make it double ton(in even call of getInstance() first object should be return and odd call of getInstance() second instance should be return). Make it triple ton.

- 1of 1 vote
Print series 010203040506. Using multi-threading 1st thread will print only 0 2nd thread will print only even numbers and 3rd thread print only odd numbers.

- 0of 0 votes
Add a digit to a number that is represented by a linked list, where each node is a digit of the number. The linked list couldn’t be modified, except the digits to be modified in answer and the number could be infinitely long. Need to do it in O(1) space.

- 1of 1 vote
Find the Minimum length Unsorted Subarray, sorting which makes the complete array sorted

- 0of 0 votes
Maximum difference between node and its ancestor in Binary Tree in O(n) time.

- 0of 0 votes
Given a very large binary number which cannot be stored in a variable, determine the remainder of the decimal equivalent of the binary number when divided by 3. Then generalize to remainder of any number 'k'

- 1of 1 vote
Given a pre-order traversal, construct a binary search tree in O(n) time.

- 0of 0 votes
Given a large text file, find an efficient algorithm to find the least distance(measured in number of words) between any two given words.

- 0of 0 votes
here are tuples given for each users of a website (Si,Ei) where Si denotes the when the user entered the website and Ei denotes when the user exits the website .Find the maximum number of users active of website at any time duration.

- 0of 0 votes
There is a binary stream coming . You need to print true or false based on the fact whether the number formed is divisible by 5 or not.

- -1of 1 vote
What is the last digit of the largest prime number?

- 0of 0 votes
How many integers from 1 to 100 inclusive can be written as the product of two (not necessarily distinct) primes?

- 0of 0 votes
Mr. White is an approximately forty years old father with 4 sons of distinct ages. Writing his age 3 times in succession, we get a 6-digit number that is equal to the product of his age, his wife's age and his 4 sons' ages.

Give the sum of his wife's age and all 4 sons' ages.

- 0of 0 votes
2^2014 + 1007^4

Is this sum equal to a prime number?

- 0of 0 votes
If a prime 'p' can be expressed as the difference of square of two positive integers, then find the

Prime Numbers: Level 1 Challenges

If a prime can be expressed as the difference of square of two positive integers, then find the remainder, when (p^2 + 138 ) is divided by 4.

- 0of 0 votes
Find the number of primes among the numbers mentioned below. (! means factorial)

345!+2, 345!+3, 345!+4, ......., 345!+345.

- 0of 0 votes
The sum of three primes is 100. One of them exceeds the other by 36. Find the largest prime.

- -1of 1 vote
P, P+2, and P+3

If P > 3, can all three numbers above be prime?

- 0of 0 votes
Consider a digital clock. The first time after midnight when the three digits are all prime numbers is 2:22 am. What is the last time before 10:00 am when the three digits on the clock are all prime numbers?

- 0of 0 votes
## This is the text editor interface.

## Anything you type or change here will be seen by the other person in real time.

# Implement the function that takes a board string

# and decodes it into the representative 2D array.

#

# |_|_|_|_|_|_|_|

# |_|_|r|_|_|_|_|

# |b|r|b|r|b|r|_|

# |b|b|b|r|r|b|_|

# |b|r|r|b|b|r|_|

# |r|b|b|r|r|r|b|

# CFN: 9_r4_brbrbr_3b2rb_b2r2br_r2b3rb

#

# This function should return a list of lists of strings.

# (i.e. a string[6][7]). The strings should be one of:

# * 'r' to indicate a red piece

# * 'b' to indicate a black piece

# * '_' to indicate an empty space

#

# The input string is not necessarily a valid

# CFN board string. It is guaranteed not-empty.

- 0of 0 votes
transactions = [

{"payee": "BoA", "amount": 132, "payer": "Chase"},

{"payee": "BoA", "amount": 827, "payer": "Chase"},

{"payee": "Well Fargo", "amount": 751, "payer": "BoA"},

{"payee": "BoA", "amount": 585, "payer": "Chase"},

{"payee": "Chase", "amount": 877, "payer": "Well Fargo"},

{"payee": "Well Fargo", "amount": 157, "payer": "Chase"},

{"payee": "Well Fargo", "amount": 904, "payer": "Chase"},

{"payee": "Chase", "amount": 976, "payer": "BoA"},

{"payee": "Chase", "amount": 548, "payer": "Well Fargo"},

{"payee": "BoA", "amount": 872, "payer": "Well Fargo"},

There are multiple transactions from payee to payer. Consolidate all these transactions to minimum number of possible transactions.

HINT: Consolidate transitive transactions along with similar transactions

For Example in the above program, the result is a single transaction [ Boa -> 482 -> Wells Fargo ]

- 0of 0 votes
Given a set of start date and end date design a data structure to return a given date falls in.

Example

1Sep 2016 - 10 Sep 2016

1 Jan 2009 - 31 Aug 2015

given 12 Jan 2014 should return 1 Jan 2009 - 31 Aug 2015

- -1of 1 vote
I am looking for a good resource to learn lossy counting sticky sampling.Can anyone point me towards good resource?I am ready for a one-to-one session too.

- 1of 1 vote
You are given a text file. You have to return the list of starting index of the given word in text file. Design an efficient DS for that.

Example :-

Text file content : “geeks for geeks”

word : “geeks”

List : {0,10}