## unknown Interview Questions

- 0of 0 votes
Create a SQL-like language parser that manipulates directories and files (The compiler/parser may be created in any other language).

To summarize, I want you to create a "file and directory manipulation language" with the following rules/syntax (you may create another commands):

CREATE DIR <path>

CREATE FILE <name> IN <path> [WITH <data>]

'WITH' insert the <data> in the file on the fly, but it's optional

GET DATA FROM <path/to/file>

Examples on how this language may be used:`import FDML ex = "Hey guys" data = FDML.get('GET DATA FROM "./path/to/file"'); FDML.statement("""CREATE DIR "./imgs"; CREATE FILE "test.txt" IN "./path/to/dir""") FDML.statement('CREATE FILE "welcome.txt" IN "./path/to/dir" WITH "{}"'.format(ex)) print(data)`

Or those commands can be run in a shell:

> fdml "CREATE DIR './dir'"

> /dir was created!

- 0of 0 votes
I have applied for Software Engineer at a startup company in India, I have asked the following question.

You are building an application with ORM model say django, you have set of models, urls. Let's say an user is hitting api /user/account/profile/xxx/yyy like this. You have to check whether user has permission to access or not. If user has access to /user/ then he has access to the whole URL, like wise if he has access to /user/account/ he has access to whole URL. User table looks like below and it has a field called prefix which contains URL prefix of that particular user.

Users

userid | prefix | username | firstname | lastname

1 /user/ lokesh1729 lokesh sanapalli

2 /user/account lokesh1729 lokesh sanapalli

What is the most efficient way to check if a particular user has access to an API or not???

I gave a brute-force approach that first we will check if he has access to /user/ then /user/account then /user/account/profile and so on, if he has access to a prefix and we will process the request.

He is not satisfied with the answer. Can anyone tell me what might be the answer for this???

- 0of 0 votes
The question which has been asked is : how to share a variable across two unrelated process in Linux without using IPC.

- 0of 0 votes
The question which has been asked to me is : Print right angle triangle with stars(*) without nested loops. Implement in C programming language.

- 0of 0 votes
Given a string S(a data structure) that contains only square brackets, convert it to an array that stores arrays in the following format: [positionOpeningBracket, positionClosingBracket, nestedDataStructure]. Example: https://i.imgur.com/vZhlZdr.png

`def parser(S): #whatever... print(r) parser("[[]][]") #output: [[0,3,[1,2,null]], [4, 5, null]]`

- 0of 0 votes
You are given a tree and any of the leaf node which is given as input is set to fire. And in each unit time all the neighbouring nodes of the nodes which are already in fire also catch fire. Given a tree find the time taken for the whole tree to catch fire.

The whole catches fire meaning all nodes catches fire.

Example :

4

/ \

5 6

/ \ / \

7 8 9 10

\ \

13 11

\

12

Assume the source leaf node : 9

At 1 sec : 6 catches fire

At 2 sec : 10 and 4 catches fire

At 3 sec : 5 catches fire

At 4 sec : 7 and 8 catches fire

At 5 sec : 13 and 11 catches fire

At 6 sec : 12 catches fire

If we have access to parent pointers its easy just BFS and keeping track of visited we get the answer.

How to go about the problem if we do not have access to parent pointers ??

- 0of 0 votes
Given a array of integers there is one that is repeated several time. How would you compute the length of the sequence of repeated elements.

Assuming the initial array is sorted can you do better than O(n) both for spatial and temporal cost?

- 0of 0 votes
You are given 20 questions to solve in 20 minutes.

If you successfully solve the question, you would receive 2 marks.

If you failed to solve the question, and you do not try it ( let it untouched ) , you would receive 0 marks. If you solve it wrong ( i.e. not the correct answer ) - you would receive -1 ( negative) .

With the story, here are the problems:

1. Write an algorithm, which, given an input array ( set ) of questions, and varying probability ( 0 <= p <= 1 ) of can do and can not do per question, generates a strategy for solving the paper to generate maximum expected pay off.

