Bar for Hiring - String Calculator

Vertivco / Eng Fast Papua
Aug 19, 2018 36 Comments

A string calculator is a program that receives an expression such as "7+8-13" as an argument, and the program must return the numbers result, as if entered on a TI-84+.

What will you expect from candidates when you ask them to implement a string calculator that adds and subtracts? Multiple follow ups? How far do you accept a hirable candidate to get?

A friend was doing this challenge.

comments

Want to comment? LOG IN or SIGN UP
TOP 36 Comments
  • Uber uber.
    Can you assume you have access to yacc and lex?
    Aug 19, 2018 7
    • Amazon cnnm16
      I've never heard of someone trying to use tools outside the standard library to solve an interview problem
      Aug 20, 2018
    • Uber uber.
      I was thinking of making a full blown compiler to solve this
      Aug 20, 2018
    • Amazon / Eng Troll Food
      If you need external tool to implement this you already fail. Not even external library should be allowed
      Aug 21, 2018
    • Uber uber.
      to handle every possible case you want millions of lines of code on a whiteboard ru insane!
      Aug 21, 2018
    • Amazon / Eng Troll Food
      No you don't need to handle all, but you can also define condition and rules. Looking at the company OP is from, this is likely a question to be implemented in C in a bare metal no library allowed system.
      Aug 21, 2018
  • Amazon
    \°_°/

    Amazon

    PRE
    Electronic Arts, Google, Nokia, Citrix Systems, Cisco
    \°_°/more
    What's Vertivco? (not trolling)
    Aug 19, 2018 6
    • Vertivco / Eng Fast Papua
      OP
      Aug 20, 2018
    • Amazon Planck
      Ugh, try dismiss all buddy.
      Aug 21, 2018
    • Vertivco / Eng Fast Papua
      OP
      ?
      Aug 21, 2018
    • Amazon
      \°_°/

      Amazon

      PRE
      Electronic Arts, Google, Nokia, Citrix Systems, Cisco
      \°_°/more
      @OP - Thanks for sharing. Appreciate it.
      Aug 21, 2018
    • Amazon Planck
      Hideous number of notifications.
      Aug 21, 2018
  • Amazon / Eng pejamqothc
    I got this for Pinterest and it wasn’t that easy to write on the spot. If you haven’t already seen it it’ll take some time to get right.
    Aug 20, 2018 3
    • Amazon Xode
      Any solution without polish notations will have bugs. Converting to Polish notation needs to follow a pre defined algorithm.

      Interviewee has to be helped if he doesn’t remember which is most likely. Stack calculation is really easy implementation after it.

      I won’t ask this question as this doesn’t required or leaves room to test any knowledge of data structures other than stack. I have never seen use of stack in my career of 10+ years in application programming.

      So, this is a stupid question.
      Aug 20, 2018
    • Indeed / Eng WrinklMgee
      With only addition and subtraction there is a simpler solution. Also conversion to Polish notation may not be so explicit but rather conversion to a tree
      Aug 20, 2018
    • Amazon / Eng Troll Food
      Depends on which area. I have seen people ask this in embedded system to see if you understand command line interface implementation.
      Aug 21, 2018
  • Amazon cnnm16
    For the companies you tagged this question is too easy and would not likely be asked. If it were asked for some reason, nothing less than a fully working solution that respects order of operations and parentheses grouping would be acceptable
    Aug 19, 2018 1
    • Google / Eng hooli.xyz
      Can be a good question for intern candidates.
      Aug 20, 2018
  • This comment was deleted by original commenter.

  • Airbnb def
    This is what they teach you to use stacks for in cs101. It wouldn’t be impossible to see this question but it seems on the easy side
    Aug 19, 2018 0
  • Twitter Zz4567
    This is too easy. In Python you replace '+' with ' + ' and then you split and then you go over the numbers adding or subtracting.
    Aug 19, 2018 6
    • Twitter Zz4567
      Because Python has a "split" method that will take care of the splitting for you, but it needs a separator.

      If you have * or /, you'll first replace and split the around + and - and then the resulting parts around * and /.

      The point here is writing something short.

      If we had parentheses as well we can do something recursive or use reversed polish notation algorithm.
      Aug 20, 2018
    • Amazon / Eng Troll Food
      What makes you think they would let you replace like that? And what makes you think you can implement with Python.

      This smells like a bare metal implementation with no external library help.
      Aug 21, 2018
    • Twitter Zz4567
      They might not.
      Aug 21, 2018
    • Amazon cnnm16
      Python is always allowed
      Aug 21, 2018
    • Amazon / Eng Troll Food
      Not always. Why would someone interviewing you with a simple solution with an answer to just call a Python command or library.
      Aug 21, 2018
  • Tesla LEETCODER
    Which company asked your this question ?
    Aug 19, 2018 3
    • Vertivco / Eng Fast Papua
      OP
      Toyota.
      Aug 19, 2018
    • Vertivco / Eng Fast Papua
      OP
      Pinterest, I mean.
      Aug 19, 2018
    • Vertivco / Eng Fast Papua
      OP
      Happened to a friend, not me.
      Aug 19, 2018
  • Avegant / Eng
    Zilla T

    Avegant Eng

    BIO
    Bring Back Hardware Jobs
    Zilla Tmore
    This is a simple stack problem. The one of Polish notification variety is a bit tougher
    Aug 20, 2018 0
  • Indeed / Eng WrinklMgee
    Just make sure you follow order of operations
    Aug 19, 2018 0