You are given a String equation containing an equation of the form A * B + C = D
, where A, B, C and D are positive integers that don't have leading zeros.
One digit in the equation is missing.
Determine and return the correct digit.
If the missing digit cannot be determined (i.e., there is no solution or there is more than one solution), return -1
instead.
- Class:
FixEquation
- Method :
findMissingDigit
- Parameters :
String
- Returns :
Integer
- Method signature :
function findMissingDigit(equation)
Note: A digit is correct if and only if it produces a valid equation in which A, B, C and D are positive integers with no leading zeros.
- Equation will have the form
A * B + C = D
. - Each of A, B, C, D will be a nonempty string of 1 to 4 characters, i.e.,
1 <= length of A, B, C, D <= 4
. - Each character in each of A, B, C, D will be either a digit ('0'-'9') or a question mark ('?').
- There will be exactly one question mark in equation.
- The numbers represented by A, B, C, D will not have leading zeros.
1️⃣
Equation: 42 * 47 + 2 = 1?76
Returns: 9
We know that 42 * 47 + 2 = 1974, so the missing digit is 9.
2️⃣
Equation: 4? * 47 + 2 = 1976
Returns: 2
The same equation, another missing digit.
3️⃣
Equation: 42 * ?7 + 2 = 1976
Returns: 4
And again the same equation.
4️⃣
Equation: 42 * ?47 + 2 = 1976
Returns: -1
This test case has no valid solution. The numbers cannot have leading zeros, so we cannot fill in a zero in front of 47.
5️⃣
Equation: 2 * 12? + 2 = 247
Returns: -1
Two times something + 2 will never be 247, so this test case has no solution either.
github-externship-assignment's People
Recommend Projects
-
React
A declarative, efficient, and flexible JavaScript library for building user interfaces.
-
Vue.js
🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.
-
Typescript
TypeScript is a superset of JavaScript that compiles to clean JavaScript output.
-
TensorFlow
An Open Source Machine Learning Framework for Everyone
-
Django
The Web framework for perfectionists with deadlines.
-
Laravel
A PHP framework for web artisans
-
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.
-
Visualization
Some thing interesting about visualization, use data art
-
Game
Some thing interesting about game, make everyone happy.
Recommend Org
-
Facebook
We are working to build community through open source technology. NB: members must have two-factor auth.
-
Microsoft
Open source projects and samples from Microsoft.
-
Google
Google ❤️ Open Source for everyone.
-
Alibaba
Alibaba Open Source for everyone
-
D3
Data-Driven Documents codes.
-
Tencent
China tencent open source team.