## Java Developer Interview Questions

- 0of 0 votes
Multi -level cache system design with different storage in each level.

Read Operation : – Minimum time to read a particular key from cache system. This should be followed by writing the key in all levels above it. Eg. if “key” is found at level ‘i’, add this key to cache present at 1 to i-1 level.

b. Write Operation: – Any write Operation should write in cache of all levels.

You can choose any algorithm for cache management like LRU, MRU.

- 0of 0 votes
https://codejamanalysis.wordpress.com/2017/03/18/crossover-problem-super-stack/

Any Optimized Solution to avoid TLE for 4 test cases. I have tried by implementing Stack using Doubly Linked List.

Still not able to pass test cases!!!

- 0of 0 votes
1. There is a list of 20 words. 10 of them are good works, and 10 of them are bad words. Write a regex of not more than 25 characters which would tell if given word is good or bad. Input would only contain one of these 20 words.

Good words: papa, book, home, cars, jolly, sugar, friend, mother, father, bloomiest

Bad words: ache, slow, torn, slum, boom, rival, wrong, cholera, revenge, arrogant

Input: book

Output: Good

Input: boom

Output: bad

- 0of 0 votes
Design a system like github.

- 0of 0 votes
What is the issue with this Producer Consumer Problem. Can you fix it.

`public class ProducerConsumerProb { public static void main(String[] args) { Container container = new Container(); Turn turn = Turn.PRODUCER; Producer p = new Producer(container, turn); Consumer c = new Consumer(container, turn); Thread pro = new Thread(p); Thread con = new Thread(c); pro.start(); con.start(); } public static class Producer implements Runnable{ Container container; Turn turn; public Producer(Container integer,Turn turn) { this.container = integer; this.turn = turn; } @Override public void run() { for(int i=0;i<10;i++){ Turn temp = null; while(true){ synchronized (turn) { temp = turn; } if(temp == Turn.PRODUCER){ break; } } synchronized (turn) { container.setI(i); turn = Turn.CONSUMER; } } } } public static class Consumer implements Runnable{ Container container; Turn turn; public Consumer(Container integer,Turn turn) { this.container = integer; this.turn = turn; } @Override public void run() { for(int i=0;i<10;i++){ Turn temp = null; while(true){ synchronized (turn) { temp = turn; } if(temp == Turn.CONSUMER){ break; } } synchronized (turn) { System.out.println(container.getI()); turn = Turn.PRODUCER; } } } } public static class Container{ Integer i = new Integer(0); public int getI() { return i; } public void setI(int i) { this.i = i; } } enum Turn{ PRODUCER,CONSUMER; } }`

- 0of 0 votes
There are hierarchy of class like super class and sub class. Yo have to make sure only one object can be create for any class using new keyword. How you implement the class.

- 0of 0 votes
List<Integer> list=Arrays.asList(1,2,3,4,5,6);

Iterator it=list.iterator();

while(it.hasNext()){

System.out.println(it.next());

}

The above code will iterate sequentially through 1 to 6. Can we iterate the same list alternatively so that it will print 1,3,5 without changing the while loop.

- 0of 0 votes
You are given a string S consisting of lowercase English letters denoting different types of candies. A substring of a string S is a string S' that occurs in S. For example, "bam" is a substring of "babammm". Each candy costs 1 unit. You can pick some continuous candies such that you can create a palindrome of length K by using some or all picked candies. Your task is to find the minimum cost to create a palindrome of length K.

Input Format:

First line contains string S.

Next line contains an integer T denoting the number of test cases.

Next T lines contain a single integer K.

Output Format:

For each test case, print minimum cost as mentioned above. If you cannot create a palindrome of length K then, simply print -1.

Constraints:

Constraints:

1≤|S|≤10^5

1≤T≤10

1≤K≤10^5

Sample Input

babammm

2

2

5

Sample Output

2

5

Explanation

Test Case 1: You can pick candies denoted by "mm" and create a palindrome of size 2. So the cost will be 2 units.

Test Case 2: You can pick candies denoted by "babam" and rearrange them, "bamab", to create a palindrome of size 5. So the cost will be 5 units.

- 0of 0 votes
Numbers with 4 are considered to be unlucky, floor numbers are skipped with numbers with 4; for a top level n, ask how many layers there are actually; for example n=20, that is 18 levels [Remove 4, 14]

- 0of 0 votes
Input unsorted integer array represents a list of coins,

find the minimum amount of money that cannot be formed by these coins, each coin can only be used once

E.g. {1,1} -> 3, {1,2,4} -> 8

