Yahoo Interview Question for Software Engineer / Developers


Team: Search
Country: United States
Interview Type: In-Person




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

Use maps or maps.

class SpreadSheet {		
	private static final int MAX_CELL_INDEX = 65000;	
	private final Map<Integer, Map<Integer, String>> data = new HashMap<>();
	
	public void setValue(int row, int column, String value){		
		checkRowAndColumnIndex(row, column);		
		Map<Integer, String> columnsMap = data.get(row);		
		if( columnsMap == null ){
			columnsMap = new HashMap<>();
			data.put( row, columnsMap );
		}		
		columnsMap.put(column, value);
	}
	
	public String getValue(int row, int column){		
		checkRowAndColumnIndex(row, column);		
		Map<Integer, String> columnsMap = data.get(row);		
		if( columnsMap != null ){
			return columnsMap.get(column);
		}		
		return null;
	}

- m@}{ November 09, 2012 | Flag Reply
Comment hidden because of low score. Click to expand.
-1
of 1 vote

why don't you use hashtable?
What is the different between hashtable and hashmap?

- Jerry April 14, 2013 | Flag
Comment hidden because of low score. Click to expand.
0
of 0 votes

Why cant we use a simple two dimensional array in place of hashmap in the above example?

- Kim September 12, 2013 | Flag
Comment hidden because of low score. Click to expand.
0
of 0 votes

@Kim: Because 2D array reserves O(r*c) space even if we will be using only few cells(as it is sparse)

- mytestaccount2 March 03, 2015 | Flag
Comment hidden because of low score. Click to expand.
-1
of 1 vote

csr and csc, csrc formats are standard for sparse matrices.

- huha November 09, 2012 | Flag Reply
Comment hidden because of low score. Click to expand.
0
of 0 votes

can you explain in detail ?

- codemonkey November 09, 2012 | Flag
Comment hidden because of low score. Click to expand.
0
of 0 votes

en.wikipedia.org/wiki/Sparse_matrix

- dgbfs November 09, 2012 | Flag
Comment hidden because of low score. Click to expand.
0
of 0 votes

CSC or CRC is efficient for matrix operation

I would suggest using DOK which a dictionary mapping the tuples (row, column) to the value

- dgbfs November 09, 2012 | Flag


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