## Java Developer Interview Questions

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

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

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

- 0of 0 votes
Give a chessboard, check if a group of white chesses are surrounded by all black chesses.

- 0of 0 votes
Given a list of relationship of report

A reported to D, D reported to Z, who are reported to Z

- 0of 0 votes
Give the structure of a directed graph

START -> a -> b -> c -> END

If a word can start from start and end at END, then we think the word is in this diagram

For example, the string "abc" is consistent, but "ab" does not match,

Although "ab" is also inside the graph, b's next is "c" instead of END, so it's not legal word

(Note: each node can have more than one next)

1. According to the problem, design the data structure

Write a function, input is START and a string, to determine whether the string is a valid word

3. follow up, if the graph has cycle, how to do?

4. If the graph has repeated characters how to do?

- 0of 0 votes
how to check is a small matrix appear in a big matrix

boolean isSubmatrix(int[][] small, int[][] big)

- 0of 0 votes
You have to cut a wood stick into pieces. The most affordable company, The Analog Cutting Machinery,

Inc. (ACM), charges money according to the length of the stick being cut. Their procedure of work

requires that they only make one cut at a time.

It is easy to notice that different selections in the order of cutting can led to different prices. For

example, consider a stick of length 10 meters that has to be cut at 2, 4 and 7 meters from one end.

There are several choices. One can be cutting first at 2, then at 4, then at 7. This leads to a price

of 10 + 8 + 6 = 24 because the first stick was of 10 meters, the resulting of 8 and the last one of 6.

Another choice could be cutting at 4, then at 2, then at 7. This would lead to a price of 10 + 4 + 6 =

20, which is a better price.

Your boss trusts your computer abilities to find out the minimum cost for cutting a given stick.

- 0of 0 votes
Given an aray with ['a1', 'a2', .....'aN', 'b1', 'b2', ....'bN', 'c1', 'c2', .....'cN'],

stagger the subarrays so it becomes ['a1', 'b1', 'c1', 'a2', 'b2', 'c2', ...'aN', 'bN', 'cN']. The optimal solution requires linear-time

sorting and a constant space complexity.

- 0of 0 votes
How to design a spreadsheet program? How do you know to update a field after another

field was changed that it depended on?

- 0of 0 votes
Given a set of points in the 2D coordinate system, find the radius of the

smallest circle which encompasses

all the given points

- 0of 0 votes
Try to come up with a combination of two data structures to implement a

data structure that supports search,

delete in O(1) time and insert in O(n) time.Try to come up with a combination of two data structures to implement a

data structure that supports search,

delete in O(1) time and insert in O(n) time.