## Software Developer Interview Questions

- 0of 0 votes
Design a data structure which reads below block of text

*Status update1

**Joe is working on a bug

**Alice is on vacation

*StatusUpdate2

**Alex finished task1

and returns me an Object such that I can navigate the this nested text easily like this:

obj.children[0] - > returns "StatusUpdate"

obj.children[0].children[1] -> "Alice is on vacation"

- 0of 0 votes
Given a Tree where each node contains an attribute say color(R,G,B... etc). find subtree with maximum number of attributes.

Input:

G

/ \

B R

/ \ / \

B B R R

/ \ / \

B R R R

Output:

Input:

R

/ \

R R

\ / \

R R R

- 1of 1 vote
Partition given string in such manner that i'th substring is sum of (i-1)'th and (i-2)'nd substring. If such partition not possible then return empty arrayList.

eg.

1) given "1111223" then return ["1", "11", "12", "23"]

2) given "1111213" then return ["11", "1", "12", "13"]

3) given "11121114" then return []

- -3of 3 votes
Modify the following code:

`def GenerateGraph(data): d = {} g = Graph() for word in data: for i in range(len(word)): bucket = word[:i] + '_' + word[i+1:] if bucket in d: d[bucket].append(word) else: d[bucket] = [word] for v in d.keys(): for word1 in d[v]: for word2 in d[v]: if word1 != word2: g.addEdge(word1,word2) return g`

The objective is to find all combination of words by changing one letter at a time and adding to the graph if word exists in the dictionary.

We need to rewrite a different logic for the above code.

- -1of 1 vote
Given a list of characters, write a function to output a list of length of minimum non overlapping subsequences that can partition the input list.

For example:

Input : [a,b,c]

Output: [1,1,1]

Explanation: There are no repeated characters.

Input : [a,b,c,a]

Output: [4]

Explanation: The 'a' is repeated so one subsequence is between a to last a.

Input : [a,b,c,b,a,e,b,a,d,f,g,d,f,i,f,k,l,m,n,m,l]

Output: [8,7,6]

Explanation: max length from 1st 'a' to last 'a' is 8.

1st 'f' to last is 6 adding d to it = 7

so on

- 1of 1 vote
Michelle has created a word game for her students. The word game begins with Michelle writing a string and a number, K, on the board.

The students must find a substring of size K such that there is exactly one character that is repeated one;

in other words, there should be k - 1 distinct characters in the substring.

Write an algorithm to help the students find the correct answer. If no such substring can be found, return an empty list;

if multiple such substrings exist, return all them, without repetitions. The order in which the substrings are does not matter.

Input:

The input to the function/method consists of two arguments - inputString, representing the string written by the teacher;

num an integer representing the number, K, written by the teacher on the board.

Output:

Return a list of all substrings of inputString with K characters, that have k-1 distinct character i.e.

exactly one character is repeated, or an empty list if no such substring exist in inputString.

The order in which the substrings are returned does not matter.

Constraints:

The input integer can only be greater than or equal to 0 and less than or equal to 26 (0 <= num <= 26)

The input string consists of only lowercase alphabetic characters.

Example

Input:

inputString = awaglk

num = 4

Output:

[awag]

Explanation:

The substrings are {awag, wagl, aglk}

The answer is 'awag' as it has 3 distinct characters in a string of size 4, and only one character is repeated twice.

- 0of 0 votes
from robot movement tell final position of robot...

testcases:

"ULDLLUDL"

"UP 2xDOWN LEFT 4xRIGHT"

- 0of 0 votes
"Implement a job scheduler which takes in a function `f` and an integer `n`, and calls `f` after `n` milliseconds."

That's it. :)

- 0of 0 votes
Is Quicken Customer Service The Finest Customer Care?

- 0of 0 votes
Is Quicken Customer Service The Finest Customer Care?

- 1of 1 vote
The time taken by ith person to complete a task is Ki minutes.

A company wants to finish N tasks given K persons each if their given time. Find minimum time to complete N tasks using K persons. There is no waiting time between the tasks switching. Persons can start their tasks simultaneously.

For N=3 and K=2,

Input:

3 2

1

2

Output:

2

Explanation:

Person 1 will start task 1 at t=0. Person 2 will start task 2 at t=0.

At t=1, Person 1 will switch to 3rd task finishing its first task.

By the end of 2 minutes, all 3 tasks will be finished. So, minimum time taken is 3 minutes.

- 0of 0 votes
Given a string of size n consisting of 0s and/or 1s.you have to perform k queries and there are two types of queries possible.

"1"(without quotes): Print length of the longest substring with all '1'.

