## Oracle Interview Questions

- 0of 0 votes
Round 3- Find the first duplicate occurence of a number in an array

- 0of 0 votes
Round 3 - puzzle-there are 8 coins out of which 1 coin is faulty.The faulty coin has a lesser weight than the rest of coins which all have the same weight.You have been given a weighing balance with a pulley.Find the faulty coin

- 0of 0 votes
Round 3 - Write a java program to print a matrix in spiral

- 0of 0 votes
Round 2 - Write a java program to determine if a 10 digit number is magic number.A number is magic number if it has all digits between 1 to 6 occuring in it or if it has any number between 0 to 9 occuring thrice or if it contains three consecutilvely increasing or decreasing digits differing by 1 example 345 or 543

- 0of 0 votes
Round 2 - write java code to create the following pattern

*

* * *

* * * * *

* * * * * * *

* * * * * * * * *

- 0of 0 votes
Round 1-question 1 - given an array of stock prices for n days.Write an algorithm to maximize the profit of a customer such that he can buy and sell only once.

-Question 2

Prove that complexity for searching in arraylist is o(n)

and adding is o(1)

- 0of 0 votes
write java code to create the following pattern

*

* * *

* * * * *

* * * * * * *

* * * * * * * * *

- 0of 0 votes
Round 2- puzzle given 4 pair of socks of different colors(Red,green,blue and yellow)

Arrange the socks in such a way such that there are exacly 4 socks between the yellow socks,3 between the red ones and 2 between the green

- 0of 0 votes
Round 1-Question 2

Prove that complexity for searching in arraylist is o(n)

- 0of 0 votes
Round 1-Question 1

1)Given an array of stock prices for 7 continuous days.Write an algorithm to maximize the profit for a customer who buys stock on any day and sells it later.Buying and selling can happen only once and selling should happen on any day after buying

- 0of 0 votes
Consider a game similar to tennis. The game can be palyed by 'N' number of players. The player has to win atleast 'M' games to win a set.

Print all the possible combination of winning set for all the payers.

Where

2 <= N

1 <= M

For Example if [A, B] are the players and

if M = 2 The player has to win atleast '2' games to win a set.

The output will be

A A

A B A

B A A

B B

B A B

A B B

if M = 3 The player has to win atleast '3' games to win a set.

The output will be

A A A

A B A A

A A B A

B A A A

B B B

B A B B

B B A B

A B B B

Write an algorithm to print all the possible combination of winning set for all the payers

- 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

- 0of 0 votes
Coin change problem with finite number of coins available

denominations of coins = {1,2,3}

count of coins = ={1,1,3}

find the number of ways for getting change for S=6

- 0of 0 votes
how to create an object on the stack.

and also make sure that only 5 objects are created for the class

- 0of 0 votes
Given a random function with equal probability of getting 1 or 0 ie 50% each. write a custom function which uses the above random function such that your function should return 1 with 75% probability and 0 with 25% probability

- 0of 0 votes
given an arraylist of say 50 lac entries and an empty queue, Design a multi-threading bases system which can copy the items in arraylist in a queue parallely

How many threads can be spawned based on what criterion ? Basically the interviewer wanted to know how to implement an algorithm where we can design number of threads to be spawned ?

- 0of 0 votes
Design a system java same as relational database.

For example,

You Have employee table as bellow:`ID | Name | Manager | Salary`

Now you can execute queries like :

`select * from Employee where ID= ' something' select * from Employee where Name= ' something' select * from Employee where salary = ' something'`

In same way you have a class Emplyee as bellow:

`class Employee { String ID; String Name; String Salary; String Manager; }`

Now I want to query on this class as same as the sql queries above,

How can I do it efficiently?

The code should be optimized on time complexity and space complexity.

- 0of 0 votes
Input Parser and Processor

Problem

Implement a java program for querying data from a java object. Java object need to be constructed based on text data provided to program.

