Facebook | Phone | Expression add operators
Company: Meta (Facebook)
Role: e3, e4
Interview Stage: Phone Screen
Location: Menlo Park, California
Year: unknown
Original Post Content:
Location: Menlo Park, California
Question asked:
Variation of expression add operators without * operator
Confused it with https://leetcode.com/problems/target-sum/
at first but interviewer pointed in the right direction.
Example 1:
Input: num = "123", target = 6
Output: ["1+2+3"]
Example 2:
Input: num = "105", target = 5
Output: ["10-5"]
https://leetcode.com/problems/expression-add-operators/
Provided Java Backtrace accepted Solution.
Interviewer asked about additional cases where the expression can start with + or - (Input: num = "510", target = 5
Output: ["-5+10"]) and if the input String has trailing spaces. (Input: num = " 123", target = 6
Output: ["1+2+3"] )
Answered by starting substring from 0th position and using String.trim() on input string to get rid of trailing spaces in input string.