Adobe Interview Question for Applications Developers


Country: United States
Interview Type: Written Test




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

This is Analogous to Java's LinkedHashMap. Just create a LinkedList structure and attach new nodes (elements) as they are added, it's going to be in added order.

- Aasen May 30, 2013 | Flag Reply
Comment hidden because of low score. Click to expand.
1
of 1 vote

public class OrderedHashtable {

	private Hashtable<String, String> internalHashTable = new Hashtable<String, String>();
	private List<String> orderedKeyList = new ArrayList<String>();

	public void addToHashTable(String key, String value) {
		orderedKeyList.add(key);
		internalHashTable.put(key, value);
	}

	public String getValue(String key) {
		return internalHashTable.get(key);
	}

	public List<String> getKeys() {
		return orderedKeyList;
	}

}

public static void main(String[] args) {

		OrderedHashtable orderedHashtable = new OrderedHashtable();
		orderedHashtable.addToHashTable("a", "1");
		orderedHashtable.addToHashTable("b", "2");
		orderedHashtable.addToHashTable("c", "3");
		orderedHashtable.addToHashTable("e", "6");
		
		orderedHashtable.addToHashTable("f", "22");
		orderedHashtable.addToHashTable("g", "100");
		
		List<String> keys = orderedHashtable.getKeys();
		for (String key : keys) {
			System.out.println(orderedHashtable.getValue(key));
		}
	}

- Narita September 13, 2013 | Flag Reply
Comment hidden because of low score. Click to expand.
0
of 0 vote

you have to do using hashtable itself

- amit.grynch May 31, 2013 | Flag Reply
Comment hidden because of low score. Click to expand.
0
of 0 votes

Is additional space allowed, lets say another datastructure to store ordering of elements?

- parag June 27, 2013 | Flag
Comment hidden because of low score. Click to expand.
0
of 0 vote

In LinkedHashMap implementation doubly linked list is used to maintain the insertion order. This doubly linked list is different from linked list maintained by each bucket location in hashmap.

- Prashant Kesarwani June 02, 2013 | Flag Reply
Comment hidden because of low score. Click to expand.
0
of 2 vote

LinkedHashMap lists the elements in the order they were inserted.
TreeHashMap iterates over the elements in their natural order.

- Murali Mohan June 09, 2013 | Flag Reply
Comment hidden because of low score. Click to expand.
0
of 0 vote

store the keys dynamically in a array as they are added

- anoymous June 25, 2013 | Flag Reply
Comment hidden because of low score. Click to expand.
-1
of 1 vote

Can you explain the question? Is it asking about a method to do this, using an extra structure?

- EugenDu May 31, 2013 | Flag Reply
Comment hidden because of low score. Click to expand.
-1
of 1 vote

create Map<String, String> treeMap = new TreeMap<String, String>(unsortMap);
it will create sorted map from unsorted.
Please let me know if any issue concern.

- Sharma June 04, 2013 | Flag Reply
Comment hidden because of low score. Click to expand.
0
of 0 votes

TreeMap will have higher time complexity for search around O(logn). While hashtable has a complexity of O(1), compromising on search capability is not good. Ideally, implement a linked list wrapper over hashtable, so as in an element get inserted in hashtable, it also gets inserted in linked list, if it is removed from hashtable then it is also removed from linked list. Although an additional space is compromised. Also this question is about ordering of insertion and not about sorted order.

- parag June 27, 2013 | Flag
Comment hidden because of low score. Click to expand.
-2
of 2 vote

We cannot retrieve the elements in the hashtable in the same order as you have inserted. Because the basic design of hashtable is to provide searching in O(1) time.

- ijaz June 03, 2013 | Flag Reply
Comment hidden because of low score. Click to expand.
Comment hidden because of low score. Click to expand.


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