"2 X"(without quotes): where X is an Integer between 1 to n.In this query, you will change character at Xth position to '1' (it is possible that the character at ith position was already '1')

Input Format:

First Line of input contains n and k, where n is string length and k is the number of queries.

Next line contains a string of 0's and/or 1's of length n.

Each of next k lines contains query of any one type (i.e 1 or 2).

Output Format: For each query of type 1, print in new line the maximum size of subarray with all 1's.

Example Input:

5 7

00000

1

2 3

1

2 5

1

2 4

1

Example Output:

0

1

1

3

- 0of 0 votes
3. Complete the following function-

Node * alternateReverse( Node* head1, Node*head2){

// code goes here

}

Where ‘Node’ is the structure of a linked list node defined as:

struct Node{

int data;

struct Node *next;

};

alternateReverse() must remove the even number nodes from the linked list and append them to the end in reverse order. No extra space was allowed. It was for 5 marks.

Example:

Input-1->2->3->4->5->6

Output-1->3->5->6->4->2

Input-1->2->3->4->5->6->7->8->9

Output-1->3->5->7->9->8->6->4->2

- 0of 0 votes
Suppose you have an input character stream (StreamReader) and you have a list of pattens like ABCAS, ASGKT. KHTSD etc. You need to read the stream one by one character and you need to keep count on number of each pattern found so far and when EOF occures just print all the patterns along with count.

Example:

Input String: 011100010

Pattern 1: 011

Pattern 2: 010

Output:

011 => 1

010 => 1

- 0of 0 votes
You are given a rooted tree. The tree is not necessarily binary. The tree contains N nodes, labeled 1 to N. You are given the tree in the form of an array P[1..N] of size N. P[i] denotes label of the parent of node labeled i. For clarity, you may assume that the tree satisfies the following conditions.

The root of the tree is labeled 1. Hence P[1] is set to 0.

The parent of node T will always have a label less than T. Hence P[i] < i will always be true.

All nodes contain a mutable value (or, more simply, a variable), which is initially set to 0.

You are asked to perform several operations of the following type

ADD X Y: add Y to the value at node X.

ADDUP X Y: add Y to the value at node X. Then, add Y to the value at P[X] (i.e. the parent of X). The, add Y to the value at P[P[X]] (i.e. the parent of P[X]).. and so on, till you add Y to the value at root.

After you have performed all the given operations, you are asked to answer several queries of the following type

VAL X: print the value at node X.

VALTREE X: print the sum of values at all nodes in the subtree rooted at X (including X).

Input

The first line of input contains the number T, the number of test cases. Then follows the description of T test cases. The first line of each test case contains the numbers N, M and Q respectively (separated by single space character). N depicts the number of nodes. M depicts the number of operations you must perform. Q depicts the number of queries you must answer.

The next N lines contain a number each, depicting the array P[1..N]. Of course the number on the first such line is always 0.

The next M lines contain description of the respective operation. An operation will be either "ADD X Y" or "ADDUP X Y" (without the quotes). Please refer to the problem statement and sample I/O explanation for clarity on the meaning of the operations.

After the operations, the next Q lines contain description of the queries. A query will be either "VAL X" or "VALTREE X" (without the quotes). Please refer to the problem statement and sample I/O explanation for clarity on the meaning of the queries.

Output

Print the result of each query on a line by itself. Since the answer for some queries may be too large, please print the result modulo 1,000,000,007. Do not print any blank lines between test cases.

Constraints

1 ≤ T ≤ 10

1 ≤ N ≤ 50000

1 ≤ M ≤ 50000

1 ≤ Q ≤ 50000

1 ≤ X ≤ N

1 ≤ Y ≤ 50000

The input file will be smaller than 2 MB.

Sample Input

2

5 5 3

0

1

1

1

3

ADD 1 10

ADD 2 20

ADD 3 30

ADD 4 40

ADDUP 5 50

VAL 3

VALTREE 3

VALTREE 1

7 4 5

0

1

2

2

2

1

2

ADD 6 76

ADDUP 1 49

ADD 4 48

ADDUP 2 59

VALTREE 1

VALTREE 5

VAL 5

VALTREE 2

VAL 2

Sample Output

80

130

250

291

0

0

107

59

Explanation

In the first sample case, at the end of app the operations, the values at each of the nodes is as follows

1: 60

2: 20

3: 80

4: 40

5: 50

Also, the sum of the values of all the nodes in the subtree rooted at each of the nodes is as follows

1: 250

2: 20

3: 130

4: 40

5: 50

- 0of 0 votes
You are given a grid with 3 rows and N columns. Each cell in the grid contains the value 0 initially. You perform several operations of the following type on the grid

