Company: Expedia

Difficulty: medium

Problem Statement

Text Editor Prototype You are building a prototype of a text editor. The editor holds a document , which is a string that is initially empty, and a caret (cursor) that sits between characters. The caret position is the number of characters that lie to its left, so it is initially 0 and can range from 0 (before the first character) to the current length of the document (after the last character). You are given n commands, which must be executed in the given order. Exactly one of the commands writes to the answer. Commands Each command is an operation name followed by one argument. For Insert the argument is a string s ; for every other operation the argument is an integer x . Insert s — insert the string s into the document at the caret position, then move the caret to the right end of the inserted text (i.e. right by |s| positions). For example, if the document is abcdef with the caret written as abc|def , then Insert XYZ makes the document abcXYZdef with the caret at abcXYZ|def . Prin

More Expedia OA questionsInterview experiences