## Coding Interview Questions

- 0of 0 votes
{1, 1, 0, 0, 0},

{1, 1, 0, 0, 0},

{1, 0, 0, 1, 1},

{0, 0, 0, 0, 0},

{1, 0, 1, 0, 1}

write a function to return the size of max cluster and coordinate of it, max cluster size to the above example is 5.

- 0of 0 votes
given a string, characters can be shuffled to make a paliandrome.

What is the minimum possible number of insertions to original string needed so that it will be a palindrome (after shuffling, if required).Input

T -> number of test cases

T number of Strings in different lines`import java.util.Arrays; import java.io.InputStreamReader; import java.io.BufferedReader; public class Xsquare{ public static void main (String[] args) throws Exception{ BufferedReader br = new BufferedReader(new InputStreamReader(System.in)); int limit = Integer.parseInt(br.readLine()); int [] alphabets = new int[26]; while(limit-- >0){ String input = br.readLine(); Arrays.fill(alphabets,0); char [] inpChar = input.toCharArray(); int sum = 0; for (int i=0;i<input.length();i++){ int pos = (int)inpChar[i] - (int)'a'; alphabets[pos]+=1; } for(int i=0;i<26;i++){ if(alphabets[i]%2==0) sum+=0; else sum+=1; } if(sum<=0) sum=0; else sum-=1; System.out.println(sum); } } }`

This is the code I submitted online. But it was not accepted as solution. What is the correct approach to this question?

- 0of 0 votes
Given this set of interfaces:

public interface Processor<T,U> {

U process(T arg);

}

public interface Splitter<T,V> {

V[] split(T arg);

}

public interface Worker<V,W> {

W processPart(V part);

}

public interface Aggregator<U,W> {

U aggregate(W[] args);

}

and this scenario:

Please provide

1. An implementation of Processor interface

2. Test cases for testing the implementation

http://webcache.googleusercontent.com/search?q=cache:QW8rjNE9dDwJ:stackoverflow.com/questions/29716343/how-to-implement-processort-u-using-java-generics+&cd=1&hl=en&ct=clnk&gl=in

- 1of 1 vote
write custom pattern match function to match following logic

.’ Matches any single character.

‘*’ Matches zero or more of the preceding element.

The matching should cover the entire input string (not partial).

The function prototype should be:`bool isMatch(const char *s, const char *p) Some examples: isMatch(“aa”,”a”) → false isMatch(“aa”,”aa”) → true isMatch(“aaa”,”aa”) → false isMatch(“aa”, “a*”) → true isMatch(“aa”, “.*”) → true isMatch(“ab”, “.*”) → true isMatch(“aab”, “c*a*b”) → true isMatch(“ccca”, “c*a”) → true`

- 0of 2 votes
Write a program to test whether a string and all strings that can be made using the characters of that string are palindrome or not.

Eg:

Input Output

mmo True

yakak True

travel False

Note : Please do not use any inbuilt functions.

- 3of 3 votes
Sparse number is an integer if there are no adjacent 1 in it's binary representation.

Like: 5 -> 101 (no adjacent 1)

9 -> 1001 (no adjacent 1)

while 6-> 110 is not sparse number.

Now you are given an integer find the NEXT BIGGER sparse number.Please mind 'it is next bigger'.

- 0of 0 votes
Write a program to modify the string in following pattern,

Change odd words to uppercase and Reverse the even words. Make sure that the spaces (multiple) between the words remains as it is.

E.g.:

Input : "This is a test String!!"

Output: "THIS si A tset STRING!!"

- 0of 0 votes
hi i have one question, for example : convert A2B2A to A3B2, that is simple but but string can also have parentheses like AB3((CB)2(CB)2)3 which to converted to AB15C12

- 0of 0 votes
You are given heights of n candles .

First day you lit one candle

second day you need to lit two candles

Third day you need to lit three candles

..........

........

till possible.

After lighting candles the height of candles deduced by 1 each day.You can also extinguish any candle you want but only at the end of day.

So you need to tell the maximum number number of days , you can carry on lighting the candles.

Example : there are three candles of heights {2 , 2 ,2 }

Answer : 3

1.You light first candle on day one. heights -> {1,2,2}

2.You light second and third and extinguish first one . heights ->{1, 1,1}

3.You light all the candles. heights -{0,0,0}

- 0of 0 votes
Input any string, count the maximum depth of parenthesis nesting, i.e. "abc(123(xyz))m(((n)))o" -> 3.

if input is null or contains a mismatch "a)b(c" or "a(b"

Also some other samples:

(((()))) -> 4

()()()() -> 1

- 0of 0 votes
Convert a binary tree into a In Order traversal circular list re-purposing the node's pointers Left & Right as Previous and Next respectively.

Hint: A single node Left & Right points to itself.

Note: This is not a binary search tree.

- 0of 0 votes
Write a function that takes an array of numbers and returns the maximum and minimum values.

Give BigO for runtime.

(This is a basic coding question. There are no real tricks or shortcuts.)

- 1of 1 vote
Given a list of employees and their bosses as a text file , write a function that will print out a hierarchy tree of the employees.

Sample input =

Sam, Ian, technical lead, 2009 / Ian, NULL, CEO,2007/ Fred, Sam, developer, 2010

The format is name, supervisor, designation, year of joining

The output should be

Ian CEO 2007

-Sam Technical lead 2009

- -Fred Developer 2010

- 0of 0 votes
(Variant of Children-Sum Problem better than O(n^2))