The parser should be generic to parse any input confirming to the hierarchical format similar to the one mentioned in sample

The Content of the file

[employee]

name=john

age=30

salary=100

[address]

houseno=221b

street=bakerstreet

[location]

place=xyz

state=abc

country=123

[/location]

[/address]

designation = srDeveloper

[/employee]

Sample Input and Output

employee.name Output John

employee.address.houseno Output 221b

employee.address.location.state Output abc

employee.manager Output NOT_FOUND

The program should work any object data specified as input file.

- 1of 1 vote
Design and implement LRU Cache.

- 0of 0 votes
Identify the output

`Class A { } Class B { } B b = new B(); A a = (A) b; sysout(b.getClass()); sysout(a.getClass());`

- 0of 0 votes
Given Two classes A & B. How will B know if an instance of A is already created?

- 0of 0 votes
Mark likes to listen to music while travelling. His iPod™ contains N songs and he wants to listen to L (not necessarily different) songs during a trip. So he creates a playlist such that:

• Every song is played at least once.

• A song can be played again only if at least K other songs have been played

Mark wants to know how many different playlists are possible. Can you help Mark determine this number? As the number can be very large, display number modulo 1,000,000,007.

You are given N, K and L.

- 0of 0 votes
Mr. Xhas recently shut down his factory and wants to sell off his metal rods to a local businessman. Mr. Octopus has many rods whose length are represented by array - lengths = {lengths[0], lengths[1], lengths[2], ...}.

The local businessman will only pay for rods that have same length. Let's say Mr. Octopus plans to sell rods of lengthL only. Then he had to cut each rod 0 or more time, so that he can maximize the profit. The remaining rods whose length is not L will be thrown away. Price of N rods of length L will be N × L × unit_price. Also note that for each cut made to a rod, he had to pay cut_cost.

What is the maximum amount of money Mr. Octopus can make? You have to complete the function int maxProfit(int cut_cost, int unit_price, int[] lengths).

Constraints

• lengths will contain between 1 to 50 elements, inclusive.

• Each element of lengths will lie in range [1, 10,000].

• 1 ≤ unit_price, cut_cost ≤ 1,000.

Sample Input #1:

cut_cost = 1

unit_price = 10

lengths = [26, 103, 59]

Sample Output #1:

1770

- 2of 2 votes
Got this sh***y problem.

A judge tells a person under trial that if your answer is true, you get 2 year sentence and if your answer is false you get 3 year sentence. The person under trial gives an answer which made the judge set him free. What did he say?

- 2of 2 votes
Traverse a given 2D matrix from given source to destination in such way that every cell should be visited exactly one time (we have to cover all cells of matrix exactly once and have to reach at destination).

- 1of 1 vote
Given a BST, replace each node with the sum of the values of all the nodes that are greater than that node. Only constraint being that I was not allowed to use any global or static variable.

- 1of 1 vote
Giving a number T, print out all possible ways to get to T.

For example

T= 5

1 + 1 + 1 +1 +1

2 + 1 + 1 + 1

3 + 1 +1

2 + 2 + 1

4 + 1

3 + 3

Note that, 3 + 2 is equal than 2 + 3, so you don´t have to print both cases.

What is the time complexity? ( VERY IMPORTANT TO ELABORATE ) Brute force is not allow.

- 1of 1 vote
Serling Enterprises buys long steel roads and cuts them into shorter rods, which it then sells. Each cut is free. The management of Serling Enterprises charges for a road of length i inches. Road lengths are always an integral number of inches.

The rod-cutting problem is the following: Given a rod of length n and a table of prices V for {1,2...n} determine the maximum revenue Rn obtain by cutting up the road and selling the pieces.

Table:`length i 1, 2, 3 ,4 ,5 , 6 , 7 , 8 , 9, 10 price Pi 1, 5, 8, 9, 10,17,17,20,24,30`

- 1of 1 vote
Implement the queue using stack

- 1of 1 vote
Implement the stack using queue