2. Given the question paper is multiple choice, between 4 choices ( a,b,c,d ) do a bias analysis ( e.g. if more a's are coming than 'c's ), and decide if you would like to probabilistically take risk and mark some to increase pay off.

Obviously, you can get a maximum 40, and a minimum -20.

3. Now, put yourself in the position of the examiner, and try to ensure it is almost impossible to increase payoff by random selection over the questions. Try to negate the bias. That is question 3.

In all 3 cases write an algorithm. Face to face interview, time allocated was 60 minutes. Panel Interview.

- 0of 0 votes
Consider a string A containing exactly X characters. A variant of A, A(k), can be obtained by doing a cyclic shift of A starting from position k (0 <= k < X). The number of characters after the shift in A(k) will remain the same as they were in A. Every j-th character (0 <= j <= X-1) of A(k) is equal to (k+j)%X character of A. We will call A a classic word if there are exactly M positions k such that A(k) = A

You are given array Q containing exactly R strings. For each permutation s = (s[0], s[1], ..., s[R-1]) of integers between 0 and R-1, inclusive, we can define a string generated by this permutation as a concatenation Q[s[0]] + Q[s[1]] + ... + Q[s[R-1]]. Find the number of permutations that generate classic words. All indices in this problem are 0-based

Constraints

Set Q will contain between 1 and 8 elements, inclusive. Each element will have 1 to 20 characters, inclusive

M will be between 1 and 200, inclusive

Input Format

Line 1: comma separated strings representing set Q

Line 2: Integer M

Output Format

Number of permutations that generate classic words

Sample Input

CD,QCCD,QC

2

Sample Output

3

Explanation

The classic words are "CDQCCDQC" and "QCCDQCCD". Permutation 0, 1, 2 generates the first, and 1, 2, 0 and 2, 0, 1 generate the second

- 0of 0 votes
Your friend has invented a new compound consisting of N elements. However, he has forgotten the amount of each element that goes into the recipe.

For N-1 pairs of elements, he remembers the proportion in which the elements within each pair should be added to the compound. Fortunately, these N-1 proportions are sufficient to restore the recipe of the entire compound.

You are given N-1 proportions as String. Each String is formatted "#<a> and #<b> as <p>:<q>" (quotes for clarity), which means that the mass of element <a> divided by the mass of element <b> in the cocktail must be equal to <p>/<q> (all elements are 0-indexed). Print exactly N elements, where the first line is the mass of element 0 and second line is the mass of element 1 and so on... such that all the given proportions are satisfied and the total mass is as small as possible. The total mass must be greater than 0.

Input

Line 1: N

Line 2 .. N: proportion_i

Output

N lines of masses, as stated in the problem statement

Input Explanation

Line 1: N, the number of elements

Line 2 to line N: N-1 proportions, format described in the problem statement

Output Explanation

Output will contain exactly N lines, each line is the mass of the element such that all the given proportions are satisfied and the total mass is as small as possible. The total mass must be greater than 0.

Sample Input

3

#0 and #1 as 9:8

#1 and #2 as 9:8

Sample Output

81

72

64

- 0of 0 votes
Consider a social website SocialX, where friends connect to each other, just as they do on Facebook

Friendship on SocialX is symmetric (if X is a friend of Z, then Z is also a friend of X) however not transient (if X and Z are friends and Z and Y are friends, then X and Y are not necessarily friends)

The term "k-joined" is defined as follows. If two people are friends, they are called 1-joined. For k >= 1, two people X and Z are called (k+1)-joined if X and Z are k-joined, or if there exists a person Y such that X and Y are k-joined and Y and Z are friends.

"Approachable Score" is defined as follows. If two people X and Z are not friends, then their Approachable Score is the fewest number of people (other than themselves) who must be removed from the network in order for X and Z to not be 3-joined. The higher the Approachable Score, the more likely it is that X and Z know each other.

Given a set of friends containing exactly K elements, where K is the number of people in the network. People are numbered from 0 to K-1. The j-th character of the i-th element of friends is '1' if i and j are friends, and '0' otherwise. Return the Approachable Score for personX and personZ

Constraints

Set of friends will contain exactly K (1 < K < 41) elements, where each element will contain exactly K characters. Each character will either be '0' or '1'

friends[i][j] will always be equal to friends[j][i] and friends[i][i] will always be equal to 0

friend[personX][personZ] will be equal to 0 and personX will never be equal to personZ

Input Format

Line 1: comma separated K elements representing friends

Line 2: Integer representing personX

Line 3: Integer representing personZ

Output Format

Integer representing Approachable Score

Sample Input

0100,1010,0101,0010

0

3

Sample Output

1

Explanation

Either remove person 1 or person 2 to get an Approachable Score of 1 for person 0 and 3

- 1of 1 vote
You are given a list of tasks as an integer array, task_costs. Every i-th element of task_costs represents a task and requires task_costs[i] seconds to complete. All tasks listed in the array are independent of other tasks.

It is required to finish all the tasks independently and as soon as possible. You are given a single worker robot to start taking the tasks and finish them one at a time. However if you like, you can divide the worker robot in two. Each resulting robot can then be further divided into two and so on. There is a cost, in seconds, of dividing a robot in two, represented by robot_divide_cost.

You can assign an independent task to any available robot, however you can't interrupt or divide a robot while it is working on the assigned task. At the same time you can't assign a task to any robot while its in the process of getting divided.

To keep things simple you can't allow multiple robots to work on the same task. At any given time only one robot can work on a task and finish it. Once any particular robot finishes a task it can't be assigned any further tasks.

Given a list of tasks and cost of dividing a robot, find the least amount of time to finish all tasks.

Input:

3600,3600,3600,3600,3600,3600,3600,3600,3600,3600,3600,3600,3600,3600,3600,3600,3600,3600,3600,3600,3600,3600,3600,3600,3600,3600,360,3600,3600,3600,3600,3600,3600,3600,3600,3600,3600,3600,3600,3600,3600,3600,3600,3600,3600,3600,3600,3600,3600,3600

3600

Expected Output: 25200

Input:

1113,773,824,822,1458,1257,908,1320,780,1016,1066,861,1150,718,1405,738,718,980,1037,946,1121,1349,805,1378,1308,1272,1532,779,875,1392,982,1282,744,723,1033,1067,1158,1071,742,683,678,762,686,1143,862,1231,765,1472,1560,1085

3147

Expected Output: 20040

- 0of 0 votes
You are given a string X and integer k (0 <= k < length of X). For each value of k you can look at a sub-string of X starting from index 0 to index k and choose to reverse it. As an example, let X = LMNAP and k = 2. If you reverse the sub-string of X between 0 and 2 you will get NMLAP. Subsequently if choose k = 3 and reverse you will end up with ALMNP.

Given the string X as an input find lexicographically earliest possible string. In the example above, lexicographically ALMNP comes earlier than NMLAP.

Input:

AACAACAABBABACAACBCACCCAAABACABACACCBCCAAABABACBCC

Expected Output: AAAAAAAAAAAAAAAAAAAAAAACCBBBCCBCCCCBCBCCCBCCBBCBCC

Input:

BACBCBCACAACBCBBCCBACCCCAACCBCCAABACAABCAAAABBAABC

Expected Output: AAAAAAAAAAAAAAAAAABCBCBCCCBCBBCCBCCCCCCBCCBCBCBBBC

- 0of 0 votes
How to print from 3rd column to till last columns using awk command in unix, if there are 'n' columns in a file.

- 0of 0 votes
Given a matrix of ‘O’ and ‘X’, find the largest sub rectangle surrounded by ‘X’

Example :

XXXXX

X0X0X

XXXXX

XXXXX

Output : largest rectangle size is 4 x 5

- 0of 0 votes
`interface RangeContainerFactory { /** * builds an immutable container optimized for range queries. * Data is expected to be 32k items or less. * The position in the “data” array represents the “id” for that instance * in question. For the “PayrollResult” example before, the “id” might be * the worker’s employee number, the data value is the corresponding * net pay. E.g, data[5]=2000 means that employee #6 has net pay of 2000. */ RangeContainer createContainer(long[] data) } /** * a specialized container of records optimized for efficient range queries * on an attribute of the data. */ interface RangeContainer { /** * @return the Ids of all instances found in the container that * have data value between fromValue and toValue with optional * inclusivity. The ids should be returned in ascending order when retrieved * using nextId(). */ Ids findIdsInRange(longfromValue, long toValue, boolean fromInclusive, boolean toInclusive) } /** * an iterator of Ids */ interface Ids { /** * return the next id in sequence, -1 if at end of data. * The ids should be in sorted order (from lower to higher) to facilitate * the query distribution into multiple containers. */ static final shortEND_OF_IDS = -1 short nextId() } Validation: Your implementation should pass the following simple JUnit test before you start tuning for performance with volume data: public class RangeQueryBasicTest { private RangeContainer rc @Before public void setUp(){ RangeContainerFactory rf = new YourRangeContainerFactory() rc = rf.createContainer(new long[]{10,12,17,21,2,15,16}) } @Test public void runARangeQuery(){ Ids ids = rc.findIdsInRange(14, 17, true, true) assertEquals(2, ids.nextId()) assertEquals(5, ids.nextId()) assertEquals(6, ids.nextId()) assertEquals(Ids.END_OF_IDS, ids.nextId()) ids = rc.findIdsInRange(14, 17, true, false) assertEquals(5, ids.nextId()) assertEquals(6, ids.nextId()) assertEquals(Ids.END_OF_IDS, ids.nextId()) ids = rc.findIdsInRange(20, Long.MAX_VALUE, false, true) assertEquals(3, ids.nextId()) assertEquals(Ids.END_OF_IDS, ids.nextId()) } } FAQ Can't we just use a B-Tree/ NavigableMap/HashTable/BinarySearch/Lucene... Sure, if you want. But there are a number of things we'd like to achieve: ● The container will be in memory and will need to hold lots of data, so we'd like it to be as space efficient as possible, but not to the extent where speed is significantly compromised. Speed is king, memory/disk can be purchased. ● Since we hate collecting garbage, we need to be careful about memory allocation during a query, as my grandmother told me, "allocate not, gc not". ● Code should be clear and understandable. ● The rough order of trade off to consider for this case is: search performance, efficient usage of memory, simplicity and maintainability of the code These objectives are often at odds - we'd like to explore what's possible.`

- 2of 2 votes
How to find middle element in a linked list without knowing the length of the linked list

- 2of 2 votes
You know result of a soccer match, print all the possible ways that this game ends up with this result.

Example: final score 1 - 1:

0 - 0

0 - 1

1 - 1

0 - 0

1 - 0

1 - 1

Another example if the final score is 2 - 3 there are many possibilities for reaching to that score:

2 - 3

0 - 0

1 - 0

2 - 0

2 - 1

2 - 2

2 - 3

0 - 0

1 - 0

1 - 1

1 - 2

2 - 2

2 - 3

0 - 0

0 - 1

0 - 2

0 - 3

...

- 0of 0 votes
Find the largest substring in s1, such that all characters in the substring are present somewhere in s2

- 0of 0 votes
Asked me to write an API. Then ask:

Consider how the API could support 3rd party applications which need to perform some logic based on the structure and content of a filter in a type-safe manner.

- 0of 0 votes
It is part of a programming exercise.

Input is a combination of arbitrary complex filters. For example:

name = "smith" AND age > 9 OR Not(city = "New York")

It asks for a string representation, including the ability to generate and parse filters from the string representation. (you are not required to implement the string parsing logic since this could take too long)

Hint: give an example of a tree data structure.

- 0of 0 votes
Given an array of integers of unknown size, how to reverse the order of the positive integers?

Ex [4 3 8 9 -2 6 10 13 -1 2 3 .. ] =>

[ 9 8 3 4 -2 13 10 6 -1 3 2]

- 0of 2 votes
The "Island Count" Problem

Given a 2D matrix M, filled with either 0s or 1s, count the number of islands of 1s in M.

An island is a group of adjacent values that are all 1s. Every cell in M can be adjacent to the 4 cells that are next to it on the same row or column.

Explain and code the most efficient solution possible and analyze its runtime complexity.

Example: the matrix below has 6 islands:

0 1 0 1 0

0 0 1 1 1

1 0 0 1 0

0 1 1 0 0

1 0 1 0 1

- 0of 0 votes
Find the nth Fibonacci Prime, in the shortest code

- 0of 0 votes
Given a list of nodes, each with a left child and a right child (they can be null), determine if all nodes belong in a single valid binary tree. The root is not given.

- 0of 0 votes
A paper consists of a series of consecutive numbers from 1 up to 2^n values. For example,

For case 2^1, content of the paper is,

1 2

For case 2^2, content of the paper is,

1 2 3 4

For case 2^3, content of the paper is,

1 2 3 4 5 6 7 8

There will be n number of commands for 2^n case. Below are the commands,

L – Fold the paper from Left edge to Right edge

R – Fold the paper from Right edge to Left edge

After performing the n number of commands, there will be a single number in all layer of paper, you need to write down the numbers in all layers when you see the paper from upside of it.

Please provide an efficient algorithm.

Example:

Content of the paper (2^3):

1 2 3 4 5 6 7 8

Commands: LRL

Output:

5 4 1 8 7 2 3 6

- 0of 0 votes
How will you test an application like Google Analytics ?

- 0of 0 votes
What are the basic features you will add into your own test framework ?

- 0of 0 votes
Which structure can be used to return the lastly added node and remove it from the collection and also will allow to peek the highest valued node without removing it from the collection. What is the time and space complexity for Push, Pop and Peek actions

- 0of 0 votes
Suppose you have a huge data of students. This data is in RAM (around 48 GB). Student has following attributes:

1) RollNo

2) Name

3) Address

Now I need to implement three method:

getStudentByRollNo(int rollno)

getStudentsByName(String name)

getStudentsByAddress(String address)

In what data structure I can keep these students so that these methods can return the results really fast.