Pick a row, say r. Pick a start column and end column, say s and e. Of course 1 ≤ s ≤ e ≤ N. Now, set all values in the grid in row r, from column s to column e to 1.

After you perform all the operations, you wish to find subgrids in this grid (or rectangles, if you please) which contain only 1s. Most importantly, you wish to find the rectangle that has the largest area. Print the area of this rectangle.

Input

The first line of input contains a number T, the number of test cases. The first line of each test case contains the number N and M respectively, separated by a single space. N is the number of columns in the grid. M is the number of operations you perform on the grid. Each of the next M lines contain three integers R, C1 and C2 respectively to describe the operation. R is the row in which the operation is performed. C1 and C2 are the start and end columns respectively. You may assume that 1 ≤ C1 ≤ C2 ≤ N.

- 0of 0 votes
Implement zad-off-chu sequence for LTE eNodeB in c language?

- -2of 2 votes
There was given total physical energy H and total distance D. Five pace information speed and corresponding physical energy was given. Find the minimum time that is required in order to complete total distance D making sure that some of the physical energy does not exceed H

- 0of 0 votes
Robot hand movement

Given a (1) string message (consisting of only upper case alphabets), and (2) width of keyboard, output the movements required by an automated robot hand to print out the string message.

The robot hand can move right, left, up or down. It cannot move diagonally.

Ex 1:

String message: “HI”

Width: 26

Output: R8, T, R1, T

Ex2:

String message: “HELLO”

Width: 13

Output: R8, T, L3, T, R7, T, T, D1, L10, T

- 0of 0 votes
Given a set of strings (denoting URLs), like:

1. abc.pqr.google.com

2. pqr.google.com

3. pqr.google.net

4. yahoo.com

5. abc.yahoo.com

etc...

find an efficient way to find out how many times a particular string appears as a substring. For e.g., given the above set of strings, "google.com" appears twice; ".com" appears four times, "pqr.google.com" appears twice, and so on.

Follow up: How would you do this, if the input was no longer a URL (So, "abc.pqr.google.com" and "pqr.abc.google.com", both are valid)?

- 2of 2 votes
node {

node * left, * right;

}

Given a list of node to determine whether the node in the list can form a valid binary tree. several points of judgment

1. need to ensure that all left, right pointer point to the node inside list

2. no cycle

3. All node must be connected

Boolean isValidTree(List<Node> list){}

- 1of 1 vote
Given a matrix of N * M, given the coordinates (x, y) present in a matrix,

Find the number of paths that can reach (0, 0) from the (x, y) points with k steps (requires exactly k, k> = 0)

From each point you can go up, down, left and right in four directions.

For example, the following matrix:

----------

0 0 0 0 0

0 0 0 0 0

0 0 0 0 0

0 0 0 0 0

(x, y) = (1, 1), k = 2, the output is 2

- 0of 0 votes
Given a non-negative integer n, check if it is possible to build a pyramid of '*' and empty spaces where first row has one '*' and second has three '*' and so on.

For example-

Input: n =4 Output: True

Explanation : The pyramid can be build

*

***

Input: n = 9 Output: True

Explanation : The pyramid can be build

*

***

*****

Input: n = 6 Output: False

Explanation : The pyramid cannot be build as last row will be incomplete

*

***

**

- 0of 0 votes
alphaAndarabic

given a set of character, ex: 'A' 'B' 'C',

each char have its representative number:

A = 1, B = 13, C= 110;

when the char next to current index is smaller than current we add ex: CBA = 110+13+1

when the char next to current index is bigger than current we all the answer in prev will become minus sign(but not the last one) ABC -1 - 13 + 110 = 96;

calculate the number for each string input;

- -2of 6 votes
How will you test "Hello world" program?

- 0of 0 votes
How to Design Netflix.(System Design)

- 0of 0 votes
How to Design App-Store like google play.(System Design)

- 0of 0 votes
Given an array of strings, find out in how many cases is any of the anagrams of the string at location i, a substring of the string at location i+1.

Test Case I: ["ab", "ab", "abc", "bca"]

Answer: 3

Test Case II: ["ab","aqb"]

Answer: 0

- 0of 0 votes
Given a target sum, populate all subsets, whose sum is equal to the target sum, from an int array.

For example:

Target sum is 15.

An int array is { 1, 3, 4, 5, 6, 15 }.

Then all satisfied subsets whose sum is 15 are as follows:

15 = 1+3+5+6

15 = 4+5+6

15 = 15

- 0of 0 votes
Genarate and validate a magic matrix.A magic matrix is one in which the sum of every row,column,and every diagonal is same.One such matrix will be when every element in the matrix is same.generate and validate a magic matrix where every element is not the same