Pergunta de entrevista da empresa Yelp

The problem: I'm working on a collaborative code editor between 2 people. I have the text synchronizing across both screens. However, I have run into the problem illustrated below. Example Screen Person A Initially Screen Person B Initially |Cat Ca|t After pressing Enter on Screen1 Screen Person A After Screen Person B After | |Cat Cat >>>Expecter Output<<< Screen Person A After Screen Person B After |Cat Ca|t The content updates and the word cat shifts down a line. However, Person B's cursor is left in it's original position instead of moving down a line as expected. Implement the fixCursorRow method don't worry about updating the column. */ public class Cursor { public int column; public int row; public Cursor(int row, int column); } // diff comes from the other screen. // content is content of the current screen before diff is applied. // cursor is the cursor of the current screen. // diff format: // The diff contains all content from beginning to end of document. {{"1", "\n"}, {"0", "cat"}} // house -> horse = {{"0", "ho"}, {"-1", "u"}, {"1", "r"}, {"0", "se"}} // "0" -> equality, "1" -> addition, "-1" -> removal public Cursor fixCursorRow(String[][] diff, String content, Cursor cursor) { }