Sum of All Values
Updated
Problem statement
A school in HackerLand organized a scholarship exam with this interesting mathematics problem on addition.
Given a string num that consists of digits ('0' to '9'), a '+' can be inserted between its characters. No adjacent '+' characters are allowed. The value of the expression is then evaluated. Find the sum of the values of all possible expressions after inserting '+' characters any number of times (possibly zero). Since the answer can be large, return the value modulo (10^9 + 7).
Function
getExpressionSums(num: String) → int
Complete the function getExpressionSums in the editor below.
getExpressionSums has the following parameter(s):
Examples
Example 1
num = "123"return = 168All possible valid expressions are shown.
- "1 + 23", value = 24
- "12 + 3", value = 15
- "1 + 2 + 3", value = 6
- "123", value = 123
Their sum is 24 + 15 + 6 + 123 = 168. Thus, the answer is 168 modulo (10^9 + 7) which is 168.
Constraints
An unknown myth for now 🥲
More Flexport interview questions
- Container Ledger with TradesONSITE INTERVIEW · Seen Nov 2026
- Apply Operations to Make a String EmptyPHONE SCREEN · Seen Nov 2026
- Max Area of Island Without Changing the GridPHONE SCREEN · Seen Nov 2026
- Choose the Next Hidden-Word GuessONSITE INTERVIEW · Seen Jul 2026
- Count Good SubsequencesOA · Seen Jun 2024
- Distinct MovesOA · Seen Jun 2024
- Hotspot ConnectionsOA · Seen Jun 2024
- Throw The BallOA · Seen Jun 2024
- Matrix TraversalOA · Seen Feb 2024
- Collect PointsOA · Seen Feb 2024
Similar questions at other companies
- String Transformation (Also for Infra Automation Intern)Snowflake · OASnowflake interview questions
- Count Vowel Strings With Follow RulesC3.ai · OAC3.ai interview questions
- Without WhitespacesPostman · OAPostman interview questions
- Largest Minus Smallest Value of a Parenthesized ExpressionNutanix · ONSITE INTERVIEWNutanix interview questions
- At Most K Jumps with Quadratic Transition CostInfosys · OAInfosys interview questions
- Minimum Merge ConflictsAmazon · OA
- Maximum Signal Walk in a Server TreeTower Research Capital · OA
- Balance a Chemical EquationMicrosoft · OAMicrosoft interview questions
- Binary CircuitAkuna Capital · OAAkuna Capital interview questions
- Jump Game with Prime-3 StepsUber · OAUber interview questions