Git Product home page Git Product logo

engineering_interview_questions's Introduction

Engineering Interview Questions

A collection of sample interview questions to ask engineers.

Data Wrangling

String Encoding

Build a function that takes as input a string of letters and returns an encoded version of the string. The encoding scheme converts letters regardless of case, that appear once in the string to the '#' character and letters that appear more than once to the '&' character. Each letter should be encoded according to this scheme. The following strings and their conversions are provided as examples.

Input -> Output
one -> ###
three -> ###&&
Heartbreak hotel -> &&&&&#&&&##&#&&#
def duplicate_encode(word):
   '''
   :returns: new_string -> str. Encoded version of the input     string.
   '''
   new_string = ''
   # TODO Implement encoder
   return new_string

Solutions and Follow ups

List comprehension solution

def duplicate_encode(word):
    """ One liner via list comprehension solution """
    return "".join(["#" if word.lower().count(c) == 1 else "&" for c in word.lower()])

O(2n) solution

import collections
def duplicate_encode(word):
    """ O(2n) solution """
    new_string = ''
    word = word.lower()
    d = collections.defaultdict(int)
    for c in word:
        d[c] += 1
    for c in word:
        new_string = new_string + ('#' if d[c] == 1 else '&')
    return new_string

Follow up questions

  • What are potential problems with solutions utilizing count()
  • What are potential downsides implementing a solution similar to the O(2n) solution?
  • Are there cases where one would be more appropriate than the other?

engineering_interview_questions's People

Contributors

nmaynes avatar

Watchers

 avatar  avatar

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    ๐Ÿ–– Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. ๐Ÿ“Š๐Ÿ“ˆ๐ŸŽ‰

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google โค๏ธ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.