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.
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
Can be a good question for intern candidates.
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
Which company asked your this question ?
Toyota.
Pinterest, I mean.
Can you assume you have access to yacc and lex?
Usually.
You don't need yacc and lex to solve this
This is too easy. In Python you replace '+' with ' + ' and then you split and then you go over the numbers adding or subtracting.
Why bother adding the spaces in and what if you have * or /
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.
Just make sure you follow order of operations
What's Vertivco? (not trolling)
This is a simple stack problem. The one of Polish notification variety is a bit tougher
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.
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.
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
Ask Blinders
Yesterday
1441
Top red flags in guy to see before saying yes to marriage (arranged)
India
Yesterday
644
Duniya me Vishwaguru ka Danka
Tech Industry
5h
346
The new Tesla Model 3 P goes from 0-60 in 2.9 seconds
Personal Finance
Yesterday
1350
Are we ready to buy our forever home?
Tech Industry
8h
322
how do we feel about the future of work/tech?
Edited.