- 0of 0 votes
public TreeNode{

int val = val;

TreeNode left, right;

public TreeNode(int val){

this.val = val;

}

given a tree and an API, delete a part of the nodes in the tree and return the forest formed after the node is deleted.

public List<TreeNode> deletenodes(TreeNode root, List<TreeNode> toDeletes){

}

example`1 / \ 2 3 / / \ 4 5 6 If you delete the 2 and 5 nodes, you will need to return to the forest [4, 1] \ 3 \ 6`

- 0of 0 votes
Given: Collection of sorted (ascending) iterators which return integer value.

Implement hasNext() and next() methods in SuperIterator class that next() method should return sorted values from all iterators.

Note that we can't load all iterators to memory, because they might get values from big file (1TB for instance) and it will lead to OutOfMemoryError.`/* iter1: 1, 4, 5, 20, ... iter2: 2, 10, 12, 50, ... SuperIterator.next() method should return: 1, 2, 4, 5, 10, 12, 20, 50, ... */ interface Iterator { boolean hasNext(); int next(); } class SuperIterator { public SuperIterator(Collection<Iterator> iters) { } boolean hasNext() { //TODO } int next() { //TODO } }`

- 0of 0 votes
There is a process sequence that contains the start and end of each process. There is a query sequence asking how many processes are running at a certain point in time. Please return the query result of the query sequence.

Example

Given logs = [[1, 1234], [2, 1234]], queries = [2], return [2].

Explanation:

There are 2 processes running at time 2.

Given logs = [[1, 1234], [2, 1234]], queries = [1, 1235], return [1, 0].

Explanation:

There is a process running at time 1, and 0 processes running at time 1235.

- -1of 1 vote
Given:

R number of Red Cards

B number of Black cards

K

Cards needs to be placed in a circle. Start from a position and for

every K moves remove that card And

repeat the process until all the cards are eliminated.

Question: Position the cards such that the red cards are completely

eliminated before the blacks cards are selected for elimination.

- 0of 0 votes
Given a BST convert it into new Data Structure that satisfies following conditions:

1. every leaf node's left ptr point to its parent and right ptr points to the next leaf

2. every non leaf node's left ptr points to its parent and right ptr is NULL

3. return the head and print the new DS`example: 7 / \ 5 9 / \ \ 4 6 10 output: head->4->5->7 | ->6->5->7 | ->10->9-7`

with optimal time and space complexity

- 0of 0 votes
input: "kitten%20pic.jpg"

output: "kitten pic.jpg"

%20 -> ' '

%3A -> '?'

%3D -> ':'

modify your input in place.

no string library functions.

void Decode(char[] str)

- 0of 0 votes
Given a string T of length n, partition it in n' "phrases" (p1, p2, ..., pn'),

such that

pi = pj + c, for some j<i, where + is string concatenation and c is a character

p0 = ''

p1 = pj + c where j < 1

T = p1 + p2 + ... + pn'

For example:

T = aababcabcd = a + ab + abc + abcd

p1 p2 p3 p4

- 0of 0 votes
Print a binary tree in vertical order using singly linked list...

- 0of 0 votes
find a points that has same distance to given three points

- 0of 0 votes
input is an int [] number is the car number parked in the parking lot, 0 for empty spaces

Output is also an int [] requires a method to convert the input into target array.

Each car can only be exchanged with a 0.

- 0of 0 votes
`Given a string s1, we may represent it as a binary tree by partitioning it to two non-empty substrings recursively. Below is one possible representation of s1 = "great": great / \ gr eat / \ / \ g r e at / \ a t To scramble the string, we may choose any non-leaf node and swap its two children. For example, if we choose the node "gr" and swap its two children, it produces a scrambled string "rgeat". rgeat / \ rg eat / \ / \ r g e at / \ a t We say that "rgeat" is a scrambled string of "great". Similarly, if we continue to swap the children of nodes "eat" and "at", it produces a scrambled string "rgtae". rgtae / \ rg tae / \ / \ r g ta e / \ t a We say that "rgtae" is a scrambled string of "great". give a string s, print all the scrambled string of it class Solution { public List<String> ScrambleString(String s) { } }`

- 0of 0 votes
Design a dictionary with historical records

t0: hdict = HistoricalDict ()

t2: hdict.set ('foo', 1)

t4: hdict.set ('foo', 2)

t5: hdict.get ('foo', t5) -> 2

t6: hdict.get ('foo', t3) -> 1

t7: hdict.get ('foo', t0) -> None

- 0of 0 votes
CSS colors can be defined in the hexadecimal notation "#rgb", a shorthand for "#rrggbb". For example, "#03f" is equivalent to "#0033ff". Suppose the similarity between two colors "#abcdef" and "#ghijkl" is defined as (-(ab-gh)^2 - (cd-ij)^2 - (ef-kl)^2), write a function that accepts a color in the "#abcdef" format and returns a "#rgb" color that is most similar to the input. For example, given "#09f166", "#1e6" should be returned.

- 0of 0 votes
`Given a binary tree, output the maximum EVEN sum along any path 10 / \ 2 5 / \ \ 1 101 13 Maximum even sum = 101 +2 +10 + 5 = 118`

- 0of 0 votes
convert a Sorted linkedList to complete BST

- 0of 0 votes
Given list of edge in the graph, find the number of reversed pairs,(1,2)

and (2,1) are such pair. Follow up: How to implement the distributed version.

- 0of 0 votes
An n * m matrix represents an array of computers, giving you a List <int []> that represents the coordinates of the broken computer.

Now we start from (0,0) repair computer requirements:

1. You must finish all the broken computers in the current line to get to the next line

2. To go to the next line, the mechanic must first return to the far left or right of this line

And then find repair each computer order that has the minimum access distance,

- -1of 1 vote
A robot can only be moved one step to the right (x + 1) at a time while moving upward or downward or horizontally (y-1, y + 1, y) , given the starting and ending positions, and a series of points must pass, ask how many kinds of ways from start to end.

- -1of 1 vote
Determine whether the inorder of n binary trees is the same

- 0of 0 votes
Give you a csv file There are three columns are id, parent, weight Then give you a class Node which has these three fields

But you also have the option of adding more fields for you to print out all the node's subwebs.

The definition of subweight is the sum of the node's weight plus the subweight of his children.