VMWare Inc Interview Question for Staff Engineers


Country: United States
Interview Type: Phone Interview




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

function decode(str) {
  var i = 0;
  var decodes = {
    'startWith3' : [],
    'startWith2': []
  };

  function breakString(s) {
    if(s.length < 2) {
      return s;
    }
    var subStr3Digit = parseInt(s.substring(0, 3))
    if(subStr3Digit > 99 && subStr3Digit <= 126) {
      decodes['startWith3'].push(subStr3Digit);
      return breakString(s.substring(3));
    }
    var subStr2Digit = parseInt(s.substring(0, 2))
    if(subStr2Digit > 9 && subStr2Digit <= 99) {
      decodes['startWith2'].push(subStr2Digit);
      return breakString(s.substring(2));
    }
  }

  breakString(str);
  var decodeStr = '';
  var iStr = str;
  while( iStr.length >=2) {
    //console.log(iStr);
    var stuff_3 = parseInt(iStr.substring(iStr.length - 3));
    var stuff_2 = parseInt(iStr.substring(iStr.length - 2));
    var stuff3Last = decodes['startWith3'][decodes['startWith3'].length - 1];
    var stuff2Last = decodes['startWith2'][decodes['startWith2'].length - 1];

    if(stuff3Last !== undefined && stuff3Last === stuff_3){
      decodeStr = decodeStr + String.fromCharCode(stuff_3)
      iStr = iStr.substr(0, iStr.length - 3);
      decodes['startWith3'].pop();

    } else if(stuff2Last !== undefined && stuff2Last === stuff_2){
      decodeStr = decodeStr + String.fromCharCode(stuff_2)
      iStr = iStr.substr(0, iStr.length - 2);
      decodes['startWith2'].pop();
    }
  }
  return decodeStr;
}

- echorohit February 20, 2018 | Flag Reply
Comment hidden because of low score. Click to expand.
0
of 0 vote

solutions = []
currentSolution = ''
unprocessed = ''


def decode(s):
    flipped = s[::-1]
    global solutions
    global unprocessed
    global currentSolution
    currentSolution = ''
    unprocessed = flipped
    _decode()
    return solutions


def is_valid(split):
    if split.startswith('0'):
        return False
    value = int(split)
    if value < 10 or value > 126:
        return False
    return True


def _decode():
    global unprocessed
    global currentSolution
    global solutions
    if len(unprocessed) == 0:
        solutions.append(currentSolution)
    else:
        possible_splits = list()
        possible_splits.append(unprocessed[0:2])
        possible_splits.append(unprocessed[0:3])

        for split in possible_splits:
            if is_valid(split):
                decoded_character = chr(int(split))
                currentSolution += decoded_character
                unprocessed = unprocessed[len(split):]
                _decode()
                currentSolution = currentSolution[0: len(currentSolution) - 1]
                unprocessed = split + unprocessed


def main():
    final_solutions = decode('0018014111117811180180110127')
    print(final_solutions)


if __name__ == '__main__':
    main()

- jhavarp April 11, 2018 | 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