Oracle Interview Question for Software Architects


Country: India
Interview Type: In-Person




Comment hidden because of low score. Click to expand.
3
of 3 vote

Create a hashmap with key as id and value as Employee object.

Create two more hashmap as below
1. First HashMap with key as name and value as id
2. Second HashMap with key as salary and value as id.

Now, when getEmployeeByName(String name) is called, it get the employee id corresponding to the name by looking up in the first hashmap. Use the key to get Employee from master hashmap

Similarly for getEmployeeBySalary.

- Anonymous August 26, 2015 | Flag Reply
Comment hidden because of low score. Click to expand.
0
of 0 votes

Exactly what I was thinking. However if we need functions like name like 'a%' or name like '%a%' or name like '%a' I would have a Map<Character, NameInfo>. Where NameInfo has 3 binary trees. Tree 1 has entry for all IDs with names starting with that Character, Tree 2 has all ending with it and Tree 3 with all names containing it. This is a lot of space I know but makes the retrieval faster.

- Asif Garhi September 05, 2015 | Flag
Comment hidden because of low score. Click to expand.
2
of 2 vote

We can have three different hash tables based on ID, name and salary. Also, each table is like a bucket, which contains a list of all employees with same ID (or name or salary).
In this case each query will be answered in O(L) in which L is the number of result items, which is the most efficient time complexity we could have.
Note that for inserting an employee we should insert it in three different tables, which causes to have space complexity of 3*N(N is number of all employees) which is O(N) in total.

- MehrdadAP August 17, 2015 | Flag Reply
Comment hidden because of low score. Click to expand.
0
of 0 vote

Create an interface with method called IEmployee
with method declaration :

FindAllEmployee();

FindEmployeeById(int employeeId);

UpdateEmployee(int employeeId);

DeleteEmployee(int employeeId);

----------------

Now implement the interface in a class

(using C#)

EmployeeRepositoryClass : IEmployee

{

now define all the methods

}

Now wherever we are using the employee object

Employee = new Employeee();

List<Employee> empList = FindAllEmployee();

- Paro August 17, 2015 | Flag Reply
Comment hidden because of low score. Click to expand.
0
of 0 vote

1 - Create one LinkedHashMap and prepare a key for this map comprising of ID, Name and Salary.

2 - Now when gets a search criteria on those columns (ID,Name,Salary) or any of its combination, iterate though the Map collection and pull the designed records/objects.

- Anonymous August 24, 2015 | Flag Reply
Comment hidden because of low score. Click to expand.
0
of 0 vote

Write one method with with query string and value array.
public void pojoToSQL(String query, String[] values) {
//Create a hashmap with Key as pojo field and value as corresponding db field.
//parse the query string and replace pojo fields with corresponding db columns
//make db connection and execute query in statement.

}

- Venkat September 20, 2015 | Flag Reply
Comment hidden because of low score. Click to expand.
0
of 0 vote

1. create a method with arguments query string and value array
2. create a hashmap with pojo field as key and db field as key
2. parse query string and replace pojo fields with db fields by looking up hashmap.
4. make connection and execute query in statement.

- damineni.rathnam September 20, 2015 | Flag Reply
Comment hidden because of low score. Click to expand.
0
of 0 vote

We can implement this using reflection.
1) Write a query parser which will parse the query.
2) The from clause contains class name. Load it using forName
3) The select clause contains few or all fields of the class mentioned in from clause.
4) Query may contain where clause or may not. If contains, then where clause may use "=" or like or >= or <= or > or <.
5) Using reflection we can extra the fields and compare the value with the where clause field values. If matches, then add it in some data structure which we want to return. Else ignore that record and move one.

- XYZ October 12, 2015 | Flag Reply
Comment hidden because of low score. Click to expand.
0
of 0 vote

class TestRDB

- Ashwin De March 10, 2016 | Flag Reply
Comment hidden because of low score. Click to expand.
0
of 0 vote

I would create like below,

1) One hashmap with ID as key and Employee Object as value
2) Create a BST for Name and it has id. (so that search can be faster) - another gentleman suggested three trees for %a, %a%,a%...that's nice too..
3) Create a BST for Salary and ID. or B+ Tree in case they are looking for range queries on Salary.

- rocky August 02, 2016 | Flag Reply
Comment hidden because of low score. Click to expand.
0
of 0 vote

Assume that employees are stored in array Employee[] employeeArr
1. Implement comparator interface using fields (ID,Name,Salary, Manager.. ) of the class.
2. Use Arrays.binarySearch( employeeArr, "searchField","SearchComparator") to search employee using specific information. E.g if searchField is ID then use comparator for ID field and pass appropriate information to binarySearch call.
3. You will be able to search values in O(log n).
This solution give good performance while keeping memory footprint low.

- vaibhav Joshi September 30, 2016 | Flag Reply
Comment hidden because of low score. Click to expand.
0
of 0 vote

DATASTRUCTURE:
- BST or Hash Maps.

COMPLEXITY:
- O(1) for searching for an employee Id using Id as a Key in a hash map (Id will be unique. So, makes more sense to use a hash map).

ONE WAY:
- O(N)..Worst case if all the employees have the same name. Then there will be just one key and a list of employee objects associated with it. But if you simply want to print all the employee objects with the searched name, then it will be O(1). This will be exactly like querying.
- O(N)..Worst case if all the employees have the same salaries. Then there will be just one key and a list of employee objects associated with it. But if you simply want to print all the employee objects with the searched salary, then it will be O(1). This will be exactly like querying.

SECOND WAY (We won't need hash map for this alternative):
-Load all the employee objects into 2 binary search trees. The criteria for loading the two BSTs will be Name and Salary respectively (alphabetically for name and value-based for salary). That way the search would be O(logn).
-Moreover, we can also have searches such as "a%","%a" or "%a%" (where 'a' can be any charater or string of characters) using the BST which will fetch us the data in O(logn)....(AS ALREADY HIGHLIGHTED BY SOMEONE ELSE).

DESIGN:
- Create an Interface "IEmployee".
public Interface IEmployee{
public Employee getUsingId(int Id);
public Employee getUsingName(String nm);
public Employee getUsingSalary(int sal);
}

Implement the above interface in the Employee class.

- Addy November 12, 2016 | Flag Reply


Add a Comment
Name:

Writing Code? Surround your code with {{{ and }}} to preserve whitespace.

Books

is a comprehensive book on getting a job at a top tech company, while focuses on dev interviews and does this for PMs.

Learn More

Videos

CareerCup's interview videos give you a real-life look at technical interviews. In these unscripted videos, watch how other candidates handle tough questions and how the interviewer thinks about their performance.

Learn More

Resume Review

Most engineers make critical mistakes on their resumes -- we can fix your resume with our custom resume review service. And, we use fellow engineers as our resume reviewers, so you can be sure that we "get" what you're saying.

Learn More

Mock Interviews

Our Mock Interviews will be conducted "in character" just like a real interview, and can focus on whatever topics you want. All our interviewers have worked for Microsoft, Google or Amazon, you know you'll get a true-to-life experience.

Learn More