Given a tree, implement a function which replaces a node’s value with the sum of all its childrens’ value, considering only those children whose value is less than than the main node’s value.

Eg: input = 60->50->80->40 , output = 90->40->40->0

- 0of 0 votes
Given a function rev(int i) which reverses the segment of array ar[] from 0-i, Implement a function sort() using rev().

- 0of 0 votes
Find if a given number can be expressed in the form of p^q, where p and q are integers

- 0of 0 votes
Find all palindromes in a given string. Single letters are also considered as palindromes.

- 0of 0 votes
Given a number A, find the smallest number which has only 1s and 0s as its digits which divisible by the number A. For example: if the given number A is 4, the smallest number with 1s and 0s is which is divisible by 4 is 100.

- 1of 1 vote
{{

There are 3 machines M1, M2 and M3. Each machine is 90% full of its capacity with integers. Now you have to sort all the integers combined and then store the first 1/3rd in M1, second 1/3rd in M2 and last 1/3rd in M3.

Your objective is to minimize the number of sort operations and number of data transfer operations.

Each sort operation/data transfer operation is counted as 1 irrespective of the count of values that are being sorted/transferred.

}}

- 1of 1 vote
How to find efficiently the minimum of an array of integers that is the maximum of other arrays?

Example:

A = [126, 110, 130]

B = [125]

C = [105, 115]

The minimum element of array A that is the maximum of B and C is 126

- 0of 0 votes
Write a function that takes a string as an input and outputs an integer, e.g. turning "1234" into 1234.

- 0of 0 votes
Java coding

Given a file with the following entry

ID EMp_Name Manager_ID

1 "ABC" 2

2 "PRW" Null

3 "DEF" 2

4 "PRE" 3

5 "DKF" 4

Print the Respective Manager hierarchy in the below format

PRW | ABC |

| DEF | PRE | DKF

The Employe Manager table can be extended to Hold N entry

- 0of 0 votes
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 0 votes
how to design a relation functionality. similar to facebook , how to hold friends objects for a user profile , so that that is easily searchable . how to use cache for this?

- 3of 5 votes
You are given two integer arrays A and B .

1<=i<=len(A) so i is iterator of array A

1<=j<=len(B) so j is iterator of array B

find all the pairs(i,j) such that : i < j and A[i]>B[j]

- 3of 3 votes
given a pre and post order kindof a traversal (2 arrays) create an n-ary treee out of it with struct of the form :

struct node {

int data;

struct node *child[MAX];

int child_num;

}

- 0of 0 votes
given matrix like :

a b e d

b c f e

a b d d

….

find the longest path of consecutive alphabets given a starting alphabet. You can move in all 8 directions. for eg. a->b(right)->c(down)->d(diagnal down)… len = 4 , find max such len

- 0of 0 votes
You are given a rectangular grid with 2 rows and N columns. The top row is labeled 1 and the bottom row is labeled 2. The columns are labeled from 1 to N in increasing order. Each cell in the grid contains a single character.

Consider a hamiltonian walk in this grid. Meaning, pick a starting cell, say (i,j), and consider a path that starts from (i,j) and goes through every cell in the grid exactly once. Note that you can only walk to adjacent cells, or cells that you share a common edge with. There may be several such paths. Let us concatenate the characters in the order in which the cells are visited during a walk. The string formed can be called the string for the walk.

Among all the possible walks, and their respective strings, find out the lexicographically smallest string. We know that the length of the strings are all the same - to be precise, 2N. Thus, the lexicographically smallest string is simply the alphabetically smallest string if you compare the characters from left to right.

Input

The first line of input contains a number T, the number of test cases. Then follow T test cases. Each test case contains 3 lines. The first line contains the number N, the number of columns in the grid. It is well known of course that the grid contains 2 rows. The next two lines contain the description of the grid in the form of two strings; the string of N characters in row 1 from left to right and the string of N characters in row 2 from left to right, respectively. Each character will be a lowercase engish letter.

Output

Output a single line for each test case. The line must contain a string with 2N characters. This string should be the lexicographically smallest string for some hamiltonian walk in the grid.

Constraints

1 = T = 100

1 = N = 10

Sample Input

2

3

abc

def

10

ababaaabab

bababababa

Sample Output

abcfed

aaababababababababab

Explanation

In the first test the possible strings are { abcfed, adebcf, adefcb, badefc, bcfeda, cbadef, cfedab, cfebad, dabcfe, dabefc, defcba, edabcf, efcbad, fedabc, fcbade, fcbeda }. The smallest string is abcfed.

- 1of 1 vote
given n > 0 fair dice with m > 0 "sides", write an function that returns a histogram of the frequency of the result of dice rolls. For example, for two dice, each with three sides, the results are:

(1, 1) -> 2

(1, 2) -> 3

(1, 3) -> 4

(2, 1) -> 3

(2, 2) -> 4

(2, 3) -> 5

(3, 1) -> 4

(3, 2) -> 5

(3, 3) -> 6

And the function should return:

2: 1

3: 2

4: 3

5: 2

6: 1

- 6of 6 votes
Given a string (1-d array) , find if there is any sub-sequence that repeats itself.

Here, sub-sequence can be a non-contiguous pattern, with the same relative order.

Eg:

1. abab <------yes, ab is repeated

2. abba <---- No, a and b follow different order

3. acbdaghfb <-------- yes there is a followed by b at two places

4. abcdacb <----- yes a followed by b twice

The above should be applicable to ANY TWO (or every two) characters in the string and optimum over time.

In the sense, it should be checked for every pair of characters in the string.